Skip to content

Commit

Permalink
tls: add vlc_tls_DummyCreate()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Denis-Courmont committed Dec 18, 2015
1 parent 754c3ef commit 30d18b6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/vlc_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/libvlccore.sym
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ vlc_tls_SessionDelete
vlc_tls_Read
vlc_tls_Write
vlc_tls_GetLine
vlc_tls_DummyCreate
ToCharset
update_Check
update_Delete
Expand Down
29 changes: 29 additions & 0 deletions src/network/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,32 @@ char *vlc_tls_GetLine(vlc_tls_t *session)
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;
}

0 comments on commit 30d18b6

Please sign in to comment.