From 66ab92584be5e1adacaacf6f75072ddfb6367a66 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Thu, 2 Dec 2010 17:32:02 +0200 Subject: [PATCH] Fixed a regression introduced in HTTP protocol. --- protocolhttp.c | 25 +++++++++++++++---------- socket.c | 5 +---- socket.h | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/protocolhttp.c b/protocolhttp.c index 39c2b79..62abbd6 100644 --- a/protocolhttp.c +++ b/protocolhttp.c @@ -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; } diff --git a/socket.c b/socket.c index 0330a29..b63c381 100644 --- a/socket.c +++ b/socket.c @@ -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 diff --git a/socket.h b/socket.h index d2b9ea7..14bd75a 100644 --- a/socket.h +++ b/socket.h @@ -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); };