1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

Fixed a regression introduced in HTTP protocol.

This commit is contained in:
Rolf Ahrenberg 2010-12-02 17:32:02 +02:00
parent 05e57802c3
commit 66ab92584b
3 changed files with 17 additions and 15 deletions

View File

@ -39,7 +39,7 @@ bool cIptvProtocolHttp::Connect(void)
{
debug("cIptvProtocolHttp::Connect()\n");
// Check that stream address is valid
if (!isempty(streamAddr) && !isempty(streamPath)) {
if (!isActive && !isempty(streamAddr) && !isempty(streamPath)) {
// Ensure that socket is valid and connect
OpenSocket(socketPort, streamAddr);
if (!ConnectSocket()) {
@ -58,12 +58,13 @@ bool cIptvProtocolHttp::Connect(void)
CloseSocket();
return false;
}
// Now process headers
if (!ProcessHeaders()) {
CloseSocket();
return false;
}
// Update active flag
isActive = true;
}
return true;
}
@ -71,8 +72,12 @@ bool cIptvProtocolHttp::Connect(void)
bool cIptvProtocolHttp::Disconnect(void)
{
debug("cIptvProtocolHttp::Disconnect()\n");
// Close the socket
CloseSocket();
if (isActive) {
// Close the socket
CloseSocket();
// Update active flag
isActive = false;
}
return true;
}
@ -82,11 +87,12 @@ bool cIptvProtocolHttp::GetHeaderLine(char* dest, unsigned int destLen,
debug("cIptvProtocolHttp::GetHeaderLine()\n");
bool linefeed = false;
bool newline = false;
unsigned char buf[4096];
unsigned char *bufptr = buf;
memset(buf, '\0', sizeof(buf));
char *bufptr = dest;
recvLen = 0;
if (!dest)
return false;
while (!newline || !linefeed) {
// Wait 500ms for data
if (ReadChar(bufptr, 500)) {
@ -102,8 +108,8 @@ bool cIptvProtocolHttp::GetHeaderLine(char* dest, unsigned int destLen,
++recvLen;
}
++bufptr;
// Check that buffers won't be exceeded
if (recvLen >= sizeof(buf) || recvLen >= destLen) {
// Check that buffer won't be exceeded
if (recvLen >= destLen) {
error("Header wouldn't fit into buffer\n");
recvLen = 0;
return false;
@ -114,7 +120,6 @@ bool cIptvProtocolHttp::GetHeaderLine(char* dest, unsigned int destLen,
return false;
}
}
memcpy(dest, buf, recvLen);
return true;
}

View File

@ -262,7 +262,6 @@ bool cIptvTcpSocket::OpenSocket(const int Port, const char *StreamAddr)
void cIptvTcpSocket::CloseSocket(void)
{
debug("cIptvTcpSocket::CloseSocket()\n");
isActive = false;
cIptvSocket::CloseSocket();
}
@ -287,8 +286,6 @@ bool cIptvTcpSocket::ConnectSocket(void)
error("Connect() failed: %s", strerror_r(retval, tmp, sizeof(tmp)));
return false;
}
// Update connection flag
isActive = true;
}
return true;
@ -311,7 +308,7 @@ int cIptvTcpSocket::Read(unsigned char* BufferAddr, unsigned int BufferLen)
return len;
}
bool cIptvTcpSocket::ReadChar(unsigned char* BufferAddr, unsigned int TimeoutMs)
bool cIptvTcpSocket::ReadChar(char* BufferAddr, unsigned int TimeoutMs)
{
//debug("cIptvTcpSocket::ReadChar()\n");
// Error out if socket not initialized

View File

@ -48,7 +48,7 @@ public:
bool OpenSocket(const int Port, const char *StreamAddr);
void CloseSocket(void);
bool ConnectSocket(void);
bool ReadChar(unsigned char* BufferAddr, unsigned int TimeoutMs);
bool ReadChar(char* BufferAddr, unsigned int TimeoutMs);
bool Write(const char* BufferAddr, unsigned int BufferLen);
};