Commit 30d18b6a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

tls: add vlc_tls_DummyCreate()

parent 754c3ef0
......@@ -132,6 +132,16 @@ static inline int vlc_tls_SessionHandshake (vlc_tls_creds_t *crd,
*/
VLC_API void vlc_tls_Delete (vlc_tls_creds_t *);
/**
* Fakes a TLS session.
*
* Creates a dummy TLS session structure from a socket file descriptor. Data
* will be sent and received directly through the socket. This can be used
* either to share common code between non-TLS and TLS cases, or for testing
* purposes.
*/
VLC_API vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd);
/** @} */
#endif
......@@ -431,6 +431,7 @@ vlc_tls_SessionDelete
vlc_tls_Read
vlc_tls_Write
vlc_tls_GetLine
vlc_tls_DummyCreate
ToCharset
update_Check
update_Delete
......
......@@ -308,3 +308,32 @@ error:
free(line);
return NULL;
}
static ssize_t vlc_tls_DummyReceive(vlc_tls_t *tls, void *buf, size_t len)
{
return recv(tls->fd, buf, len, 0);
}
static ssize_t vlc_tls_DummySend(vlc_tls_t *tls, const void *buf, size_t len)
{
return send(tls->fd, buf, len, 0);
}
static void vlc_tls_DummyClose(vlc_tls_t *tls)
{
(void) tls;
}
vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd)
{
vlc_tls_t *session = malloc(sizeof (*session));
if (unlikely(session == NULL))
return NULL;
session->obj = obj;
session->fd = fd;
session->recv = vlc_tls_DummyReceive;
session->send = vlc_tls_DummySend;
session->close = vlc_tls_DummyClose;
return session;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment