[glib-networking/mcatanzaro/tls-thread: 14/24] progress
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/mcatanzaro/tls-thread: 14/24] progress
- Date: Sat, 28 Dec 2019 21:04:39 +0000 (UTC)
commit c942a467055ba036933d42ebd2a0d37c8eb8447b
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Dec 22 18:31:10 2019 -0600
progress
tls/base/gtlsconnection-base.c | 3 --
tls/base/gtlsoperationsthread-base.c | 21 +++++++++-
tls/gnutls/gtlsconnection-gnutls.c | 1 -
tls/gnutls/gtlsoperationsthread-gnutls.c | 64 +++++++++++++++++++-----------
tls/openssl/gtlsoperationsthread-openssl.c | 39 +++++++++++++-----
5 files changed, 90 insertions(+), 38 deletions(-)
---
diff --git a/tls/base/gtlsconnection-base.c b/tls/base/gtlsconnection-base.c
index 71667ca..0576d06 100644
--- a/tls/base/gtlsconnection-base.c
+++ b/tls/base/gtlsconnection-base.c
@@ -1721,7 +1721,6 @@ g_tls_connection_base_handshake_async (GTlsConnection *conn,
{
GTlsConnectionBase *tls = G_TLS_CONNECTION_BASE (conn);
GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
- GTlsConnectionBaseClass *tls_class = G_TLS_CONNECTION_BASE_GET_CLASS (tls);
GTask *thread_task, *caller_task;
g_tls_log_debug (tls, "Starting asynchronous TLS handshake");
@@ -1780,7 +1779,6 @@ start_async_implicit_handshake (GTlsConnectionBase *tls,
GError **error)
{
GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
- GTlsConnectionBaseClass *tls_class = G_TLS_CONNECTION_BASE_GET_CLASS (tls);
g_tls_log_debug (tls, "Starting async implicit handshake");
@@ -1817,7 +1815,6 @@ do_sync_implicit_handshake (GTlsConnectionBase *tls,
GError **error)
{
GTlsConnectionBasePrivate *priv = g_tls_connection_base_get_instance_private (tls);
- GTlsConnectionBaseClass *tls_class = G_TLS_CONNECTION_BASE_GET_CLASS (tls);
GError *my_error = NULL;
gboolean success;
diff --git a/tls/base/gtlsoperationsthread-base.c b/tls/base/gtlsoperationsthread-base.c
index 62efc40..0ee81f1 100644
--- a/tls/base/gtlsoperationsthread-base.c
+++ b/tls/base/gtlsoperationsthread-base.c
@@ -157,7 +157,12 @@ enum
static GParamSpec *obj_properties[LAST_PROP];
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GTlsOperationsThreadBase, g_tls_operations_thread_base, G_TYPE_OBJECT)
+static void g_tls_operations_thread_base_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GTlsOperationsThreadBase, g_tls_operations_thread_base, G_TYPE_OBJECT,
+ G_ADD_PRIVATE (GTlsOperationsThreadBase);
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ g_tls_operations_thread_base_initable_iface_init);)
GTlsConnectionBase *
g_tls_operations_thread_base_get_connection (GTlsOperationsThreadBase *self)
@@ -1182,6 +1187,14 @@ g_tls_operations_thread_base_set_property (GObject *object,
}
}
+static gboolean
+g_tls_operations_thread_base_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ return TRUE;
+}
+
static void
g_tls_operations_thread_base_init (GTlsOperationsThreadBase *self)
{
@@ -1244,3 +1257,9 @@ g_tls_operations_thread_base_class_init (GTlsOperationsThreadBaseClass *klass)
g_object_class_install_properties (gobject_class, LAST_PROP, obj_properties);
}
+
+static void
+g_tls_operations_thread_base_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = g_tls_operations_thread_base_initable_init;
+}
diff --git a/tls/gnutls/gtlsconnection-gnutls.c b/tls/gnutls/gtlsconnection-gnutls.c
index 6b8f88f..40115c9 100644
--- a/tls/gnutls/gtlsconnection-gnutls.c
+++ b/tls/gnutls/gtlsconnection-gnutls.c
@@ -158,7 +158,6 @@ g_tls_connection_gnutls_is_session_resumed (GTlsConnectionBase *tls)
static void
g_tls_connection_gnutls_class_init (GTlsConnectionGnutlsClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GTlsConnectionBaseClass *base_class = G_TLS_CONNECTION_BASE_CLASS (klass);
base_class->create_op_thread = g_tls_connection_gnutls_create_op_thread;
diff --git a/tls/gnutls/gtlsoperationsthread-gnutls.c b/tls/gnutls/gtlsoperationsthread-gnutls.c
index 570900a..560b6e1 100644
--- a/tls/gnutls/gtlsoperationsthread-gnutls.c
+++ b/tls/gnutls/gtlsoperationsthread-gnutls.c
@@ -91,7 +91,14 @@ static GParamSpec *obj_properties[LAST_PROP];
static gnutls_priority_t priority;
-G_DEFINE_TYPE (GTlsOperationsThreadGnutls, g_tls_operations_thread_gnutls, G_TYPE_TLS_OPERATIONS_THREAD_BASE)
+static GInitableIface *g_tls_operations_thread_gnutls_parent_initable_iface;
+
+static void g_tls_operations_thread_gnutls_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GTlsOperationsThreadGnutls, g_tls_operations_thread_gnutls,
G_TYPE_TLS_OPERATIONS_THREAD_BASE,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ g_tls_operations_thread_gnutls_initable_iface_init);
+ )
static inline gboolean
is_dtls (GTlsOperationsThreadGnutls *self)
@@ -540,7 +547,6 @@ g_tls_operations_thread_gnutls_handshake (GTlsOperationsThreadBase *base,
GError **error)
{
GTlsOperationsThreadGnutls *self = G_TLS_OPERATIONS_THREAD_GNUTLS (base);
- GTlsConnectionBase *tls;
GTlsConnectionBaseStatus status;
gnutls_datum_t protocol;
int ret;
@@ -609,7 +615,7 @@ g_tls_operations_thread_gnutls_read (GTlsOperationsThreadBase *base,
if (self->application_data_buffer)
{
*nread = MIN (size, self->application_data_buffer->len);
- memcpy (buffer, self->application_data_buffer->data, nread);
+ memcpy (buffer, self->application_data_buffer->data, *nread);
if (*nread == self->application_data_buffer->len)
g_clear_pointer (&self->application_data_buffer, g_byte_array_unref);
else
@@ -1394,23 +1400,28 @@ g_tls_operations_thread_gnutls_finalize (GObject *object)
G_OBJECT_CLASS (g_tls_operations_thread_gnutls_parent_class)->finalize (object);
}
-static void
-g_tls_operations_thread_gnutls_constructed (GObject *object)
+static gboolean
+g_tls_operations_thread_gnutls_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
{
- GTlsOperationsThreadGnutls *self = G_TLS_OPERATIONS_THREAD_GNUTLS (object);
+ GTlsOperationsThreadGnutls *self = G_TLS_OPERATIONS_THREAD_GNUTLS (initable);
GTlsConnectionBase *tls;
int ret;
- G_OBJECT_CLASS (g_tls_operations_thread_gnutls_parent_class)->constructed (object);
+ if (!g_tls_operations_thread_gnutls_parent_initable_iface->init (initable, cancellable, error))
+ return FALSE;
tls = g_tls_operations_thread_base_get_connection (G_TLS_OPERATIONS_THREAD_BASE (self));
ret = gnutls_certificate_allocate_credentials (&self->creds);
- /* FIXME: GInitable? */
-#if 0
- if (ret != GNUTLS_E_SUCCESS)
- return FALSE;
-#endif
+ if (ret != 0)
+ {
+ g_set_error (error, G_TLS_ERROR, G_TLS_ERROR_MISC,
+ _("Failed to allocate credentials: %s"),
+ gnutls_strerror (ret));
+ return FALSE;
+ }
gnutls_certificate_set_retrieve_function2 (self->creds, retrieve_certificate_cb);
gnutls_init (&self->session, self->init_flags);
@@ -1421,16 +1432,13 @@ g_tls_operations_thread_gnutls_constructed (GObject *object)
ret = gnutls_credentials_set (self->session,
GNUTLS_CRD_CERTIFICATE,
self->creds);
- /* FIXME: GInitable? */
-#if 0
if (ret != 0)
{
g_set_error (error, G_TLS_ERROR, G_TLS_ERROR_MISC,
_("Could not create TLS connection: %s"),
- gnutls_strerror (status));
+ gnutls_strerror (ret));
return FALSE;
}
-#endif
gnutls_transport_set_push_function (self->session,
g_tls_operations_thread_gnutls_push_func);
@@ -1458,6 +1466,8 @@ g_tls_operations_thread_gnutls_constructed (GObject *object)
GNUTLS_HOOK_POST,
session_ticket_received_cb);
}
+
+ return TRUE;
}
static void
@@ -1474,7 +1484,6 @@ g_tls_operations_thread_gnutls_class_init (GTlsOperationsThreadGnutlsClass *klas
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GTlsOperationsThreadBaseClass *base_class = G_TLS_OPERATIONS_THREAD_BASE_CLASS (klass);
- gobject_class->constructed = g_tls_operations_thread_gnutls_constructed;
gobject_class->finalize = g_tls_operations_thread_gnutls_finalize;
gobject_class->get_property = g_tls_operations_thread_gnutls_get_property;
gobject_class->set_property = g_tls_operations_thread_gnutls_set_property;
@@ -1520,12 +1529,21 @@ g_tls_operations_thread_gnutls_new (GTlsConnectionGnutls *connection,
GDatagramBased *base_socket,
guint flags)
{
- return G_TLS_OPERATIONS_THREAD_BASE (g_object_new (G_TYPE_TLS_OPERATIONS_THREAD_GNUTLS,
- "base-iostream", base_iostream,
- "base-socket", base_socket,
- "gnutls-flags", flags,
- "tls-connection", connection,
- NULL));
+ return g_initable_new (G_TYPE_TLS_OPERATIONS_THREAD_GNUTLS,
+ NULL, NULL,
+ "base-iostream", base_iostream,
+ "base-socket", base_socket,
+ "gnutls-flags", flags,
+ "tls-connection", connection,
+ NULL);
+}
+
+static void
+g_tls_operations_thread_gnutls_initable_iface_init (GInitableIface *iface)
+{
+ g_tls_operations_thread_gnutls_parent_initable_iface = g_type_interface_peek_parent (iface);
+
+ iface->init = g_tls_operations_thread_gnutls_initable_init;
}
/* FIXME: must remove this! */
diff --git a/tls/openssl/gtlsoperationsthread-openssl.c b/tls/openssl/gtlsoperationsthread-openssl.c
index f3f0fd8..3825a39 100644
--- a/tls/openssl/gtlsoperationsthread-openssl.c
+++ b/tls/openssl/gtlsoperationsthread-openssl.c
@@ -39,7 +39,14 @@ struct _GTlsOperationsThreadOpenssl {
gboolean shutting_down;
};
-G_DEFINE_TYPE (GTlsOperationsThreadOpenssl, g_tls_operations_thread_openssl,
G_TYPE_TLS_OPERATIONS_THREAD_BASE)
+static GInitableIface *g_tls_operations_thread_openssl_parent_initable_iface;
+
+static void g_tls_operations_thread_openssl_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GTlsOperationsThreadOpenssl, g_tls_operations_thread_openssl,
G_TYPE_TLS_OPERATIONS_THREAD_BASE,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ g_tls_operations_thread_openssl_initable_iface_init);
+ )
static GTlsConnectionBaseStatus
end_openssl_io (GTlsOperationsThreadOpenssl *self,
@@ -266,16 +273,21 @@ g_tls_operations_thread_openssl_close (GTlsOperationsThreadBase *base,
return status;
}
-static void
-g_tls_operations_thread_openssl_constructed (GObject *object)
+static gboolean
+g_tls_operations_thread_openssl_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
{
- GTlsOperationsThreadOpenssl *self = G_TLS_OPERATIONS_THREAD_OPENSSL (object);
+ GTlsOperationsThreadOpenssl *self = G_TLS_OPERATIONS_THREAD_OPENSSL (initable);
GTlsConnectionBase *openssl;
- G_OBJECT_CLASS (g_tls_operations_thread_openssl_parent_class)->constructed (object);
+ if (!g_tls_operations_thread_openssl_parent_initable_iface->init (initable, cancellable, error))
+ return FALSE;
openssl = g_tls_operations_thread_base_get_connection (G_TLS_OPERATIONS_THREAD_BASE (self));
self->ssl = g_tls_connection_openssl_get_ssl (G_TLS_CONNECTION_OPENSSL (openssl));
+
+ return TRUE;
}
static void
@@ -289,18 +301,25 @@ g_tls_operations_thread_openssl_class_init (GTlsOperationsThreadOpensslClass *kl
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GTlsOperationsThreadBaseClass *base_class = G_TLS_OPERATIONS_THREAD_BASE_CLASS (klass);
- gobject_class->constructed = g_tls_operations_thread_openssl_constructed;
-
base_class->handshake_fn = g_tls_operations_thread_openssl_handshake;
base_class->read_fn = g_tls_operations_thread_openssl_read;
base_class->write_fn = g_tls_operations_thread_openssl_write;
base_class->close_fn = g_tls_operations_thread_openssl_close;
}
+static void
+g_tls_operations_thread_openssl_initable_iface_init (GInitableIface *iface)
+{
+ g_tls_operations_thread_openssl_parent_initable_iface = g_type_interface_peek_parent (iface);
+
+ iface->init = g_tls_operations_thread_openssl_initable_init;
+}
+
GTlsOperationsThreadBase *
g_tls_operations_thread_openssl_new (GTlsConnectionOpenssl *tls)
{
- return G_TLS_OPERATIONS_THREAD_BASE (g_object_new (G_TYPE_TLS_OPERATIONS_THREAD_OPENSSL,
- "tls-connection", tls,
- NULL));
+ return g_initable_init (G_TYPE_TLS_OPERATIONS_THREAD_OPENSSL,
+ NULL, NULL,
+ "tls-connection", tls,
+ NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]