mirror of
https://github.com/rofafor/vdr-plugin-iptv.git
synced 2023-10-10 13:37:03 +02:00
Robustify network protocols with more error checking.
This commit is contained in:
parent
0a516fd934
commit
2758993bb2
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* See the README file for copyright information and how to reach the author.
|
* See the README file for copyright information and how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: protocolext.c,v 1.10 2007/10/19 22:56:25 rahrenbe Exp $
|
* $Id: protocolext.c,v 1.11 2007/10/20 11:36:21 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -187,6 +187,11 @@ void cIptvProtocolExt::TerminateCommand(void)
|
|||||||
int cIptvProtocolExt::Read(unsigned char* *BufferAddr)
|
int cIptvProtocolExt::Read(unsigned char* *BufferAddr)
|
||||||
{
|
{
|
||||||
//debug("cIptvProtocolExt::Read()\n");
|
//debug("cIptvProtocolExt::Read()\n");
|
||||||
|
// Error out if socket not initialized
|
||||||
|
if (socketDesc <= 0) {
|
||||||
|
error("ERROR: Invalid socket in %s\n", __FUNCTION__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
socklen_t addrlen = sizeof(sockAddr);
|
socklen_t addrlen = sizeof(sockAddr);
|
||||||
// Set argument point to read buffer
|
// Set argument point to read buffer
|
||||||
*BufferAddr = readBuffer;
|
*BufferAddr = readBuffer;
|
||||||
@ -203,14 +208,21 @@ int cIptvProtocolExt::Read(unsigned char* *BufferAddr)
|
|||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||||
return -1;
|
return retval;
|
||||||
}
|
}
|
||||||
// Check if data available
|
// Check if data available
|
||||||
else if (retval) {
|
else if (retval) {
|
||||||
// Read data from socket
|
// Read data from socket
|
||||||
int len = recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
int len = 0;
|
||||||
(struct sockaddr *)&sockAddr, &addrlen);
|
if (isActive)
|
||||||
if ((len > 0) && (readBuffer[0] == 0x47)) {
|
len = recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
||||||
|
(struct sockaddr *)&sockAddr, &addrlen);
|
||||||
|
if (len < 0) {
|
||||||
|
char tmp[64];
|
||||||
|
error("ERROR: recvfrom(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
else if ((len > 0) && (readBuffer[0] == 0x47)) {
|
||||||
// Set argument point to read buffer
|
// Set argument point to read buffer
|
||||||
*BufferAddr = &readBuffer[0];
|
*BufferAddr = &readBuffer[0];
|
||||||
return len;
|
return len;
|
||||||
@ -256,6 +268,7 @@ bool cIptvProtocolExt::Open(void)
|
|||||||
OpenSocket();
|
OpenSocket();
|
||||||
// Execute the external command
|
// Execute the external command
|
||||||
ExecuteCommand();
|
ExecuteCommand();
|
||||||
|
isActive = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +279,7 @@ bool cIptvProtocolExt::Close(void)
|
|||||||
CloseSocket();
|
CloseSocket();
|
||||||
// Terminate the external script
|
// Terminate the external script
|
||||||
TerminateCommand();
|
TerminateCommand();
|
||||||
|
isActive = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* See the README file for copyright information and how to reach the author.
|
* See the README file for copyright information and how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: protocolhttp.c,v 1.12 2007/10/19 22:18:55 rahrenbe Exp $
|
* $Id: protocolhttp.c,v 1.13 2007/10/20 11:36:21 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -307,6 +307,11 @@ bool cIptvProtocolHttp::ProcessHeaders(void)
|
|||||||
int cIptvProtocolHttp::Read(unsigned char* *BufferAddr)
|
int cIptvProtocolHttp::Read(unsigned char* *BufferAddr)
|
||||||
{
|
{
|
||||||
//debug("cIptvProtocolHttp::Read()\n");
|
//debug("cIptvProtocolHttp::Read()\n");
|
||||||
|
// Error out if socket not initialized
|
||||||
|
if (socketDesc <= 0) {
|
||||||
|
error("ERROR: Invalid socket in %s\n", __FUNCTION__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
socklen_t addrlen = sizeof(sockAddr);
|
socklen_t addrlen = sizeof(sockAddr);
|
||||||
// Set argument point to read buffer
|
// Set argument point to read buffer
|
||||||
*BufferAddr = readBuffer;
|
*BufferAddr = readBuffer;
|
||||||
@ -323,13 +328,14 @@ int cIptvProtocolHttp::Read(unsigned char* *BufferAddr)
|
|||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||||
return -1;
|
return retval;
|
||||||
}
|
}
|
||||||
// Check if data available
|
// Check if data available
|
||||||
else if (retval) {
|
else if (retval) {
|
||||||
// Read data from socket
|
// Read data from socket
|
||||||
return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
if (isActive)
|
||||||
(struct sockaddr *)&sockAddr, &addrlen);
|
return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
||||||
|
(struct sockaddr *)&sockAddr, &addrlen);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* See the README file for copyright information and how to reach the author.
|
* See the README file for copyright information and how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: protocoludp.c,v 1.13 2007/10/19 22:18:55 rahrenbe Exp $
|
* $Id: protocoludp.c,v 1.14 2007/10/20 11:36:21 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -155,6 +155,11 @@ bool cIptvProtocolUdp::DropMulticast(void)
|
|||||||
int cIptvProtocolUdp::Read(unsigned char* *BufferAddr)
|
int cIptvProtocolUdp::Read(unsigned char* *BufferAddr)
|
||||||
{
|
{
|
||||||
//debug("cIptvProtocolUdp::Read()\n");
|
//debug("cIptvProtocolUdp::Read()\n");
|
||||||
|
// Error out if socket not initialized
|
||||||
|
if (socketDesc <= 0) {
|
||||||
|
error("ERROR: Invalid socket in %s\n", __FUNCTION__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
socklen_t addrlen = sizeof(sockAddr);
|
socklen_t addrlen = sizeof(sockAddr);
|
||||||
// Set argument point to read buffer
|
// Set argument point to read buffer
|
||||||
*BufferAddr = readBuffer;
|
*BufferAddr = readBuffer;
|
||||||
@ -171,14 +176,21 @@ int cIptvProtocolUdp::Read(unsigned char* *BufferAddr)
|
|||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||||
return -1;
|
return retval;
|
||||||
}
|
}
|
||||||
// Check if data available
|
// Check if data available
|
||||||
else if (retval) {
|
else if (retval) {
|
||||||
|
int len = 0;
|
||||||
// Read data from socket
|
// Read data from socket
|
||||||
int len = recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
if (isActive)
|
||||||
(struct sockaddr *)&sockAddr, &addrlen);
|
len = recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
||||||
if ((len > 0) && (readBuffer[0] == 0x47)) {
|
(struct sockaddr *)&sockAddr, &addrlen);
|
||||||
|
if (len < 0) {
|
||||||
|
char tmp[64];
|
||||||
|
error("ERROR: recvfrom(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
else if ((len > 0) && (readBuffer[0] == 0x47)) {
|
||||||
// Set argument point to read buffer
|
// Set argument point to read buffer
|
||||||
*BufferAddr = &readBuffer[0];
|
*BufferAddr = &readBuffer[0];
|
||||||
return len;
|
return len;
|
||||||
|
Loading…
Reference in New Issue
Block a user