From 0b933ff87b55ec235c22252cff82c68bcd603b3b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 30 May 2013 17:31:13 +0200 Subject: [PATCH] rtsp: add method to get the TLS connection --- gst-libs/gst/rtsp/gstrtspconnection.c | 47 +++++++++++++++++++++++++++++++++++ gst-libs/gst/rtsp/gstrtspconnection.h | 3 +++ win32/common/libgstrtsp.def | 1 + 3 files changed, 51 insertions(+) diff --git a/gst-libs/gst/rtsp/gstrtspconnection.c b/gst-libs/gst/rtsp/gstrtspconnection.c index f8c6f75..341a616 100644 --- a/gst-libs/gst/rtsp/gstrtspconnection.c +++ b/gst-libs/gst/rtsp/gstrtspconnection.c @@ -108,6 +108,7 @@ struct _GstRTSPConnection /* URL for the remote connection */ GstRTSPUrl *url; + gboolean server; GSocketClient *client; GIOStream *stream0; GIOStream *stream1; @@ -308,6 +309,7 @@ gst_rtsp_connection_create_from_socket (GSocket * socket, const gchar * ip, stream = G_IO_STREAM (g_socket_connection_factory_create_connection (socket)); /* both read and write initially */ + newconn->server = TRUE; newconn->socket0 = socket; newconn->stream0 = stream; newconn->write_socket = newconn->read_socket = newconn->socket0; @@ -397,6 +399,51 @@ getnameinfo_failed: } } +/** + * gst_rtsp_connection_get_tls: + * @conn: a #GstRTSPConnection + * @error: #GError for error reporting, or NULL to ignore. + * + * Get the TLS connection of @conn. + * + * For client side this will return the #GTlsClientConnection when connected + * over TLS. + * + * For server side connections, this function will create a GTlsServerConnection + * when called the first time and will return that same connection on subsequent + * calls. The server is then responsible for configuring the TLS connection. + * + * Returns: (transfer none): the TLS connection for @conn. + * + * Since: 1.2 + */ +GTlsConnection * +gst_rtsp_connection_get_tls (GstRTSPConnection * conn, GError ** error) +{ + GTlsConnection *result; + + if (G_IS_TLS_CONNECTION (conn->stream0)) { + /* we already had one, return it */ + result = G_TLS_CONNECTION (conn->stream0); + } else if (conn->server) { + /* no TLS connection but we are server, make one */ + result = (GTlsConnection *) + g_tls_server_connection_new (conn->stream0, NULL, error); + if (result) { + g_object_unref (conn->stream0); + conn->stream0 = G_IO_STREAM (result); + conn->input_stream = g_io_stream_get_input_stream (conn->stream0); + conn->output_stream = g_io_stream_get_output_stream (conn->stream0); + } + } else { + /* client */ + result = NULL; + g_set_error (error, GST_LIBRARY_ERROR, GST_LIBRARY_ERROR_FAILED, + "client not connected with TLS"); + } + return result; +} + static GstRTSPResult setup_tunneling (GstRTSPConnection * conn, GTimeVal * timeout, gchar * uri) { diff --git a/gst-libs/gst/rtsp/gstrtspconnection.h b/gst-libs/gst/rtsp/gstrtspconnection.h index 5073c3e..dbd3ada 100644 --- a/gst-libs/gst/rtsp/gstrtspconnection.h +++ b/gst-libs/gst/rtsp/gstrtspconnection.h @@ -72,6 +72,9 @@ GstRTSPResult gst_rtsp_connection_connect (GstRTSPConnection *conn, GstRTSPResult gst_rtsp_connection_close (GstRTSPConnection *conn); GstRTSPResult gst_rtsp_connection_free (GstRTSPConnection *conn); +/* TLS connections */ +GTlsConnection * gst_rtsp_connection_get_tls (GstRTSPConnection * conn, GError ** error); + /* sending/receiving raw bytes */ GstRTSPResult gst_rtsp_connection_read (GstRTSPConnection * conn, guint8 * data, diff --git a/win32/common/libgstrtsp.def b/win32/common/libgstrtsp.def index 736b62a..c5f85f3 100644 --- a/win32/common/libgstrtsp.def +++ b/win32/common/libgstrtsp.def @@ -12,6 +12,7 @@ EXPORTS gst_rtsp_connection_get_ip gst_rtsp_connection_get_read_socket gst_rtsp_connection_get_remember_session_id + gst_rtsp_connection_get_tls gst_rtsp_connection_get_tunnelid gst_rtsp_connection_get_url gst_rtsp_connection_get_write_socket -- 2.7.4