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
|
|
|
/* GIO - GLib Input, Output and Streaming Library
|
|
|
|
*
|
|
|
|
* Copyright © 2010 Collabora Ltd.
|
|
|
|
*
|
2022-05-18 10:12:45 +02:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*
|
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
|
|
|
* 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
|
2017-05-27 18:21:30 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
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
|
|
|
*
|
|
|
|
* 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
|
2014-01-23 12:58:29 +01:00
|
|
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
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
|
|
|
*
|
|
|
|
* Authors: Nicolas Dufresne <nicolas.dufresne@colllabora.co.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2023-10-25 16:07:42 +02:00
|
|
|
* GTcpWrapperConnection:
|
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
|
|
|
*
|
2023-10-25 16:07:42 +02:00
|
|
|
* A `GTcpWrapperConnection` can be used to wrap a [class@Gio.IOStream] that is
|
|
|
|
* based on a [class@Gio.Socket], but which is not actually a
|
|
|
|
* [class@Gio.SocketConnection]. This is used by [class@Gio.SocketClient] so
|
|
|
|
* that it can always return a [class@Gio.SocketConnection], even when the
|
|
|
|
* connection it has actually created is not directly a
|
|
|
|
* [class@Gio.SocketConnection].
|
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
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtcpwrapperconnection.h"
|
|
|
|
|
|
|
|
#include "gtcpconnection.h"
|
|
|
|
#include "glibintl.h"
|
|
|
|
|
2013-06-11 01:29:58 +02:00
|
|
|
struct _GTcpWrapperConnectionPrivate
|
|
|
|
{
|
|
|
|
GIOStream *base_io_stream;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GTcpWrapperConnection, g_tcp_wrapper_connection, G_TYPE_TCP_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
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_NONE,
|
|
|
|
PROP_BASE_IO_STREAM
|
|
|
|
};
|
|
|
|
|
|
|
|
static GInputStream *
|
|
|
|
g_tcp_wrapper_connection_get_input_stream (GIOStream *io_stream)
|
|
|
|
{
|
|
|
|
GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (io_stream);
|
|
|
|
|
|
|
|
return g_io_stream_get_input_stream (connection->priv->base_io_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GOutputStream *
|
|
|
|
g_tcp_wrapper_connection_get_output_stream (GIOStream *io_stream)
|
|
|
|
{
|
|
|
|
GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (io_stream);
|
|
|
|
|
|
|
|
return g_io_stream_get_output_stream (connection->priv->base_io_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_tcp_wrapper_connection_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BASE_IO_STREAM:
|
|
|
|
g_value_set_object (value, connection->priv->base_io_stream);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_tcp_wrapper_connection_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_BASE_IO_STREAM:
|
|
|
|
connection->priv->base_io_stream = g_value_dup_object (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_tcp_wrapper_connection_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GTcpWrapperConnection *connection = G_TCP_WRAPPER_CONNECTION (object);
|
|
|
|
|
|
|
|
if (connection->priv->base_io_stream)
|
|
|
|
g_object_unref (connection->priv->base_io_stream);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (g_tcp_wrapper_connection_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_tcp_wrapper_connection_class_init (GTcpWrapperConnectionClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GIOStreamClass *stream_class = G_IO_STREAM_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property = g_tcp_wrapper_connection_set_property;
|
|
|
|
gobject_class->get_property = g_tcp_wrapper_connection_get_property;
|
|
|
|
gobject_class->finalize = g_tcp_wrapper_connection_finalize;
|
|
|
|
|
|
|
|
stream_class->get_input_stream = g_tcp_wrapper_connection_get_input_stream;
|
|
|
|
stream_class->get_output_stream = g_tcp_wrapper_connection_get_output_stream;
|
|
|
|
|
2023-11-29 14:23:09 +01:00
|
|
|
/**
|
|
|
|
* GTcpWrapperConnection:base-io-stream:
|
|
|
|
*
|
|
|
|
* The wrapped [class@Gio.IOStream].
|
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
*/
|
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_class_install_property (gobject_class,
|
|
|
|
PROP_BASE_IO_STREAM,
|
2023-04-28 01:59:26 +02:00
|
|
|
g_param_spec_object ("base-io-stream", NULL, NULL,
|
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_TYPE_IO_STREAM,
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_tcp_wrapper_connection_init (GTcpWrapperConnection *connection)
|
|
|
|
{
|
2013-06-24 16:43:04 +02:00
|
|
|
connection->priv = g_tcp_wrapper_connection_get_instance_private (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_tcp_wrapper_connection_new:
|
|
|
|
* @base_io_stream: the #GIOStream to wrap
|
|
|
|
* @socket: the #GSocket associated with @base_io_stream
|
|
|
|
*
|
|
|
|
* Wraps @base_io_stream and @socket together as a #GSocketConnection.
|
|
|
|
*
|
2014-02-20 01:35:23 +01:00
|
|
|
* Returns: the new #GSocketConnection.
|
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
|
|
|
*
|
|
|
|
* Since: 2.28
|
|
|
|
*/
|
|
|
|
GSocketConnection *
|
|
|
|
g_tcp_wrapper_connection_new (GIOStream *base_io_stream,
|
|
|
|
GSocket *socket)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_IO_STREAM (base_io_stream), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_SOCKET (socket), NULL);
|
|
|
|
g_return_val_if_fail (g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV4 ||
|
|
|
|
g_socket_get_family (socket) == G_SOCKET_FAMILY_IPV6, NULL);
|
|
|
|
g_return_val_if_fail (g_socket_get_socket_type (socket) == G_SOCKET_TYPE_STREAM, NULL);
|
|
|
|
|
|
|
|
return g_object_new (G_TYPE_TCP_WRAPPER_CONNECTION,
|
|
|
|
"base-io-stream", base_io_stream,
|
|
|
|
"socket", socket,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* g_tcp_wrapper_connection_get_base_io_stream:
|
|
|
|
* @conn: a #GTcpWrapperConnection
|
|
|
|
*
|
2020-06-12 15:02:30 +02:00
|
|
|
* Gets @conn's base #GIOStream
|
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
|
|
|
*
|
2014-02-20 01:35:23 +01:00
|
|
|
* Returns: (transfer none): @conn's base #GIOStream
|
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
|
|
|
*/
|
|
|
|
GIOStream *
|
|
|
|
g_tcp_wrapper_connection_get_base_io_stream (GTcpWrapperConnection *conn)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (G_IS_TCP_WRAPPER_CONNECTION (conn), NULL);
|
|
|
|
|
|
|
|
return conn->priv->base_io_stream;
|
|
|
|
}
|