Skip to content
Snippets Groups Projects
Commit 55fa4607 authored by François Cartegnie's avatar François Cartegnie :fingers_crossed:
Browse files

demux: adaptive: remove old TLS api and network primitives

fixes old api leak
parent 2aea8b85
No related branches found
No related tags found
No related merge requests found
......@@ -338,8 +338,8 @@ libadaptive_plugin_la_SOURCES = \
demux/adaptive/http/HTTPConnection.hpp \
demux/adaptive/http/HTTPConnectionManager.cpp \
demux/adaptive/http/HTTPConnectionManager.h \
demux/adaptive/http/Sockets.hpp \
demux/adaptive/http/Sockets.cpp \
demux/adaptive/http/Transport.hpp \
demux/adaptive/http/Transport.cpp \
demux/adaptive/plumbing/CommandsQueue.cpp \
demux/adaptive/plumbing/CommandsQueue.hpp \
demux/adaptive/plumbing/Demuxer.cpp \
......
......@@ -27,7 +27,7 @@ namespace adaptive
{
namespace http
{
class Socket;
class Transport;
class ConnectionParams
{
......
......@@ -24,7 +24,7 @@
#include "HTTPConnection.hpp"
#include "ConnectionParams.hpp"
#include "AuthStorage.hpp"
#include "Sockets.hpp"
#include "Transport.hpp"
#include <cstdio>
#include <sstream>
......@@ -65,10 +65,10 @@ const std::string & AbstractConnection::getContentType() const
}
HTTPConnection::HTTPConnection(vlc_object_t *p_object_, AuthStorage *auth,
Socket *socket_, const ConnectionParams &proxy, bool persistent)
Transport *socket_, const ConnectionParams &proxy, bool persistent)
: AbstractConnection( p_object_ )
{
socket = socket_;
transport = socket_;
psz_useragent = var_InheritString(p_object_, "http-user-agent");
queryOk = false;
retries = 0;
......@@ -83,7 +83,7 @@ HTTPConnection::HTTPConnection(vlc_object_t *p_object_, AuthStorage *auth,
HTTPConnection::~HTTPConnection()
{
free(psz_useragent);
delete socket;
delete transport;
}
bool HTTPConnection::canReuse(const ConnectionParams &params_) const
......@@ -108,16 +108,16 @@ bool HTTPConnection::canReuse(const ConnectionParams &params_) const
bool HTTPConnection::connect()
{
if(proxyparams.getHostname().empty())
return socket->connect(p_object, params.getHostname().c_str(),
return transport->connect(p_object, params.getHostname().c_str(),
params.getPort());
else
return socket->connect(p_object, proxyparams.getHostname().c_str(),
return transport->connect(p_object, proxyparams.getHostname().c_str(),
proxyparams.getPort());
}
bool HTTPConnection::connected() const
{
return socket->connected();
return transport->connected();
}
void HTTPConnection::disconnect()
......@@ -129,7 +129,7 @@ void HTTPConnection::disconnect()
chunkLength = 0;
bytesRange = BytesRange();
contentType = std::string();
socket->disconnect();
transport->disconnect();
}
int HTTPConnection::request(const std::string &path, const BytesRange &range)
......@@ -168,7 +168,7 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
if(!send( header ))
{
socket->disconnect();
transport->disconnect();
if(!connectionClose)
{
/* server closed connection pipeline after last req. need new */
......@@ -185,11 +185,11 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
}
else if(i_ret == VLC_ETIMEOUT) /* redir */
{
socket->disconnect();
transport->disconnect();
}
else if(i_ret == VLC_EGENERIC)
{
socket->disconnect();
transport->disconnect();
if(!connectionClose)
{
connectionClose = true;
......@@ -219,14 +219,14 @@ ssize_t HTTPConnection::read(void *p_buffer, size_t len)
len = toRead;
ssize_t ret = ( chunked ) ? readChunk(p_buffer, len)
: socket->read(p_object, p_buffer, len);
: transport->read(p_buffer, len);
if(ret >= 0)
bytesRead += ret;
if(ret < 0 || (size_t)ret < len || /* set EOF */
(contentLength == bytesRead && connectionClose))
{
socket->disconnect();
transport->disconnect();
return ret;
}
......@@ -240,7 +240,7 @@ bool HTTPConnection::send(const std::string &data)
bool HTTPConnection::send(const void *buf, size_t size)
{
return socket->send(p_object, buf, size);
return transport->send(buf, size);
}
int HTTPConnection::parseReply()
......@@ -319,7 +319,7 @@ ssize_t HTTPConnection::readChunk(void *p_buffer, size_t len)
if(toread > chunkLength)
toread = chunkLength;
ssize_t in = socket->read(p_object, &((uint8_t*)p_buffer)[copied], toread);
ssize_t in = transport->read(&((uint8_t*)p_buffer)[copied], toread);
if(in < 0)
{
return (copied == 0) ? in : copied;
......@@ -336,7 +336,7 @@ ssize_t HTTPConnection::readChunk(void *p_buffer, size_t len)
if(chunkLength == 0)
{
char crlf[2];
ssize_t in = socket->read(p_object, &crlf, 2);
ssize_t in = transport->read(&crlf, 2);
if(in < 2 || memcmp(crlf, "\r\n", 2))
return (copied == 0) ? -1 : copied;
}
......@@ -347,7 +347,7 @@ ssize_t HTTPConnection::readChunk(void *p_buffer, size_t len)
std::string HTTPConnection::readLine()
{
return socket->readline(p_object);
return transport->readline();
}
void HTTPConnection::setUsed( bool b )
......@@ -591,15 +591,14 @@ AbstractConnection * ConnectionFactory::createConnection(vlc_object_t *p_object,
}
else scheme = params.getScheme();
const int sockettype = (params.getScheme() == "https") ? TLSSocket::TLS : Socket::REGULAR;
Socket *socket = (sockettype == TLSSocket::TLS) ? new (std::nothrow) TLSSocket()
: new (std::nothrow) Socket();
const bool b_secure = (params.getScheme() == "https");
Transport *socket = new (std::nothrow) Transport(b_secure);
if(!socket)
return NULL;
/* disable pipelined tls until we have ticket/resume session support */
HTTPConnection *conn = new (std::nothrow)
HTTPConnection(p_object, authStorage, socket, proxy, sockettype != TLSSocket::TLS);
HTTPConnection(p_object, authStorage, socket, proxy, !b_secure);
if(!conn)
{
delete socket;
......
......@@ -34,7 +34,7 @@ namespace adaptive
{
namespace http
{
class Socket;
class Transport;
class AuthStorage;
class AbstractConnection
......@@ -66,7 +66,7 @@ namespace adaptive
class HTTPConnection : public AbstractConnection
{
public:
HTTPConnection(vlc_object_t *, AuthStorage *, Socket *,
HTTPConnection(vlc_object_t *, AuthStorage *, Transport *,
const ConnectionParams &, bool = false);
virtual ~HTTPConnection();
......@@ -107,7 +107,7 @@ namespace adaptive
static const int retryCount = 5;
private:
Socket *socket;
Transport *transport;
};
class StreamUrlConnection : public AbstractConnection
......
......@@ -28,7 +28,7 @@
#include "HTTPConnectionManager.h"
#include "HTTPConnection.hpp"
#include "ConnectionParams.hpp"
#include "Sockets.hpp"
#include "Transport.hpp"
#include "Downloader.hpp"
#include <vlc_url.h>
#include <vlc_http.h>
......
/*
* Sockets.cpp
* Transport.cpp
*****************************************************************************
* Copyright (C) 2015 - VideoLAN and VLC authors
* Copyright (C) 2015-2018 VideoLabs, VideoLAN and VLC authors
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
......@@ -21,130 +21,75 @@
# include "config.h"
#endif
#include "Sockets.hpp"
#include <vlc_network.h>
#include <cerrno>
#include "Transport.hpp"
using namespace adaptive::http;
Socket::Socket()
{
netfd = -1;
type = REGULAR;
}
Socket::Socket( int type_ )
{
netfd = -1;
type = type_;
}
Socket::~Socket()
{
disconnect();
}
bool Socket::connect(vlc_object_t *p_object, const std::string &hostname, int port)
Transport::Transport(bool b_secure_)
{
netfd = net_ConnectTCP(p_object, hostname.c_str(), port);
if(netfd == -1)
return false;
return true;
creds = NULL;
tls = NULL;
b_secure = b_secure_;
}
int Socket::getType() const
Transport::~Transport()
{
return type;
if(connected())
disconnect();
}
bool Socket::connected() const
bool Transport::connect(vlc_object_t *p_object, const std::string &hostname, int port)
{
return (netfd != -1);
}
if(connected())
disconnect();
void Socket::disconnect()
{
if (netfd >= 0)
if(b_secure)
{
net_Close(netfd);
netfd = -1;
creds = vlc_tls_ClientCreate(p_object);
if(!creds)
return false;
tls = vlc_tls_SocketOpenTLS(creds, hostname.c_str(), port, "https",
NULL, NULL );
if(!tls)
{
vlc_tls_Delete(creds);
creds = NULL;
}
}
else
{
tls = vlc_tls_SocketOpenTCP(p_object, hostname.c_str(), port);
}
}
ssize_t Socket::read(vlc_object_t *p_object, void *p_buffer, size_t len)
{
return net_Read(p_object, netfd, p_buffer, len);
}
std::string Socket::readline(vlc_object_t *p_object)
{
char *line = ::net_Gets(p_object, netfd);
if(line == NULL)
return "";
std::string ret(line);
::free(line);
return ret;
}
bool Socket::send(vlc_object_t *p_object, const void *buf, size_t size)
{
if (netfd == -1)
return false;
if (size == 0)
return true;
return net_Write(p_object, netfd, buf, size) == (ssize_t)size;
}
TLSSocket::TLSSocket() : Socket( TLS )
{
creds = NULL;
tls = NULL;
return tls != NULL;
}
TLSSocket::~TLSSocket()
bool Transport::connected() const
{
disconnect();
return tls != NULL;
}
bool TLSSocket::connect(vlc_object_t *p_object, const std::string &hostname, int port)
void Transport::disconnect()
{
disconnect();
if(!Socket::connect(p_object, hostname, port))
return false;
creds = vlc_tls_ClientCreate(p_object);
if(!creds)
if(tls)
{
disconnect();
return false;
vlc_tls_Close(tls);
tls = NULL;
}
tls = vlc_tls_ClientSessionCreateFD(creds, netfd, hostname.c_str(), "https", NULL, NULL);
if(!tls)
if(creds)
{
disconnect();
return false;
vlc_tls_Delete(creds);
creds = NULL;
}
return true;
}
bool TLSSocket::connected() const
{
return Socket::connected() && tls;
}
ssize_t TLSSocket::read(vlc_object_t *, void *p_buffer, size_t len)
ssize_t Transport::read(void *p_buffer, size_t len)
{
return vlc_tls_Read(tls, p_buffer, len, true);
}
std::string TLSSocket::readline(vlc_object_t *)
std::string Transport::readline()
{
char *line = ::vlc_tls_GetLine(tls);
if(line == NULL)
......@@ -155,7 +100,7 @@ std::string TLSSocket::readline(vlc_object_t *)
return ret;
}
bool TLSSocket::send(vlc_object_t *, const void *buf, size_t size)
bool Transport::send(const void *buf, size_t size)
{
if (!connected())
return false;
......@@ -166,13 +111,3 @@ bool TLSSocket::send(vlc_object_t *, const void *buf, size_t size)
return vlc_tls_Write(tls, buf, size) == (ssize_t)size;
}
void TLSSocket::disconnect()
{
if(tls)
vlc_tls_SessionDelete(tls);
if(creds)
vlc_tls_Delete(creds);
tls = NULL;
creds = NULL;
Socket::disconnect();
}
/*
* Sockets.hpp
* Transport.hpp
*****************************************************************************
* Copyright (C) 2015 - VideoLAN and VLC authors
* Copyright (C) 2015-2018 - VideoLabs, VideoLAN and VLC authors
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
......@@ -17,8 +17,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef SOCKETS_HPP
#define SOCKETS_HPP
#ifndef TRANSPORT_HPP
#define TRANSPORT_HPP
#include <vlc_common.h>
#include <vlc_tls.h>
......@@ -28,45 +28,24 @@ namespace adaptive
{
namespace http
{
class Socket
class Transport
{
public:
Socket();
virtual ~Socket();
virtual bool connect (vlc_object_t *, const std::string&, int port = 80);
virtual bool connected () const;
virtual bool send (vlc_object_t *, const void *buf, size_t size);
virtual ssize_t read (vlc_object_t *, void *p_buffer, size_t len);
virtual std::string readline(vlc_object_t *);
virtual void disconnect ();
int getType() const;
static const int REGULAR = 0;
Transport(bool b_secure = false);
~Transport();
bool connect (vlc_object_t *, const std::string&, int port = 80);
bool connected () const;
bool send (const void *buf, size_t size);
ssize_t read (void *p_buffer, size_t len);
std::string readline();
void disconnect ();
protected:
Socket( int );
int netfd;
int type;
};
class TLSSocket : public Socket
{
public:
TLSSocket();
virtual ~TLSSocket();
virtual bool connect (vlc_object_t *, const std::string&, int port = 443);
virtual bool connected () const;
virtual bool send (vlc_object_t *, const void *buf, size_t size);
virtual ssize_t read (vlc_object_t *, void *p_buffer, size_t len);
virtual std::string readline(vlc_object_t *);
virtual void disconnect ();
static const int TLS = REGULAR + 1;
private:
vlc_tls_creds_t *creds;
vlc_tls_t *tls;
bool b_secure;
};
}
}
#endif // SOCKETS_HPP
#endif // TRANSPORT_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment