2009-05-15 21:26:24 +02:00
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
*
|
|
|
|
* Copyright © 2008, 2009 codethink
|
|
|
|
* Copyright © 2009 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General
|
|
|
|
* Public License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Authors: Ryan Lortie <desrt@desrt.ca>
|
|
|
|
* Alexander Larsson <alexl@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "gsocketclient.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2010-08-10 22:48:45 +02:00
|
|
|
#include <string.h>
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
#include <gio/gioenumtypes.h>
|
|
|
|
#include <gio/gsocketaddressenumerator.h>
|
|
|
|
#include <gio/gsocketconnectable.h>
|
|
|
|
#include <gio/gsocketconnection.h>
|
2010-08-10 22:48:45 +02:00
|
|
|
#include <gio/gproxyaddressenumerator.h>
|
|
|
|
#include <gio/gproxyaddress.h>
|
2009-05-15 21:26:24 +02:00
|
|
|
#include <gio/gsimpleasyncresult.h>
|
|
|
|
#include <gio/gcancellable.h>
|
|
|
|
#include <gio/gioerror.h>
|
|
|
|
#include <gio/gsocket.h>
|
|
|
|
#include <gio/gnetworkaddress.h>
|
2009-05-20 12:41:50 +02:00
|
|
|
#include <gio/gnetworkservice.h>
|
2010-08-10 22:48:45 +02:00
|
|
|
#include <gio/gproxy.h>
|
2009-05-15 21:26:24 +02:00
|
|
|
#include <gio/gsocketaddress.h>
|
2010-08-10 22:48:45 +02:00
|
|
|
#include <gio/gtcpconnection.h>
|
make GProxyConnection public, as GTcpWrapperConnection
GProxyConnection is a class that was added for proxy support;
g_socket_client_connect() returns a GSocketConnection, but in some
cases (eg, encrypted SOCKS), GProxy might return a GIOStream that is
not a GSocketConnection. In that case, GSocketClient would wrap the
stream up in a GProxyConnection, which is a subclass of
GSocketConnection but uses the input/output streams of the wrapped
connection.
GTlsConnection is not a GSocketConnection, so it has the same problem,
so it will need the same treatment. Rename the class to
GTcpWrapperStream, and make it public, so people can extract the base
stream from it when necessary.
(This is not ideal and GSocketClient will need to be revisited as an
API at some point...)
https://bugzilla.gnome.org/show_bug.cgi?id=588189
2010-11-02 01:22:24 +01:00
|
|
|
#include <gio/gtcpwrapperconnection.h>
|
2009-12-21 20:50:32 +01:00
|
|
|
#include <gio/gtlscertificate.h>
|
|
|
|
#include <gio/gtlsclientconnection.h>
|
2011-11-15 01:46:02 +01:00
|
|
|
#include <gio/ginetaddress.h>
|
2009-05-15 21:26:24 +02:00
|
|
|
#include "glibintl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gsocketclient
|
2009-05-18 13:02:11 +02:00
|
|
|
* @short_description: Helper for connecting to a network service
|
2009-05-15 21:26:24 +02:00
|
|
|
* @include: gio/gio.h
|
|
|
|
* @see_also: #GSocketConnection, #GSocketListener
|
|
|
|
*
|
|
|
|
* #GSocketClient is a high-level utility class for connecting to a
|
|
|
|
* network host using a connection oriented socket type.
|
|
|
|
*
|
2011-04-20 19:08:06 +02:00
|
|
|
* You create a #GSocketClient object, set any options you want, and then
|
2009-05-15 21:26:24 +02:00
|
|
|
* call a sync or async connect operation, which returns a #GSocketConnection
|
|
|
|
* subclass on success.
|
|
|
|
*
|
|
|
|
* The type of the #GSocketConnection object returned depends on the type of
|
|
|
|
* the underlying socket that is in use. For instance, for a TCP/IP connection
|
|
|
|
* it will be a #GTcpConnection.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GSocketClient, g_socket_client, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_NONE,
|
|
|
|
PROP_FAMILY,
|
|
|
|
PROP_TYPE,
|
|
|
|
PROP_PROTOCOL,
|
2010-08-14 21:04:24 +02:00
|
|
|
PROP_LOCAL_ADDRESS,
|
2010-08-10 22:48:45 +02:00
|
|
|
PROP_TIMEOUT,
|
|
|
|
PROP_ENABLE_PROXY,
|
2009-12-21 20:50:32 +01:00
|
|
|
PROP_TLS,
|
|
|
|
PROP_TLS_VALIDATION_FLAGS
|
2009-05-15 21:26:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GSocketClientPrivate
|
|
|
|
{
|
|
|
|
GSocketFamily family;
|
|
|
|
GSocketType type;
|
2009-05-20 12:01:29 +02:00
|
|
|
GSocketProtocol protocol;
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketAddress *local_address;
|
2010-08-14 21:04:24 +02:00
|
|
|
guint timeout;
|
2010-08-10 22:48:45 +02:00
|
|
|
gboolean enable_proxy;
|
2010-08-19 22:23:50 +02:00
|
|
|
GHashTable *app_proxies;
|
2009-12-21 20:50:32 +01:00
|
|
|
gboolean tls;
|
|
|
|
GTlsCertificateFlags tls_validation_flags;
|
2009-05-15 21:26:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static GSocket *
|
|
|
|
create_socket (GSocketClient *client,
|
|
|
|
GSocketAddress *dest_address,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSocketFamily family;
|
|
|
|
GSocket *socket;
|
|
|
|
|
|
|
|
family = client->priv->family;
|
|
|
|
if (family == G_SOCKET_FAMILY_INVALID &&
|
|
|
|
client->priv->local_address != NULL)
|
|
|
|
family = g_socket_address_get_family (client->priv->local_address);
|
|
|
|
if (family == G_SOCKET_FAMILY_INVALID)
|
|
|
|
family = g_socket_address_get_family (dest_address);
|
|
|
|
|
|
|
|
socket = g_socket_new (family,
|
|
|
|
client->priv->type,
|
2009-05-20 12:01:29 +02:00
|
|
|
client->priv->protocol,
|
2009-05-15 21:26:24 +02:00
|
|
|
error);
|
|
|
|
if (socket == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (client->priv->local_address)
|
|
|
|
{
|
|
|
|
if (!g_socket_bind (socket,
|
|
|
|
client->priv->local_address,
|
|
|
|
FALSE,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
g_object_unref (socket);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-14 21:04:24 +02:00
|
|
|
if (client->priv->timeout)
|
|
|
|
g_socket_set_timeout (socket, client->priv->timeout);
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
return socket;
|
|
|
|
}
|
|
|
|
|
2011-10-17 03:24:45 +02:00
|
|
|
static gboolean
|
2010-08-10 22:48:45 +02:00
|
|
|
can_use_proxy (GSocketClient *client)
|
|
|
|
{
|
|
|
|
GSocketClientPrivate *priv = client->priv;
|
|
|
|
|
|
|
|
return priv->enable_proxy
|
|
|
|
&& priv->type == G_SOCKET_TYPE_STREAM;
|
|
|
|
}
|
|
|
|
|
2011-11-15 01:46:02 +01:00
|
|
|
static void
|
|
|
|
clarify_connect_error (GError *error,
|
|
|
|
GSocketConnectable *connectable,
|
|
|
|
GSocketAddress *address)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
char *tmp_name = NULL;
|
|
|
|
|
|
|
|
if (G_IS_PROXY_ADDRESS (address))
|
|
|
|
{
|
|
|
|
name = tmp_name = g_inet_address_to_string (g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (address)));
|
|
|
|
|
|
|
|
g_prefix_error (&error, _("Could not connect to proxy server %s: "), name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (G_IS_NETWORK_ADDRESS (connectable))
|
|
|
|
name = g_network_address_get_hostname (G_NETWORK_ADDRESS (connectable));
|
|
|
|
else if (G_IS_NETWORK_SERVICE (connectable))
|
|
|
|
name = g_network_service_get_domain (G_NETWORK_SERVICE (connectable));
|
|
|
|
else if (G_IS_INET_SOCKET_ADDRESS (connectable))
|
|
|
|
name = tmp_name = g_inet_address_to_string (g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (connectable)));
|
|
|
|
else
|
|
|
|
name = NULL;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
g_prefix_error (&error, _("Could not connect to %s: "), name);
|
|
|
|
else
|
|
|
|
g_prefix_error (&error, _("Could not connect: "));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (tmp_name);
|
|
|
|
}
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
static void
|
|
|
|
g_socket_client_init (GSocketClient *client)
|
|
|
|
{
|
|
|
|
client->priv = G_TYPE_INSTANCE_GET_PRIVATE (client,
|
|
|
|
G_TYPE_SOCKET_CLIENT,
|
|
|
|
GSocketClientPrivate);
|
|
|
|
client->priv->type = G_SOCKET_TYPE_STREAM;
|
2010-08-19 22:23:50 +02:00
|
|
|
client->priv->app_proxies = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
g_free,
|
|
|
|
NULL);
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GSocketClient with the default options.
|
|
|
|
*
|
|
|
|
* Returns: a #GSocketClient.
|
|
|
|
* Free the returned object with g_object_unref().
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketClient *
|
|
|
|
g_socket_client_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (G_TYPE_SOCKET_CLIENT, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GSocketClient *client = G_SOCKET_CLIENT (object);
|
|
|
|
|
|
|
|
if (client->priv->local_address)
|
|
|
|
g_object_unref (client->priv->local_address);
|
|
|
|
|
|
|
|
if (G_OBJECT_CLASS (g_socket_client_parent_class)->finalize)
|
|
|
|
(*G_OBJECT_CLASS (g_socket_client_parent_class)->finalize) (object);
|
2010-08-19 22:23:50 +02:00
|
|
|
|
|
|
|
g_hash_table_unref (client->priv->app_proxies);
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GSocketClient *client = G_SOCKET_CLIENT (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_FAMILY:
|
|
|
|
g_value_set_enum (value, client->priv->family);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TYPE:
|
|
|
|
g_value_set_enum (value, client->priv->type);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_PROTOCOL:
|
2009-05-20 12:01:29 +02:00
|
|
|
g_value_set_enum (value, client->priv->protocol);
|
2009-05-15 21:26:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_LOCAL_ADDRESS:
|
|
|
|
g_value_set_object (value, client->priv->local_address);
|
|
|
|
break;
|
|
|
|
|
2010-08-14 21:04:24 +02:00
|
|
|
case PROP_TIMEOUT:
|
|
|
|
g_value_set_uint (value, client->priv->timeout);
|
|
|
|
break;
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
case PROP_ENABLE_PROXY:
|
|
|
|
g_value_set_boolean (value, client->priv->enable_proxy);
|
|
|
|
break;
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
case PROP_TLS:
|
|
|
|
g_value_set_boolean (value, g_socket_client_get_tls (client));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TLS_VALIDATION_FLAGS:
|
|
|
|
g_value_set_flags (value, g_socket_client_get_tls_validation_flags (client));
|
|
|
|
break;
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GSocketClient *client = G_SOCKET_CLIENT (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_FAMILY:
|
|
|
|
g_socket_client_set_family (client, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TYPE:
|
|
|
|
g_socket_client_set_socket_type (client, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_PROTOCOL:
|
2009-05-20 12:01:29 +02:00
|
|
|
g_socket_client_set_protocol (client, g_value_get_enum (value));
|
2009-05-15 21:26:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_LOCAL_ADDRESS:
|
|
|
|
g_socket_client_set_local_address (client, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2010-08-14 21:04:24 +02:00
|
|
|
case PROP_TIMEOUT:
|
|
|
|
g_socket_client_set_timeout (client, g_value_get_uint (value));
|
|
|
|
break;
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
case PROP_ENABLE_PROXY:
|
|
|
|
g_socket_client_set_enable_proxy (client, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
case PROP_TLS:
|
|
|
|
g_socket_client_set_tls (client, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TLS_VALIDATION_FLAGS:
|
|
|
|
g_socket_client_set_tls_validation_flags (client, g_value_get_flags (value));
|
|
|
|
break;
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_get_family:
|
2009-05-18 13:02:11 +02:00
|
|
|
* @client: a #GSocketClient.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Gets the socket family of the socket client.
|
|
|
|
*
|
|
|
|
* See g_socket_client_set_family() for details.
|
|
|
|
*
|
|
|
|
* Returns: a #GSocketFamily
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketFamily
|
|
|
|
g_socket_client_get_family (GSocketClient *client)
|
|
|
|
{
|
|
|
|
return client->priv->family;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_set_family:
|
2009-05-18 13:02:11 +02:00
|
|
|
* @client: a #GSocketClient.
|
2009-05-15 21:26:24 +02:00
|
|
|
* @family: a #GSocketFamily
|
|
|
|
*
|
|
|
|
* Sets the socket family of the socket client.
|
|
|
|
* If this is set to something other than %G_SOCKET_FAMILY_INVALID
|
|
|
|
* then the sockets created by this object will be of the specified
|
|
|
|
* family.
|
|
|
|
*
|
|
|
|
* This might be useful for instance if you want to force the local
|
|
|
|
* connection to be an ipv4 socket, even though the address might
|
|
|
|
* be an ipv6 mapped to ipv4 address.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
void
|
|
|
|
g_socket_client_set_family (GSocketClient *client,
|
2009-05-28 00:20:08 +02:00
|
|
|
GSocketFamily family)
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
|
|
|
if (client->priv->family == family)
|
|
|
|
return;
|
|
|
|
|
|
|
|
client->priv->family = family;
|
|
|
|
g_object_notify (G_OBJECT (client), "family");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_get_socket_type:
|
2009-05-18 13:02:11 +02:00
|
|
|
* @client: a #GSocketClient.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Gets the socket type of the socket client.
|
|
|
|
*
|
|
|
|
* See g_socket_client_set_socket_type() for details.
|
|
|
|
*
|
|
|
|
* Returns: a #GSocketFamily
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketType
|
|
|
|
g_socket_client_get_socket_type (GSocketClient *client)
|
|
|
|
{
|
|
|
|
return client->priv->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_set_socket_type:
|
2009-05-18 13:02:11 +02:00
|
|
|
* @client: a #GSocketClient.
|
2009-05-15 21:26:24 +02:00
|
|
|
* @type: a #GSocketType
|
|
|
|
*
|
|
|
|
* Sets the socket type of the socket client.
|
|
|
|
* The sockets created by this object will be of the specified
|
|
|
|
* type.
|
|
|
|
*
|
|
|
|
* It doesn't make sense to specify a type of %G_SOCKET_TYPE_DATAGRAM,
|
|
|
|
* as GSocketClient is used for connection oriented services.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
void
|
|
|
|
g_socket_client_set_socket_type (GSocketClient *client,
|
2009-05-28 00:20:08 +02:00
|
|
|
GSocketType type)
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
|
|
|
if (client->priv->type == type)
|
|
|
|
return;
|
|
|
|
|
|
|
|
client->priv->type = type;
|
|
|
|
g_object_notify (G_OBJECT (client), "type");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_get_protocol:
|
2009-05-28 00:20:08 +02:00
|
|
|
* @client: a #GSocketClient
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Gets the protocol name type of the socket client.
|
|
|
|
*
|
|
|
|
* See g_socket_client_set_protocol() for details.
|
|
|
|
*
|
2009-05-20 12:01:29 +02:00
|
|
|
* Returns: a #GSocketProtocol
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-20 12:01:29 +02:00
|
|
|
GSocketProtocol
|
2009-05-15 21:26:24 +02:00
|
|
|
g_socket_client_get_protocol (GSocketClient *client)
|
|
|
|
{
|
|
|
|
return client->priv->protocol;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_set_protocol:
|
2009-05-18 13:02:11 +02:00
|
|
|
* @client: a #GSocketClient.
|
2009-05-20 12:01:29 +02:00
|
|
|
* @protocol: a #GSocketProtocol
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Sets the protocol of the socket client.
|
|
|
|
* The sockets created by this object will use of the specified
|
|
|
|
* protocol.
|
|
|
|
*
|
2009-05-20 12:01:29 +02:00
|
|
|
* If @protocol is %0 that means to use the default
|
2009-05-15 21:26:24 +02:00
|
|
|
* protocol for the socket family and type.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
void
|
2009-05-28 00:20:08 +02:00
|
|
|
g_socket_client_set_protocol (GSocketClient *client,
|
|
|
|
GSocketProtocol protocol)
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
2009-05-20 12:01:29 +02:00
|
|
|
if (client->priv->protocol == protocol)
|
2009-05-15 21:26:24 +02:00
|
|
|
return;
|
|
|
|
|
2009-05-20 12:01:29 +02:00
|
|
|
client->priv->protocol = protocol;
|
2009-05-15 21:26:24 +02:00
|
|
|
g_object_notify (G_OBJECT (client), "protocol");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_get_local_address:
|
2009-05-18 13:02:11 +02:00
|
|
|
* @client: a #GSocketClient.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Gets the local address of the socket client.
|
|
|
|
*
|
|
|
|
* See g_socket_client_set_local_address() for details.
|
|
|
|
*
|
2011-06-05 00:44:44 +02:00
|
|
|
* Returns: (transfer none): a #GSocketAddress or %NULL. Do not free.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketAddress *
|
|
|
|
g_socket_client_get_local_address (GSocketClient *client)
|
|
|
|
{
|
|
|
|
return client->priv->local_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_set_local_address:
|
2009-05-18 13:02:11 +02:00
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @address: a #GSocketAddress, or %NULL
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Sets the local address of the socket client.
|
|
|
|
* The sockets created by this object will bound to the
|
|
|
|
* specified address (if not %NULL) before connecting.
|
|
|
|
*
|
2011-04-20 19:08:06 +02:00
|
|
|
* This is useful if you want to ensure that the local
|
2009-05-15 21:26:24 +02:00
|
|
|
* side of the connection is on a specific port, or on
|
|
|
|
* a specific interface.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
void
|
2009-05-28 00:20:08 +02:00
|
|
|
g_socket_client_set_local_address (GSocketClient *client,
|
|
|
|
GSocketAddress *address)
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
|
|
|
if (address)
|
2010-08-10 22:48:45 +02:00
|
|
|
g_object_ref (address);
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
if (client->priv->local_address)
|
|
|
|
{
|
|
|
|
g_object_unref (client->priv->local_address);
|
|
|
|
}
|
|
|
|
client->priv->local_address = address;
|
|
|
|
g_object_notify (G_OBJECT (client), "local-address");
|
|
|
|
}
|
|
|
|
|
2010-08-14 21:04:24 +02:00
|
|
|
/**
|
|
|
|
* g_socket_client_get_timeout:
|
|
|
|
* @client: a #GSocketClient
|
|
|
|
*
|
|
|
|
* Gets the I/O timeout time for sockets created by @client.
|
|
|
|
*
|
|
|
|
* See g_socket_client_set_timeout() for details.
|
|
|
|
*
|
|
|
|
* Returns: the timeout in seconds
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
g_socket_client_get_timeout (GSocketClient *client)
|
|
|
|
{
|
|
|
|
return client->priv->timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_set_timeout:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @timeout: the timeout
|
|
|
|
*
|
|
|
|
* Sets the I/O timeout for sockets created by @client. @timeout is a
|
|
|
|
* time in seconds, or 0 for no timeout (the default).
|
|
|
|
*
|
|
|
|
* The timeout value affects the initial connection attempt as well,
|
|
|
|
* so setting this may cause calls to g_socket_client_connect(), etc,
|
|
|
|
* to fail with %G_IO_ERROR_TIMED_OUT.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_socket_client_set_timeout (GSocketClient *client,
|
|
|
|
guint timeout)
|
|
|
|
{
|
|
|
|
if (client->priv->timeout == timeout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
client->priv->timeout = timeout;
|
|
|
|
g_object_notify (G_OBJECT (client), "timeout");
|
|
|
|
}
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
/**
|
|
|
|
* g_socket_client_get_enable_proxy:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
*
|
|
|
|
* Gets the proxy enable state; see g_socket_client_set_enable_proxy()
|
|
|
|
*
|
|
|
|
* Returns: whether proxying is enabled
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_socket_client_get_enable_proxy (GSocketClient *client)
|
|
|
|
{
|
|
|
|
return client->priv->enable_proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_set_enable_proxy:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @enable: whether to enable proxies
|
|
|
|
*
|
|
|
|
* Sets whether or not @client attempts to make connections via a
|
|
|
|
* proxy server. When enabled (the default), #GSocketClient will use a
|
|
|
|
* #GProxyResolver to determine if a proxy protocol such as SOCKS is
|
|
|
|
* needed, and automatically do the necessary proxy negotiation.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_socket_client_set_enable_proxy (GSocketClient *client,
|
|
|
|
gboolean enable)
|
|
|
|
{
|
|
|
|
enable = !!enable;
|
|
|
|
if (client->priv->enable_proxy == enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
client->priv->enable_proxy = enable;
|
|
|
|
g_object_notify (G_OBJECT (client), "enable-proxy");
|
|
|
|
}
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
/**
|
|
|
|
* g_socket_client_get_tls:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
*
|
|
|
|
* Gets whether @client creates TLS connections. See
|
|
|
|
* g_socket_client_set_tls() for details.
|
|
|
|
*
|
|
|
|
* Returns: whether @client uses TLS
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
g_socket_client_get_tls (GSocketClient *client)
|
|
|
|
{
|
|
|
|
return client->priv->tls;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_set_tls:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @tls: whether to use TLS
|
|
|
|
*
|
|
|
|
* Sets whether @client creates TLS (aka SSL) connections. If @tls is
|
|
|
|
* %TRUE, @client will wrap its connections in a #GTlsClientConnection
|
|
|
|
* and perform a TLS handshake when connecting.
|
|
|
|
*
|
|
|
|
* Note that since #GSocketClient must return a #GSocketConnection,
|
|
|
|
* but #GTlsClientConnection is not a #GSocketConnection, this
|
|
|
|
* actually wraps the resulting #GTlsClientConnection in a
|
|
|
|
* #GTcpWrapperConnection when returning it. You can use
|
|
|
|
* g_tcp_wrapper_connection_get_base_io_stream() on the return value
|
|
|
|
* to extract the #GTlsClientConnection.
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_socket_client_set_tls (GSocketClient *client,
|
|
|
|
gboolean tls)
|
|
|
|
{
|
|
|
|
tls = !!tls;
|
|
|
|
if (tls == client->priv->tls)
|
|
|
|
return;
|
|
|
|
|
|
|
|
client->priv->tls = tls;
|
|
|
|
g_object_notify (G_OBJECT (client), "tls");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_get_tls_validation_flags:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
*
|
|
|
|
* Gets the TLS validation flags used creating TLS connections via
|
|
|
|
* @client.
|
|
|
|
*
|
|
|
|
* Returns: the TLS validation flags
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
*/
|
|
|
|
GTlsCertificateFlags
|
|
|
|
g_socket_client_get_tls_validation_flags (GSocketClient *client)
|
|
|
|
{
|
|
|
|
return client->priv->tls_validation_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_set_tls_validation_flags:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @flags: the validation flags
|
|
|
|
*
|
|
|
|
* Sets the TLS validation flags used when creating TLS connections
|
|
|
|
* via @client. The default value is %G_TLS_CERTIFICATE_VALIDATE_ALL.
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_socket_client_set_tls_validation_flags (GSocketClient *client,
|
|
|
|
GTlsCertificateFlags flags)
|
|
|
|
{
|
|
|
|
if (client->priv->tls_validation_flags != flags)
|
|
|
|
{
|
|
|
|
client->priv->tls_validation_flags = flags;
|
|
|
|
g_object_notify (G_OBJECT (client), "tls-validation-flags");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
static void
|
|
|
|
g_socket_client_class_init (GSocketClientClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
g_type_class_add_private (class, sizeof (GSocketClientPrivate));
|
|
|
|
|
|
|
|
gobject_class->finalize = g_socket_client_finalize;
|
|
|
|
gobject_class->set_property = g_socket_client_set_property;
|
|
|
|
gobject_class->get_property = g_socket_client_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_FAMILY,
|
|
|
|
g_param_spec_enum ("family",
|
|
|
|
P_("Socket family"),
|
|
|
|
P_("The sockets address family to use for socket construction"),
|
|
|
|
G_TYPE_SOCKET_FAMILY,
|
|
|
|
G_SOCKET_FAMILY_INVALID,
|
2009-05-28 00:20:08 +02:00
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TYPE,
|
|
|
|
g_param_spec_enum ("type",
|
|
|
|
P_("Socket type"),
|
|
|
|
P_("The sockets type to use for socket construction"),
|
|
|
|
G_TYPE_SOCKET_TYPE,
|
|
|
|
G_SOCKET_TYPE_STREAM,
|
2009-05-28 00:20:08 +02:00
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PROTOCOL,
|
2009-05-20 12:01:29 +02:00
|
|
|
g_param_spec_enum ("protocol",
|
|
|
|
P_("Socket protocol"),
|
|
|
|
P_("The protocol to use for socket construction, or 0 for default"),
|
|
|
|
G_TYPE_SOCKET_PROTOCOL,
|
|
|
|
G_SOCKET_PROTOCOL_DEFAULT,
|
2009-05-28 00:20:08 +02:00
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_LOCAL_ADDRESS,
|
|
|
|
g_param_spec_object ("local-address",
|
|
|
|
P_("Local address"),
|
|
|
|
P_("The local address constructed sockets will be bound to"),
|
|
|
|
G_TYPE_SOCKET_ADDRESS,
|
2009-05-28 00:20:08 +02:00
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2010-08-14 21:04:24 +02:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TIMEOUT,
|
|
|
|
g_param_spec_uint ("timeout",
|
|
|
|
P_("Socket timeout"),
|
|
|
|
P_("The I/O timeout for sockets, or 0 for none"),
|
|
|
|
0, G_MAXUINT, 0,
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ENABLE_PROXY,
|
|
|
|
g_param_spec_boolean ("enable-proxy",
|
|
|
|
P_("Enable proxy"),
|
|
|
|
P_("Enable proxy support"),
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
g_object_class_install_property (gobject_class, PROP_TLS,
|
|
|
|
g_param_spec_boolean ("tls",
|
|
|
|
P_("TLS"),
|
|
|
|
P_("Whether to create TLS connections"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TLS_VALIDATION_FLAGS,
|
|
|
|
g_param_spec_flags ("tls-validation-flags",
|
|
|
|
P_("TLS validation flags"),
|
|
|
|
P_("TLS validation flags to use"),
|
|
|
|
G_TYPE_TLS_CERTIFICATE_FLAGS,
|
|
|
|
G_TLS_CERTIFICATE_VALIDATE_ALL,
|
|
|
|
G_PARAM_CONSTRUCT |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_connect:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @connectable: a #GSocketConnectable specifying the remote address.
|
2010-12-29 16:01:12 +01:00
|
|
|
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
|
2009-05-15 21:26:24 +02:00
|
|
|
* @error: #GError for error reporting, or %NULL to ignore.
|
|
|
|
*
|
2011-04-20 19:08:06 +02:00
|
|
|
* Tries to resolve the @connectable and make a network connection to it.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Upon a successful connection, a new #GSocketConnection is constructed
|
|
|
|
* and returned. The caller owns this new object and must drop their
|
|
|
|
* reference to it when finished with it.
|
|
|
|
*
|
|
|
|
* The type of the #GSocketConnection object returned depends on the type of
|
|
|
|
* the underlying socket that is used. For instance, for a TCP/IP connection
|
|
|
|
* it will be a #GTcpConnection.
|
|
|
|
*
|
2011-04-20 19:08:06 +02:00
|
|
|
* The socket created will be the same family as the address that the
|
2009-05-15 21:26:24 +02:00
|
|
|
* @connectable resolves to, unless family is set with g_socket_client_set_family()
|
|
|
|
* or indirectly via g_socket_client_set_local_address(). The socket type
|
|
|
|
* defaults to %G_SOCKET_TYPE_STREAM but can be set with
|
|
|
|
* g_socket_client_set_socket_type().
|
|
|
|
*
|
|
|
|
* If a local address is specified with g_socket_client_set_local_address() the
|
|
|
|
* socket will be bound to this address before connecting.
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketConnection *
|
|
|
|
g_socket_client_connect (GSocketClient *client,
|
|
|
|
GSocketConnectable *connectable,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
2009-12-21 20:50:32 +01:00
|
|
|
GIOStream *connection = NULL;
|
2010-08-10 22:48:45 +02:00
|
|
|
GSocketAddressEnumerator *enumerator = NULL;
|
2009-05-15 21:26:24 +02:00
|
|
|
GError *last_error, *tmp_error;
|
|
|
|
|
|
|
|
last_error = NULL;
|
2010-08-10 22:48:45 +02:00
|
|
|
|
|
|
|
if (can_use_proxy (client))
|
|
|
|
enumerator = g_socket_connectable_proxy_enumerate (connectable);
|
|
|
|
else
|
|
|
|
enumerator = g_socket_connectable_enumerate (connectable);
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
while (connection == NULL)
|
|
|
|
{
|
2010-08-10 22:48:45 +02:00
|
|
|
GSocketAddress *address = NULL;
|
2011-11-17 19:04:04 +01:00
|
|
|
gboolean application_proxy = FALSE;
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocket *socket;
|
|
|
|
|
|
|
|
if (g_cancellable_is_cancelled (cancellable))
|
|
|
|
{
|
|
|
|
g_clear_error (error);
|
|
|
|
g_cancellable_set_error_if_cancelled (cancellable, error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_error = NULL;
|
|
|
|
address = g_socket_address_enumerator_next (enumerator, cancellable,
|
2010-08-10 22:48:45 +02:00
|
|
|
&tmp_error);
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
if (address == NULL)
|
|
|
|
{
|
|
|
|
if (tmp_error)
|
|
|
|
{
|
|
|
|
g_clear_error (&last_error);
|
|
|
|
g_propagate_error (error, tmp_error);
|
|
|
|
}
|
|
|
|
else if (last_error)
|
|
|
|
{
|
2009-07-20 14:29:32 +02:00
|
|
|
g_propagate_error (error, last_error);
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
else
|
2009-05-19 15:03:14 +02:00
|
|
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
_("Unknown error on connect"));
|
2009-05-15 21:26:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear error from previous attempt */
|
|
|
|
g_clear_error (&last_error);
|
|
|
|
|
|
|
|
socket = create_socket (client, address, &last_error);
|
make GProxyConnection public, as GTcpWrapperConnection
GProxyConnection is a class that was added for proxy support;
g_socket_client_connect() returns a GSocketConnection, but in some
cases (eg, encrypted SOCKS), GProxy might return a GIOStream that is
not a GSocketConnection. In that case, GSocketClient would wrap the
stream up in a GProxyConnection, which is a subclass of
GSocketConnection but uses the input/output streams of the wrapped
connection.
GTlsConnection is not a GSocketConnection, so it has the same problem,
so it will need the same treatment. Rename the class to
GTcpWrapperStream, and make it public, so people can extract the base
stream from it when necessary.
(This is not ideal and GSocketClient will need to be revisited as an
API at some point...)
https://bugzilla.gnome.org/show_bug.cgi?id=588189
2010-11-02 01:22:24 +01:00
|
|
|
if (socket == NULL)
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
make GProxyConnection public, as GTcpWrapperConnection
GProxyConnection is a class that was added for proxy support;
g_socket_client_connect() returns a GSocketConnection, but in some
cases (eg, encrypted SOCKS), GProxy might return a GIOStream that is
not a GSocketConnection. In that case, GSocketClient would wrap the
stream up in a GProxyConnection, which is a subclass of
GSocketConnection but uses the input/output streams of the wrapped
connection.
GTlsConnection is not a GSocketConnection, so it has the same problem,
so it will need the same treatment. Rename the class to
GTcpWrapperStream, and make it public, so people can extract the base
stream from it when necessary.
(This is not ideal and GSocketClient will need to be revisited as an
API at some point...)
https://bugzilla.gnome.org/show_bug.cgi?id=588189
2010-11-02 01:22:24 +01:00
|
|
|
g_object_unref (address);
|
|
|
|
continue;
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
|
make GProxyConnection public, as GTcpWrapperConnection
GProxyConnection is a class that was added for proxy support;
g_socket_client_connect() returns a GSocketConnection, but in some
cases (eg, encrypted SOCKS), GProxy might return a GIOStream that is
not a GSocketConnection. In that case, GSocketClient would wrap the
stream up in a GProxyConnection, which is a subclass of
GSocketConnection but uses the input/output streams of the wrapped
connection.
GTlsConnection is not a GSocketConnection, so it has the same problem,
so it will need the same treatment. Rename the class to
GTcpWrapperStream, and make it public, so people can extract the base
stream from it when necessary.
(This is not ideal and GSocketClient will need to be revisited as an
API at some point...)
https://bugzilla.gnome.org/show_bug.cgi?id=588189
2010-11-02 01:22:24 +01:00
|
|
|
if (g_socket_connect (socket, address, cancellable, &last_error))
|
2009-12-21 20:50:32 +01:00
|
|
|
connection = (GIOStream *)g_socket_connection_factory_create_connection (socket);
|
2011-11-15 01:46:02 +01:00
|
|
|
else
|
|
|
|
clarify_connect_error (last_error, connectable, address);
|
make GProxyConnection public, as GTcpWrapperConnection
GProxyConnection is a class that was added for proxy support;
g_socket_client_connect() returns a GSocketConnection, but in some
cases (eg, encrypted SOCKS), GProxy might return a GIOStream that is
not a GSocketConnection. In that case, GSocketClient would wrap the
stream up in a GProxyConnection, which is a subclass of
GSocketConnection but uses the input/output streams of the wrapped
connection.
GTlsConnection is not a GSocketConnection, so it has the same problem,
so it will need the same treatment. Rename the class to
GTcpWrapperStream, and make it public, so people can extract the base
stream from it when necessary.
(This is not ideal and GSocketClient will need to be revisited as an
API at some point...)
https://bugzilla.gnome.org/show_bug.cgi?id=588189
2010-11-02 01:22:24 +01:00
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
if (connection &&
|
|
|
|
G_IS_PROXY_ADDRESS (address) &&
|
|
|
|
client->priv->enable_proxy)
|
|
|
|
{
|
|
|
|
GProxyAddress *proxy_addr = G_PROXY_ADDRESS (address);
|
|
|
|
const gchar *protocol;
|
|
|
|
GProxy *proxy;
|
|
|
|
|
|
|
|
protocol = g_proxy_address_get_protocol (proxy_addr);
|
|
|
|
proxy = g_proxy_get_default_for_protocol (protocol);
|
|
|
|
|
|
|
|
/* The connection should not be anything else then TCP Connection,
|
|
|
|
* but let's put a safety guard in case
|
|
|
|
*/
|
|
|
|
if (!G_IS_TCP_CONNECTION (connection))
|
|
|
|
{
|
|
|
|
g_critical ("Trying to proxy over non-TCP connection, this is "
|
|
|
|
"most likely a bug in GLib IO library.");
|
|
|
|
|
|
|
|
g_set_error_literal (&last_error,
|
|
|
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Trying to proxy over non-TCP connection is not supported."));
|
|
|
|
|
|
|
|
g_object_unref (connection);
|
|
|
|
connection = NULL;
|
|
|
|
}
|
|
|
|
else if (proxy)
|
|
|
|
{
|
2009-12-21 20:50:32 +01:00
|
|
|
GIOStream *proxy_connection;
|
2010-08-10 22:48:45 +02:00
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
proxy_connection = g_proxy_connect (proxy,
|
|
|
|
connection,
|
|
|
|
proxy_addr,
|
|
|
|
cancellable,
|
|
|
|
&last_error);
|
make GProxyConnection public, as GTcpWrapperConnection
GProxyConnection is a class that was added for proxy support;
g_socket_client_connect() returns a GSocketConnection, but in some
cases (eg, encrypted SOCKS), GProxy might return a GIOStream that is
not a GSocketConnection. In that case, GSocketClient would wrap the
stream up in a GProxyConnection, which is a subclass of
GSocketConnection but uses the input/output streams of the wrapped
connection.
GTlsConnection is not a GSocketConnection, so it has the same problem,
so it will need the same treatment. Rename the class to
GTcpWrapperStream, and make it public, so people can extract the base
stream from it when necessary.
(This is not ideal and GSocketClient will need to be revisited as an
API at some point...)
https://bugzilla.gnome.org/show_bug.cgi?id=588189
2010-11-02 01:22:24 +01:00
|
|
|
g_object_unref (connection);
|
2009-12-21 20:50:32 +01:00
|
|
|
connection = proxy_connection;
|
make GProxyConnection public, as GTcpWrapperConnection
GProxyConnection is a class that was added for proxy support;
g_socket_client_connect() returns a GSocketConnection, but in some
cases (eg, encrypted SOCKS), GProxy might return a GIOStream that is
not a GSocketConnection. In that case, GSocketClient would wrap the
stream up in a GProxyConnection, which is a subclass of
GSocketConnection but uses the input/output streams of the wrapped
connection.
GTlsConnection is not a GSocketConnection, so it has the same problem,
so it will need the same treatment. Rename the class to
GTcpWrapperStream, and make it public, so people can extract the base
stream from it when necessary.
(This is not ideal and GSocketClient will need to be revisited as an
API at some point...)
https://bugzilla.gnome.org/show_bug.cgi?id=588189
2010-11-02 01:22:24 +01:00
|
|
|
g_object_unref (proxy);
|
2010-08-10 22:48:45 +02:00
|
|
|
}
|
2010-08-19 22:23:50 +02:00
|
|
|
else if (!g_hash_table_lookup_extended (client->priv->app_proxies,
|
|
|
|
protocol, NULL, NULL))
|
2010-08-10 22:48:45 +02:00
|
|
|
{
|
|
|
|
g_set_error (&last_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Proxy protocol '%s' is not supported."),
|
|
|
|
protocol);
|
|
|
|
g_object_unref (connection);
|
|
|
|
connection = NULL;
|
|
|
|
}
|
2011-11-17 19:04:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
application_proxy = TRUE;
|
|
|
|
}
|
2010-08-10 22:48:45 +02:00
|
|
|
}
|
|
|
|
|
2011-11-17 19:04:04 +01:00
|
|
|
if (!application_proxy && connection && client->priv->tls)
|
2009-12-21 20:50:32 +01:00
|
|
|
{
|
2010-12-07 16:06:38 +01:00
|
|
|
GIOStream *tlsconn;
|
2009-12-21 20:50:32 +01:00
|
|
|
|
|
|
|
tlsconn = g_tls_client_connection_new (connection, connectable, &last_error);
|
|
|
|
g_object_unref (connection);
|
2010-12-07 16:06:38 +01:00
|
|
|
connection = tlsconn;
|
2009-12-21 20:50:32 +01:00
|
|
|
|
|
|
|
if (tlsconn)
|
|
|
|
{
|
2010-12-07 16:06:38 +01:00
|
|
|
g_tls_client_connection_set_validation_flags (G_TLS_CLIENT_CONNECTION (tlsconn),
|
|
|
|
client->priv->tls_validation_flags);
|
2009-12-21 20:50:32 +01:00
|
|
|
if (!g_tls_connection_handshake (G_TLS_CONNECTION (tlsconn),
|
|
|
|
cancellable, &last_error))
|
|
|
|
{
|
|
|
|
g_object_unref (tlsconn);
|
|
|
|
connection = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connection && !G_IS_SOCKET_CONNECTION (connection))
|
|
|
|
{
|
|
|
|
GSocketConnection *wrapper_connection;
|
|
|
|
|
|
|
|
wrapper_connection = g_tcp_wrapper_connection_new (connection, socket);
|
|
|
|
g_object_unref (connection);
|
|
|
|
connection = (GIOStream *)wrapper_connection;
|
|
|
|
}
|
|
|
|
|
make GProxyConnection public, as GTcpWrapperConnection
GProxyConnection is a class that was added for proxy support;
g_socket_client_connect() returns a GSocketConnection, but in some
cases (eg, encrypted SOCKS), GProxy might return a GIOStream that is
not a GSocketConnection. In that case, GSocketClient would wrap the
stream up in a GProxyConnection, which is a subclass of
GSocketConnection but uses the input/output streams of the wrapped
connection.
GTlsConnection is not a GSocketConnection, so it has the same problem,
so it will need the same treatment. Rename the class to
GTcpWrapperStream, and make it public, so people can extract the base
stream from it when necessary.
(This is not ideal and GSocketClient will need to be revisited as an
API at some point...)
https://bugzilla.gnome.org/show_bug.cgi?id=588189
2010-11-02 01:22:24 +01:00
|
|
|
g_object_unref (socket);
|
2009-05-15 21:26:24 +02:00
|
|
|
g_object_unref (address);
|
|
|
|
}
|
|
|
|
g_object_unref (enumerator);
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
return G_SOCKET_CONNECTION (connection);
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_host:
|
2010-04-30 00:51:42 +02:00
|
|
|
* @client: a #GSocketClient
|
2009-05-15 21:26:24 +02:00
|
|
|
* @host_and_port: the name and optionally port of the host to connect to
|
|
|
|
* @default_port: the default port to connect to
|
2010-12-29 16:01:12 +01:00
|
|
|
* @cancellable: (allow-none): a #GCancellable, or %NULL
|
2009-05-15 21:26:24 +02:00
|
|
|
* @error: a pointer to a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* This is a helper function for g_socket_client_connect().
|
|
|
|
*
|
|
|
|
* Attempts to create a TCP connection to the named host.
|
|
|
|
*
|
2011-04-20 19:08:06 +02:00
|
|
|
* @host_and_port may be in any of a number of recognized formats; an IPv6
|
2009-05-15 21:26:24 +02:00
|
|
|
* address, an IPv4 address, or a domain name (in which case a DNS
|
|
|
|
* lookup is performed). Quoting with [] is supported for all address
|
|
|
|
* types. A port override may be specified in the usual way with a
|
|
|
|
* colon. Ports may be given as decimal numbers or symbolic names (in
|
|
|
|
* which case an /etc/services lookup is performed).
|
|
|
|
*
|
|
|
|
* If no port override is given in @host_and_port then @default_port will be
|
|
|
|
* used as the port number to connect to.
|
|
|
|
*
|
|
|
|
* In general, @host_and_port is expected to be provided by the user (allowing
|
2011-04-20 19:08:06 +02:00
|
|
|
* them to give the hostname, and a port override if necessary) and
|
2009-05-15 21:26:24 +02:00
|
|
|
* @default_port is expected to be provided by the application.
|
2009-05-28 00:20:08 +02:00
|
|
|
*
|
2009-05-15 21:26:24 +02:00
|
|
|
* In the case that an IP address is given, a single connection
|
|
|
|
* attempt is made. In the case that a name is given, multiple
|
|
|
|
* connection attempts may be made, in turn and according to the
|
|
|
|
* number of address records in DNS, until a connection succeeds.
|
|
|
|
*
|
|
|
|
* Upon a successful connection, a new #GSocketConnection is constructed
|
|
|
|
* and returned. The caller owns this new object and must drop their
|
|
|
|
* reference to it when finished with it.
|
|
|
|
*
|
|
|
|
* In the event of any failure (DNS error, service not found, no hosts
|
|
|
|
* connectable) %NULL is returned and @error (if non-%NULL) is set
|
|
|
|
* accordingly.
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketConnection *
|
2009-05-28 00:20:08 +02:00
|
|
|
g_socket_client_connect_to_host (GSocketClient *client,
|
|
|
|
const gchar *host_and_port,
|
2009-06-12 15:57:51 +02:00
|
|
|
guint16 default_port,
|
2009-05-28 00:20:08 +02:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
|
|
|
GSocketConnectable *connectable;
|
|
|
|
GSocketConnection *connection;
|
|
|
|
|
|
|
|
connectable = g_network_address_parse (host_and_port, default_port, error);
|
|
|
|
if (connectable == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
connection = g_socket_client_connect (client, connectable,
|
|
|
|
cancellable, error);
|
|
|
|
g_object_unref (connectable);
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
|
2009-05-20 12:41:50 +02:00
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_service:
|
|
|
|
* @client: a #GSocketConnection
|
|
|
|
* @domain: a domain name
|
|
|
|
* @service: the name of the service to connect to
|
2010-12-29 16:01:12 +01:00
|
|
|
* @cancellable: (allow-none): a #GCancellable, or %NULL
|
2009-05-20 12:41:50 +02:00
|
|
|
* @error: a pointer to a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* Attempts to create a TCP connection to a service.
|
|
|
|
*
|
|
|
|
* This call looks up the SRV record for @service at @domain for the
|
|
|
|
* "tcp" protocol. It then attempts to connect, in turn, to each of
|
|
|
|
* the hosts providing the service until either a connection succeeds
|
|
|
|
* or there are no hosts remaining.
|
|
|
|
*
|
|
|
|
* Upon a successful connection, a new #GSocketConnection is constructed
|
|
|
|
* and returned. The caller owns this new object and must drop their
|
|
|
|
* reference to it when finished with it.
|
|
|
|
*
|
|
|
|
* In the event of any failure (DNS error, service not found, no hosts
|
|
|
|
* connectable) %NULL is returned and @error (if non-%NULL) is set
|
|
|
|
* accordingly.
|
2011-11-21 17:03:31 +01:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): a #GSocketConnection if successful, or %NULL on error
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-20 12:41:50 +02:00
|
|
|
GSocketConnection *
|
|
|
|
g_socket_client_connect_to_service (GSocketClient *client,
|
2009-05-28 00:20:08 +02:00
|
|
|
const gchar *domain,
|
|
|
|
const gchar *service,
|
2009-05-20 12:41:50 +02:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSocketConnectable *connectable;
|
|
|
|
GSocketConnection *connection;
|
|
|
|
|
|
|
|
connectable = g_network_service_new (service, "tcp", domain);
|
|
|
|
connection = g_socket_client_connect (client, connectable,
|
|
|
|
cancellable, error);
|
|
|
|
g_object_unref (connectable);
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
|
2010-04-30 00:51:42 +02:00
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_uri:
|
|
|
|
* @client: a #GSocketClient
|
|
|
|
* @uri: A network URI
|
|
|
|
* @default_port: the default port to connect to
|
2010-12-29 16:01:12 +01:00
|
|
|
* @cancellable: (allow-none): a #GCancellable, or %NULL
|
2010-04-30 00:51:42 +02:00
|
|
|
* @error: a pointer to a #GError, or %NULL
|
|
|
|
*
|
|
|
|
* This is a helper function for g_socket_client_connect().
|
|
|
|
*
|
|
|
|
* Attempts to create a TCP connection with a network URI.
|
|
|
|
*
|
|
|
|
* @uri may be any valid URI containing an "authority" (hostname/port)
|
|
|
|
* component. If a port is not specified in the URI, @default_port
|
2010-12-06 17:21:16 +01:00
|
|
|
* will be used. TLS will be negotiated if #GSocketClient:tls is %TRUE.
|
|
|
|
* (#GSocketClient does not know to automatically assume TLS for
|
|
|
|
* certain URI schemes.)
|
2010-04-30 00:51:42 +02:00
|
|
|
*
|
|
|
|
* Using this rather than g_socket_client_connect() or
|
|
|
|
* g_socket_client_connect_to_host() allows #GSocketClient to
|
|
|
|
* determine when to use application-specific proxy protocols.
|
|
|
|
*
|
|
|
|
* Upon a successful connection, a new #GSocketConnection is constructed
|
|
|
|
* and returned. The caller owns this new object and must drop their
|
|
|
|
* reference to it when finished with it.
|
|
|
|
*
|
|
|
|
* In the event of any failure (DNS error, service not found, no hosts
|
|
|
|
* connectable) %NULL is returned and @error (if non-%NULL) is set
|
|
|
|
* accordingly.
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
|
2010-04-30 00:51:42 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
GSocketConnection *
|
|
|
|
g_socket_client_connect_to_uri (GSocketClient *client,
|
|
|
|
const gchar *uri,
|
|
|
|
guint16 default_port,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSocketConnectable *connectable;
|
|
|
|
GSocketConnection *connection;
|
|
|
|
|
|
|
|
connectable = g_network_address_parse_uri (uri, default_port, error);
|
|
|
|
if (connectable == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
connection = g_socket_client_connect (client, connectable,
|
|
|
|
cancellable, error);
|
|
|
|
g_object_unref (connectable);
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *result;
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GSocketClient *client;
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
GSocketConnectable *connectable;
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketAddressEnumerator *enumerator;
|
2010-08-10 22:48:45 +02:00
|
|
|
GProxyAddress *proxy_addr;
|
2011-11-15 01:46:02 +01:00
|
|
|
GSocketAddress *current_addr;
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocket *current_socket;
|
2009-12-21 20:50:32 +01:00
|
|
|
GIOStream *connection;
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
GError *last_error;
|
|
|
|
} GSocketClientAsyncConnectData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
|
|
|
|
{
|
|
|
|
if (data->last_error)
|
|
|
|
{
|
2010-09-23 13:02:50 +02:00
|
|
|
g_simple_async_result_take_error (data->result, data->last_error);
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-10 22:48:45 +02:00
|
|
|
g_assert (data->connection);
|
2009-05-15 21:26:24 +02:00
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
if (!G_IS_SOCKET_CONNECTION (data->connection))
|
|
|
|
{
|
|
|
|
GSocketConnection *wrapper_connection;
|
|
|
|
|
|
|
|
wrapper_connection = g_tcp_wrapper_connection_new (data->connection,
|
|
|
|
data->current_socket);
|
|
|
|
g_object_unref (data->connection);
|
|
|
|
data->connection = (GIOStream *)wrapper_connection;
|
|
|
|
}
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
g_simple_async_result_set_op_res_gpointer (data->result,
|
2010-08-10 22:48:45 +02:00
|
|
|
data->connection,
|
2009-05-15 21:26:24 +02:00
|
|
|
g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_simple_async_result_complete (data->result);
|
|
|
|
g_object_unref (data->result);
|
2009-12-21 20:50:32 +01:00
|
|
|
g_object_unref (data->connectable);
|
2009-07-23 22:27:01 +02:00
|
|
|
g_object_unref (data->enumerator);
|
2010-08-14 22:15:39 +02:00
|
|
|
if (data->cancellable)
|
|
|
|
g_object_unref (data->cancellable);
|
2011-11-15 01:46:02 +01:00
|
|
|
if (data->current_addr)
|
|
|
|
g_object_unref (data->current_addr);
|
2010-08-10 22:48:45 +02:00
|
|
|
if (data->current_socket)
|
|
|
|
g_object_unref (data->current_socket);
|
|
|
|
if (data->proxy_addr)
|
|
|
|
g_object_unref (data->proxy_addr);
|
2009-07-23 22:27:01 +02:00
|
|
|
g_slice_free (GSocketClientAsyncConnectData, data);
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_enumerator_callback (GObject *object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_last_error (GSocketClientAsyncConnectData *data,
|
|
|
|
GError *error)
|
|
|
|
{
|
|
|
|
g_clear_error (&data->last_error);
|
|
|
|
data->last_error = error;
|
|
|
|
}
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
static void
|
|
|
|
enumerator_next_async (GSocketClientAsyncConnectData *data)
|
|
|
|
{
|
2011-11-17 19:01:05 +01:00
|
|
|
/* We need to cleanup the state */
|
|
|
|
g_clear_object (&data->current_socket);
|
|
|
|
g_clear_object (&data->current_addr);
|
|
|
|
g_clear_object (&data->proxy_addr);
|
|
|
|
g_clear_object (&data->connection);
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
g_socket_address_enumerator_next_async (data->enumerator,
|
|
|
|
data->cancellable,
|
|
|
|
g_socket_client_enumerator_callback,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-12-21 20:50:32 +01:00
|
|
|
g_socket_client_tls_handshake_callback (GObject *object,
|
2010-08-10 22:48:45 +02:00
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSocketClientAsyncConnectData *data = user_data;
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
if (g_tls_connection_handshake_finish (G_TLS_CONNECTION (object),
|
|
|
|
result,
|
|
|
|
&data->last_error))
|
|
|
|
{
|
|
|
|
g_object_unref (data->connection);
|
|
|
|
data->connection = G_IO_STREAM (object);
|
2011-08-10 15:56:13 +02:00
|
|
|
|
|
|
|
g_socket_client_async_connect_complete (data);
|
2009-12-21 20:50:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_unref (object);
|
|
|
|
enumerator_next_async (data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_tls_handshake (GSocketClientAsyncConnectData *data)
|
|
|
|
{
|
2010-12-07 16:06:38 +01:00
|
|
|
GIOStream *tlsconn;
|
2009-12-21 20:50:32 +01:00
|
|
|
|
|
|
|
if (!data->client->priv->tls)
|
2010-08-10 22:48:45 +02:00
|
|
|
{
|
2009-12-21 20:50:32 +01:00
|
|
|
g_socket_client_async_connect_complete (data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tlsconn = g_tls_client_connection_new (data->connection,
|
|
|
|
data->connectable,
|
|
|
|
&data->last_error);
|
|
|
|
if (tlsconn)
|
|
|
|
{
|
2010-12-07 16:06:38 +01:00
|
|
|
g_tls_client_connection_set_validation_flags (G_TLS_CLIENT_CONNECTION (tlsconn),
|
|
|
|
data->client->priv->tls_validation_flags);
|
2009-12-21 20:50:32 +01:00
|
|
|
g_tls_connection_handshake_async (G_TLS_CONNECTION (tlsconn),
|
|
|
|
G_PRIORITY_DEFAULT,
|
|
|
|
data->cancellable,
|
|
|
|
g_socket_client_tls_handshake_callback,
|
|
|
|
data);
|
2010-08-10 22:48:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-21 20:50:32 +01:00
|
|
|
enumerator_next_async (data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_proxy_connect_callback (GObject *object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSocketClientAsyncConnectData *data = user_data;
|
|
|
|
|
|
|
|
g_object_unref (data->connection);
|
|
|
|
data->connection = g_proxy_connect_finish (G_PROXY (object),
|
|
|
|
result,
|
|
|
|
&data->last_error);
|
|
|
|
if (!data->connection)
|
|
|
|
{
|
|
|
|
enumerator_next_async (data);
|
|
|
|
return;
|
2010-08-10 22:48:45 +02:00
|
|
|
}
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
g_socket_client_tls_handshake (data);
|
2010-08-10 22:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_proxy_connect (GSocketClientAsyncConnectData *data)
|
|
|
|
{
|
|
|
|
GProxy *proxy;
|
2009-12-21 20:50:32 +01:00
|
|
|
const gchar *protocol;
|
2010-08-10 22:48:45 +02:00
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
if (!data->proxy_addr)
|
|
|
|
{
|
|
|
|
g_socket_client_tls_handshake (data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol = g_proxy_address_get_protocol (data->proxy_addr);
|
2010-08-10 22:48:45 +02:00
|
|
|
proxy = g_proxy_get_default_for_protocol (protocol);
|
|
|
|
|
|
|
|
/* The connection should not be anything else then TCP Connection,
|
|
|
|
* but let's put a safety guard in case
|
|
|
|
*/
|
|
|
|
if (!G_IS_TCP_CONNECTION (data->connection))
|
|
|
|
{
|
|
|
|
g_critical ("Trying to proxy over non-TCP connection, this is "
|
|
|
|
"most likely a bug in GLib IO library.");
|
|
|
|
|
|
|
|
g_set_error_literal (&data->last_error,
|
|
|
|
G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Trying to proxy over non-TCP connection is not supported."));
|
|
|
|
|
|
|
|
enumerator_next_async (data);
|
|
|
|
}
|
|
|
|
else if (proxy)
|
|
|
|
{
|
|
|
|
g_proxy_connect_async (proxy,
|
2009-12-21 20:50:32 +01:00
|
|
|
data->connection,
|
2010-08-10 22:48:45 +02:00
|
|
|
data->proxy_addr,
|
|
|
|
data->cancellable,
|
|
|
|
g_socket_client_proxy_connect_callback,
|
|
|
|
data);
|
|
|
|
g_object_unref (proxy);
|
|
|
|
}
|
2010-08-19 22:23:50 +02:00
|
|
|
else if (!g_hash_table_lookup_extended (data->client->priv->app_proxies,
|
|
|
|
protocol, NULL, NULL))
|
2010-08-10 22:48:45 +02:00
|
|
|
{
|
|
|
|
g_clear_error (&data->last_error);
|
|
|
|
|
|
|
|
g_set_error (&data->last_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
|
|
|
_("Proxy protocol '%s' is not supported."),
|
|
|
|
protocol);
|
|
|
|
|
|
|
|
enumerator_next_async (data);
|
|
|
|
}
|
2011-11-17 19:04:04 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Simply complete the connection, we don't want to do TLS handshake
|
|
|
|
* as the application proxy handling may need proxy handshake first */
|
|
|
|
g_socket_client_async_connect_complete (data);
|
|
|
|
}
|
2010-08-10 22:48:45 +02:00
|
|
|
}
|
|
|
|
|
2010-09-10 15:12:17 +02:00
|
|
|
static void
|
|
|
|
g_socket_client_socket_connected (GSocketClientAsyncConnectData *data)
|
|
|
|
{
|
|
|
|
g_socket_set_blocking (data->current_socket, TRUE);
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
data->connection = (GIOStream *)
|
2010-09-10 15:12:17 +02:00
|
|
|
g_socket_connection_factory_create_connection (data->current_socket);
|
|
|
|
|
2009-12-21 20:50:32 +01:00
|
|
|
g_socket_client_proxy_connect (data);
|
2010-09-10 15:12:17 +02:00
|
|
|
}
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
static gboolean
|
|
|
|
g_socket_client_socket_callback (GSocket *socket,
|
|
|
|
GIOCondition condition,
|
|
|
|
GSocketClientAsyncConnectData *data)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (g_cancellable_is_cancelled (data->cancellable))
|
|
|
|
{
|
|
|
|
/* Cancelled, return done with last error being cancelled */
|
|
|
|
g_clear_error (&data->last_error);
|
|
|
|
g_cancellable_set_error_if_cancelled (data->cancellable,
|
|
|
|
&data->last_error);
|
2010-08-30 15:23:09 +02:00
|
|
|
|
|
|
|
g_socket_client_async_connect_complete (data);
|
|
|
|
return FALSE;
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* socket is ready for writing means connect done, did it succeed? */
|
2009-05-19 10:57:58 +02:00
|
|
|
if (!g_socket_check_connect_result (data->current_socket, &error))
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
2011-11-15 01:46:02 +01:00
|
|
|
clarify_connect_error (error, data->connectable,
|
|
|
|
data->current_addr);
|
2009-05-15 21:26:24 +02:00
|
|
|
set_last_error (data, error);
|
|
|
|
|
|
|
|
/* try next one */
|
2010-08-10 22:48:45 +02:00
|
|
|
enumerator_next_async (data);
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 15:12:17 +02:00
|
|
|
g_socket_client_socket_connected (data);
|
2009-05-15 21:26:24 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_socket_client_enumerator_callback (GObject *object,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSocketClientAsyncConnectData *data = user_data;
|
2010-08-10 22:48:45 +02:00
|
|
|
GSocketAddress *address = NULL;
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocket *socket;
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
|
|
|
|
if (g_cancellable_is_cancelled (data->cancellable))
|
|
|
|
{
|
|
|
|
g_clear_error (&data->last_error);
|
|
|
|
g_cancellable_set_error_if_cancelled (data->cancellable, &data->last_error);
|
|
|
|
g_socket_client_async_connect_complete (data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
address = g_socket_address_enumerator_next_finish (data->enumerator,
|
|
|
|
result, &tmp_error);
|
|
|
|
|
|
|
|
if (address == NULL)
|
|
|
|
{
|
|
|
|
if (tmp_error)
|
|
|
|
set_last_error (data, tmp_error);
|
|
|
|
else if (data->last_error == NULL)
|
2009-05-19 15:03:14 +02:00
|
|
|
g_set_error_literal (&data->last_error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
_("Unknown error on connect"));
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
g_socket_client_async_connect_complete (data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
if (G_IS_PROXY_ADDRESS (address) &&
|
|
|
|
data->client->priv->enable_proxy)
|
|
|
|
data->proxy_addr = g_object_ref (G_PROXY_ADDRESS (address));
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
g_clear_error (&data->last_error);
|
|
|
|
|
|
|
|
socket = create_socket (data->client, address, &data->last_error);
|
|
|
|
if (socket != NULL)
|
|
|
|
{
|
|
|
|
g_socket_set_blocking (socket, FALSE);
|
2009-06-23 23:42:01 +02:00
|
|
|
if (g_socket_connect (socket, address, data->cancellable, &tmp_error))
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
|
|
|
data->current_socket = socket;
|
2010-09-10 15:12:17 +02:00
|
|
|
g_socket_client_socket_connected (data);
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
g_object_unref (address);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_PENDING))
|
|
|
|
{
|
|
|
|
GSource *source;
|
|
|
|
|
|
|
|
data->current_socket = socket;
|
2011-11-15 01:46:02 +01:00
|
|
|
data->current_addr = address;
|
2009-05-15 21:26:24 +02:00
|
|
|
g_error_free (tmp_error);
|
|
|
|
|
|
|
|
source = g_socket_create_source (socket, G_IO_OUT,
|
|
|
|
data->cancellable);
|
|
|
|
g_source_set_callback (source,
|
|
|
|
(GSourceFunc) g_socket_client_socket_callback,
|
|
|
|
data, NULL);
|
2009-06-17 02:22:58 +02:00
|
|
|
g_source_attach (source, g_main_context_get_thread_default ());
|
2009-05-15 21:26:24 +02:00
|
|
|
g_source_unref (source);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-15 01:46:02 +01:00
|
|
|
clarify_connect_error (tmp_error, data->connectable, address);
|
2009-05-15 21:26:24 +02:00
|
|
|
data->last_error = tmp_error;
|
|
|
|
g_object_unref (socket);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
g_object_unref (address);
|
|
|
|
enumerator_next_async (data);
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-05-18 13:02:11 +02:00
|
|
|
* g_socket_client_connect_async:
|
2011-06-05 00:44:44 +02:00
|
|
|
* @client: a #GSocketClient
|
2009-05-15 21:26:24 +02:00
|
|
|
* @connectable: a #GSocketConnectable specifying the remote address.
|
2010-12-29 16:01:12 +01:00
|
|
|
* @cancellable: (allow-none): a #GCancellable, or %NULL
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback
|
|
|
|
* @user_data: (closure): user data for the callback
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* This is the asynchronous version of g_socket_client_connect().
|
|
|
|
*
|
|
|
|
* When the operation is finished @callback will be
|
|
|
|
* called. You can then call g_socket_client_connect_finish() to get
|
|
|
|
* the result of the operation.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
void
|
|
|
|
g_socket_client_connect_async (GSocketClient *client,
|
|
|
|
GSocketConnectable *connectable,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSocketClientAsyncConnectData *data;
|
|
|
|
|
|
|
|
g_return_if_fail (G_IS_SOCKET_CLIENT (client));
|
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
data = g_slice_new0 (GSocketClientAsyncConnectData);
|
2009-05-15 21:26:24 +02:00
|
|
|
|
|
|
|
data->result = g_simple_async_result_new (G_OBJECT (client),
|
|
|
|
callback, user_data,
|
|
|
|
g_socket_client_connect_async);
|
|
|
|
data->client = client;
|
|
|
|
if (cancellable)
|
|
|
|
data->cancellable = g_object_ref (cancellable);
|
2009-12-21 20:50:32 +01:00
|
|
|
else
|
|
|
|
data->cancellable = NULL;
|
|
|
|
data->last_error = NULL;
|
|
|
|
data->connectable = g_object_ref (connectable);
|
2010-08-10 22:48:45 +02:00
|
|
|
|
|
|
|
if (can_use_proxy (client))
|
|
|
|
data->enumerator = g_socket_connectable_proxy_enumerate (connectable);
|
2009-05-15 21:26:24 +02:00
|
|
|
else
|
2010-08-10 22:48:45 +02:00
|
|
|
data->enumerator = g_socket_connectable_enumerate (connectable);
|
2009-05-15 21:26:24 +02:00
|
|
|
|
2010-08-10 22:48:45 +02:00
|
|
|
enumerator_next_async (data);
|
2009-05-15 21:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_host_async:
|
2011-06-05 00:44:44 +02:00
|
|
|
* @client: a #GSocketClient
|
2009-05-15 21:26:24 +02:00
|
|
|
* @host_and_port: the name and optionally the port of the host to connect to
|
|
|
|
* @default_port: the default port to connect to
|
2010-12-29 16:01:12 +01:00
|
|
|
* @cancellable: (allow-none): a #GCancellable, or %NULL
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback
|
|
|
|
* @user_data: (closure): user data for the callback
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* This is the asynchronous version of g_socket_client_connect_to_host().
|
|
|
|
*
|
|
|
|
* When the operation is finished @callback will be
|
|
|
|
* called. You can then call g_socket_client_connect_to_host_finish() to get
|
|
|
|
* the result of the operation.
|
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
void
|
|
|
|
g_socket_client_connect_to_host_async (GSocketClient *client,
|
2009-05-28 00:20:08 +02:00
|
|
|
const gchar *host_and_port,
|
2009-06-12 15:57:51 +02:00
|
|
|
guint16 default_port,
|
2009-05-15 21:26:24 +02:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSocketConnectable *connectable;
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
connectable = g_network_address_parse (host_and_port, default_port,
|
|
|
|
&error);
|
|
|
|
if (connectable == NULL)
|
|
|
|
{
|
2010-09-23 13:47:13 +02:00
|
|
|
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client),
|
2009-05-15 21:26:24 +02:00
|
|
|
callback, user_data, error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_socket_client_connect_async (client,
|
|
|
|
connectable, cancellable,
|
|
|
|
callback, user_data);
|
|
|
|
g_object_unref (connectable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-20 12:41:50 +02:00
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_service_async:
|
|
|
|
* @client: a #GSocketClient
|
|
|
|
* @domain: a domain name
|
|
|
|
* @service: the name of the service to connect to
|
2010-12-29 16:01:12 +01:00
|
|
|
* @cancellable: (allow-none): a #GCancellable, or %NULL
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback
|
|
|
|
* @user_data: (closure): user data for the callback
|
2009-05-20 12:41:50 +02:00
|
|
|
*
|
|
|
|
* This is the asynchronous version of
|
|
|
|
* g_socket_client_connect_to_service().
|
2009-05-28 00:20:08 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
*/
|
2009-05-20 12:41:50 +02:00
|
|
|
void
|
|
|
|
g_socket_client_connect_to_service_async (GSocketClient *client,
|
2009-05-28 00:20:08 +02:00
|
|
|
const gchar *domain,
|
|
|
|
const gchar *service,
|
2009-05-20 12:41:50 +02:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSocketConnectable *connectable;
|
|
|
|
|
|
|
|
connectable = g_network_service_new (service, "tcp", domain);
|
|
|
|
g_socket_client_connect_async (client,
|
|
|
|
connectable, cancellable,
|
|
|
|
callback, user_data);
|
|
|
|
g_object_unref (connectable);
|
|
|
|
}
|
|
|
|
|
2010-04-30 00:51:42 +02:00
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_uri_async:
|
|
|
|
* @client: a #GSocketClient
|
|
|
|
* @uri: a network uri
|
|
|
|
* @default_port: the default port to connect to
|
2010-12-29 16:01:12 +01:00
|
|
|
* @cancellable: (allow-none): a #GCancellable, or %NULL
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback
|
|
|
|
* @user_data: (closure): user data for the callback
|
2010-04-30 00:51:42 +02:00
|
|
|
*
|
|
|
|
* This is the asynchronous version of g_socket_client_connect_to_uri().
|
|
|
|
*
|
|
|
|
* When the operation is finished @callback will be
|
|
|
|
* called. You can then call g_socket_client_connect_to_uri_finish() to get
|
|
|
|
* the result of the operation.
|
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_socket_client_connect_to_uri_async (GSocketClient *client,
|
|
|
|
const gchar *uri,
|
|
|
|
guint16 default_port,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSocketConnectable *connectable;
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
connectable = g_network_address_parse_uri (uri, default_port, &error);
|
|
|
|
if (connectable == NULL)
|
|
|
|
{
|
2010-09-23 13:47:13 +02:00
|
|
|
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client),
|
2010-04-30 00:51:42 +02:00
|
|
|
callback, user_data, error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_socket_client_connect_async (client,
|
|
|
|
connectable, cancellable,
|
|
|
|
callback, user_data);
|
|
|
|
g_object_unref (connectable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-15 21:26:24 +02:00
|
|
|
/**
|
|
|
|
* g_socket_client_connect_finish:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @result: a #GAsyncResult.
|
2011-04-20 19:08:06 +02:00
|
|
|
* @error: a #GError location to store the error occurring, or %NULL to
|
2009-05-15 21:26:24 +02:00
|
|
|
* ignore.
|
|
|
|
*
|
|
|
|
* Finishes an async connect operation. See g_socket_client_connect_async()
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketConnection *
|
|
|
|
g_socket_client_connect_finish (GSocketClient *client,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (simple, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_host_finish:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @result: a #GAsyncResult.
|
2011-04-20 19:08:06 +02:00
|
|
|
* @error: a #GError location to store the error occurring, or %NULL to
|
2009-05-15 21:26:24 +02:00
|
|
|
* ignore.
|
|
|
|
*
|
|
|
|
* Finishes an async connect operation. See g_socket_client_connect_to_host_async()
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
|
2009-05-15 21:26:24 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-15 21:26:24 +02:00
|
|
|
GSocketConnection *
|
2009-05-28 00:20:08 +02:00
|
|
|
g_socket_client_connect_to_host_finish (GSocketClient *client,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2009-05-15 21:26:24 +02:00
|
|
|
{
|
|
|
|
return g_socket_client_connect_finish (client, result, error);
|
|
|
|
}
|
|
|
|
|
2009-05-20 12:41:50 +02:00
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_service_finish:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @result: a #GAsyncResult.
|
2011-04-20 19:08:06 +02:00
|
|
|
* @error: a #GError location to store the error occurring, or %NULL to
|
2009-05-20 12:41:50 +02:00
|
|
|
* ignore.
|
|
|
|
*
|
|
|
|
* Finishes an async connect operation. See g_socket_client_connect_to_service_async()
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
|
2009-05-20 12:41:50 +02:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
2009-05-28 00:20:08 +02:00
|
|
|
*/
|
2009-05-20 12:41:50 +02:00
|
|
|
GSocketConnection *
|
2009-05-28 00:20:08 +02:00
|
|
|
g_socket_client_connect_to_service_finish (GSocketClient *client,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2009-05-20 12:41:50 +02:00
|
|
|
{
|
|
|
|
return g_socket_client_connect_finish (client, result, error);
|
|
|
|
}
|
2010-04-30 00:51:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_connect_to_uri_finish:
|
|
|
|
* @client: a #GSocketClient.
|
|
|
|
* @result: a #GAsyncResult.
|
2011-04-20 19:08:06 +02:00
|
|
|
* @error: a #GError location to store the error occurring, or %NULL to
|
2010-04-30 00:51:42 +02:00
|
|
|
* ignore.
|
|
|
|
*
|
|
|
|
* Finishes an async connect operation. See g_socket_client_connect_to_uri_async()
|
|
|
|
*
|
2010-09-24 23:24:41 +02:00
|
|
|
* Returns: (transfer full): a #GSocketConnection on success, %NULL on error.
|
2010-04-30 00:51:42 +02:00
|
|
|
*
|
|
|
|
* Since: 2.26
|
|
|
|
*/
|
|
|
|
GSocketConnection *
|
|
|
|
g_socket_client_connect_to_uri_finish (GSocketClient *client,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
return g_socket_client_connect_finish (client, result, error);
|
|
|
|
}
|
2010-08-19 22:23:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* g_socket_client_add_application_proxy:
|
|
|
|
* @client: a #GSocketClient
|
|
|
|
* @protocol: The proxy protocol
|
|
|
|
*
|
|
|
|
* Enable proxy protocols to be handled by the application. When the
|
|
|
|
* indicated proxy protocol is returned by the #GProxyResolver,
|
|
|
|
* #GSocketClient will consider this protocol as supported but will
|
2011-04-20 19:08:06 +02:00
|
|
|
* not try to find a #GProxy instance to handle handshaking. The
|
2010-08-19 22:23:50 +02:00
|
|
|
* application must check for this case by calling
|
|
|
|
* g_socket_connection_get_remote_address() on the returned
|
|
|
|
* #GSocketConnection, and seeing if it's a #GProxyAddress of the
|
|
|
|
* appropriate type, to determine whether or not it needs to handle
|
|
|
|
* the proxy handshaking itself.
|
|
|
|
*
|
|
|
|
* This should be used for proxy protocols that are dialects of
|
|
|
|
* another protocol such as HTTP proxy. It also allows cohabitation of
|
|
|
|
* proxy protocols that are reused between protocols. A good example
|
|
|
|
* is HTTP. It can be used to proxy HTTP, FTP and Gopher and can also
|
|
|
|
* be use as generic socket proxy through the HTTP CONNECT method.
|
2011-11-17 19:04:04 +01:00
|
|
|
*
|
|
|
|
* When the proxy is detected as being an application proxy, TLS handshake
|
|
|
|
* will be skipped. This is required to let the application do the proxy
|
|
|
|
* specific handshake.
|
2010-08-19 22:23:50 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
g_socket_client_add_application_proxy (GSocketClient *client,
|
|
|
|
const gchar *protocol)
|
|
|
|
{
|
|
|
|
g_hash_table_insert (client->priv->app_proxies, g_strdup (protocol), NULL);
|
|
|
|
}
|