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
This commit is contained in:
Philip Withnall 2017-09-11 09:57:30 +01:00
parent 51e852e5d0
commit 52dd98475c

View File

@ -230,14 +230,22 @@ g_tls_backend_get_server_connection_type (GTlsBackend *backend)
* Gets the #GType of @backends #GDtlsClientConnection implementation.
*
* Returns: the #GType of @backends #GDtlsClientConnection
* implementation.
* implementation, or %G_TYPE_INVALID if this backend doesnt 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 @backends #GDtlsServerConnection implementation.
*
* Returns: the #GType of @backends #GDtlsServerConnection
* implementation.
* implementation, or %G_TYPE_INVALID if this backend doesnt 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 ();
}
/**