[glib] gtlsbackend: Add missing preconditions for DTLS virtual methods
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gtlsbackend: Add missing preconditions for DTLS virtual methods
- Date: Mon, 11 Sep 2017 18:15:40 +0000 (UTC)
commit 52dd98475c45da92f971a15c6c9650b3bb1332ea
Author: Philip Withnall <withnall endlessm com>
Date: Mon Sep 11 09:57:30 2017 +0100
gtlsbackend: Add missing preconditions for DTLS virtual methods
Make it a bit more obvious when the DTLS methods aren’t implemented by a
particular TLS backend; return an invalid type rather than crashing.
Signed-off-by: Philip Withnall <withnall endlessm com>
https://bugzilla.gnome.org/show_bug.cgi?id=752240
gio/gtlsbackend.c | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/gio/gtlsbackend.c b/gio/gtlsbackend.c
index a78d84b..db156c8 100644
--- a/gio/gtlsbackend.c
+++ b/gio/gtlsbackend.c
@@ -230,14 +230,22 @@ g_tls_backend_get_server_connection_type (GTlsBackend *backend)
* Gets the #GType of @backend’s #GDtlsClientConnection implementation.
*
* Returns: the #GType of @backend’s #GDtlsClientConnection
- * implementation.
+ * implementation, or %G_TYPE_INVALID if this backend doesn’t support DTLS.
*
* Since: 2.48
*/
GType
g_tls_backend_get_dtls_client_connection_type (GTlsBackend *backend)
{
- return G_TLS_BACKEND_GET_INTERFACE (backend)->get_dtls_client_connection_type ();
+ GTlsBackendInterface *iface;
+
+ g_return_val_if_fail (G_IS_TLS_BACKEND (backend), G_TYPE_INVALID);
+
+ iface = G_TLS_BACKEND_GET_INTERFACE (backend);
+ if (iface->get_dtls_client_connection_type == NULL)
+ return G_TYPE_INVALID;
+
+ return iface->get_dtls_client_connection_type ();
}
/**
@@ -247,14 +255,22 @@ g_tls_backend_get_dtls_client_connection_type (GTlsBackend *backend)
* Gets the #GType of @backend’s #GDtlsServerConnection implementation.
*
* Returns: the #GType of @backend’s #GDtlsServerConnection
- * implementation.
+ * implementation, or %G_TYPE_INVALID if this backend doesn’t support DTLS.
*
* Since: 2.48
*/
GType
g_tls_backend_get_dtls_server_connection_type (GTlsBackend *backend)
{
- return G_TLS_BACKEND_GET_INTERFACE (backend)->get_dtls_server_connection_type ();
+ GTlsBackendInterface *iface;
+
+ g_return_val_if_fail (G_IS_TLS_BACKEND (backend), G_TYPE_INVALID);
+
+ iface = G_TLS_BACKEND_GET_INTERFACE (backend);
+ if (iface->get_dtls_server_connection_type == NULL)
+ return G_TYPE_INVALID;
+
+ return iface->get_dtls_server_connection_type ();
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]