mirror of
https://github.com/rofafor/vdr-plugin-iptv.git
synced 2023-10-10 11:37:03 +00:00
Improve object constructs of protocols. Create Separate ProtocolUdp and
ProtocolTcp -classes.
This commit is contained in:
parent
ced3540d3b
commit
eebd990991
@ -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.18 2007/10/21 13:31:21 ajhseppa Exp $
|
* $Id: protocolext.c,v 1.19 2007/10/21 17:32:43 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -110,11 +110,6 @@ void cIptvProtocolExt::TerminateScript(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cIptvProtocolExt::Read(unsigned char* *BufferAddr)
|
|
||||||
{
|
|
||||||
return ReadUdpSocket(BufferAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cIptvProtocolExt::Open(void)
|
bool cIptvProtocolExt::Open(void)
|
||||||
{
|
{
|
||||||
debug("cIptvProtocolExt::Open()\n");
|
debug("cIptvProtocolExt::Open()\n");
|
||||||
@ -140,6 +135,11 @@ bool cIptvProtocolExt::Close(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cIptvProtocolExt::Read(unsigned char* *BufferAddr)
|
||||||
|
{
|
||||||
|
return cIptvUdpSocket::Read(BufferAddr);
|
||||||
|
}
|
||||||
|
|
||||||
bool cIptvProtocolExt::Set(const char* Location, const int Parameter, const int Index)
|
bool cIptvProtocolExt::Set(const char* Location, const int Parameter, const int Index)
|
||||||
{
|
{
|
||||||
debug("cIptvProtocolExt::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
|
debug("cIptvProtocolExt::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
|
||||||
|
@ -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.h,v 1.7 2007/10/21 13:31:21 ajhseppa Exp $
|
* $Id: protocolext.h,v 1.8 2007/10/21 17:32:43 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __IPTV_PROTOCOLEXT_H
|
#ifndef __IPTV_PROTOCOLEXT_H
|
||||||
@ -13,7 +13,7 @@
|
|||||||
#include "protocolif.h"
|
#include "protocolif.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
class cIptvProtocolExt : public cIptvSocket, public cIptvProtocolIf {
|
class cIptvProtocolExt : public cIptvUdpSocket, public cIptvProtocolIf {
|
||||||
private:
|
private:
|
||||||
int pid;
|
int pid;
|
||||||
char* listenAddr;
|
char* listenAddr;
|
||||||
@ -27,7 +27,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
cIptvProtocolExt();
|
cIptvProtocolExt();
|
||||||
virtual ~cIptvProtocolExt();
|
virtual ~cIptvProtocolExt();
|
||||||
virtual int Read(unsigned char* *BufferAddr);
|
int Read(unsigned char* *BufferAddr);
|
||||||
virtual bool Set(const char* Location, const int Parameter, const int Index);
|
virtual bool Set(const char* Location, const int Parameter, const int Index);
|
||||||
virtual bool Open(void);
|
virtual bool Open(void);
|
||||||
virtual bool Close(void);
|
virtual bool Close(void);
|
||||||
|
@ -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.18 2007/10/21 13:31:21 ajhseppa Exp $
|
* $Id: protocolhttp.c,v 1.19 2007/10/21 17:32:43 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -204,32 +204,6 @@ bool cIptvProtocolHttp::ProcessHeaders(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cIptvProtocolHttp::Read(unsigned char* *BufferAddr)
|
|
||||||
{
|
|
||||||
//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);
|
|
||||||
// Set argument point to read buffer
|
|
||||||
*BufferAddr = readBuffer;
|
|
||||||
// Wait for data
|
|
||||||
int retval = select_single_desc(socketDesc, 500000, false);
|
|
||||||
// Check if error
|
|
||||||
if (retval < 0)
|
|
||||||
return retval;
|
|
||||||
// Check if data available
|
|
||||||
else if (retval) {
|
|
||||||
// Read data from socket
|
|
||||||
if (isActive)
|
|
||||||
return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
|
||||||
(struct sockaddr *)&sockAddr, &addrlen);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cIptvProtocolHttp::Open(void)
|
bool cIptvProtocolHttp::Open(void)
|
||||||
{
|
{
|
||||||
debug("cIptvProtocolHttp::Open()\n");
|
debug("cIptvProtocolHttp::Open()\n");
|
||||||
@ -245,6 +219,11 @@ bool cIptvProtocolHttp::Close(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cIptvProtocolHttp::Read(unsigned char* *BufferAddr)
|
||||||
|
{
|
||||||
|
return cIptvTcpSocket::Read(BufferAddr);
|
||||||
|
}
|
||||||
|
|
||||||
bool cIptvProtocolHttp::Set(const char* Location, const int Parameter, const int Index)
|
bool cIptvProtocolHttp::Set(const char* Location, const int Parameter, const int Index)
|
||||||
{
|
{
|
||||||
debug("cIptvProtocolHttp::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
|
debug("cIptvProtocolHttp::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
|
||||||
|
@ -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.h,v 1.10 2007/10/21 13:31:21 ajhseppa Exp $
|
* $Id: protocolhttp.h,v 1.11 2007/10/21 17:32:43 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __IPTV_PROTOCOLHTTP_H
|
#ifndef __IPTV_PROTOCOLHTTP_H
|
||||||
@ -13,7 +13,7 @@
|
|||||||
#include "protocolif.h"
|
#include "protocolif.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
class cIptvProtocolHttp : public cIptvSocket, public cIptvProtocolIf {
|
class cIptvProtocolHttp : public cIptvTcpSocket, public cIptvProtocolIf {
|
||||||
private:
|
private:
|
||||||
char* streamAddr;
|
char* streamAddr;
|
||||||
char* streamPath;
|
char* streamPath;
|
||||||
@ -28,7 +28,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
cIptvProtocolHttp();
|
cIptvProtocolHttp();
|
||||||
virtual ~cIptvProtocolHttp();
|
virtual ~cIptvProtocolHttp();
|
||||||
virtual int Read(unsigned char* *BufferAddr);
|
int Read(unsigned char* *BufferAddr);
|
||||||
virtual bool Set(const char* Location, const int Parameter, const int Index);
|
virtual bool Set(const char* Location, const int Parameter, const int Index);
|
||||||
virtual bool Open(void);
|
virtual bool Open(void);
|
||||||
virtual bool Close(void);
|
virtual bool Close(void);
|
||||||
|
@ -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.19 2007/10/21 13:31:21 ajhseppa Exp $
|
* $Id: protocoludp.c,v 1.20 2007/10/21 17:32:43 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -74,11 +74,6 @@ bool cIptvProtocolUdp::DropMulticast(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cIptvProtocolUdp::Read(unsigned char* *BufferAddr)
|
|
||||||
{
|
|
||||||
return ReadUdpSocket(BufferAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cIptvProtocolUdp::Open(void)
|
bool cIptvProtocolUdp::Open(void)
|
||||||
{
|
{
|
||||||
debug("cIptvProtocolUdp::Open()\n");
|
debug("cIptvProtocolUdp::Open()\n");
|
||||||
@ -97,6 +92,11 @@ bool cIptvProtocolUdp::Close(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cIptvProtocolUdp::Read(unsigned char* *BufferAddr)
|
||||||
|
{
|
||||||
|
return cIptvUdpSocket::Read(BufferAddr);
|
||||||
|
}
|
||||||
|
|
||||||
bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int Index)
|
bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int Index)
|
||||||
{
|
{
|
||||||
debug("cIptvProtocolUdp::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
|
debug("cIptvProtocolUdp::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
|
||||||
|
@ -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.h,v 1.11 2007/10/21 13:31:21 ajhseppa Exp $
|
* $Id: protocoludp.h,v 1.12 2007/10/21 17:32:43 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __IPTV_PROTOCOLUDP_H
|
#ifndef __IPTV_PROTOCOLUDP_H
|
||||||
@ -13,7 +13,7 @@
|
|||||||
#include "protocolif.h"
|
#include "protocolif.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
class cIptvProtocolUdp : public cIptvSocket, public cIptvProtocolIf {
|
class cIptvProtocolUdp : public cIptvUdpSocket, public cIptvProtocolIf {
|
||||||
private:
|
private:
|
||||||
char* streamAddr;
|
char* streamAddr;
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
cIptvProtocolUdp();
|
cIptvProtocolUdp();
|
||||||
virtual ~cIptvProtocolUdp();
|
virtual ~cIptvProtocolUdp();
|
||||||
virtual int Read(unsigned char* *BufferAddr);
|
int Read(unsigned char* *BufferAddr);
|
||||||
virtual bool Set(const char* Location, const int Parameter, const int Index);
|
virtual bool Set(const char* Location, const int Parameter, const int Index);
|
||||||
virtual bool Open(void);
|
virtual bool Open(void);
|
||||||
virtual bool Close(void);
|
virtual bool Close(void);
|
||||||
|
54
socket.c
54
socket.c
@ -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: socket.c,v 1.2 2007/10/21 15:49:54 rahrenbe Exp $
|
* $Id: socket.c,v 1.3 2007/10/21 17:32:43 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -88,9 +88,20 @@ void cIptvSocket::CloseSocket(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cIptvSocket::ReadUdpSocket(unsigned char* *BufferAddr)
|
// UDP socket class
|
||||||
|
cIptvUdpSocket::cIptvUdpSocket()
|
||||||
{
|
{
|
||||||
//debug("cIptvSocket::Read()\n");
|
debug("cIptvUdpSocket::cIptvUdpSocket()\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
cIptvUdpSocket::~cIptvUdpSocket()
|
||||||
|
{
|
||||||
|
debug("cIptvUdpSocket::~cIptvUdpSocket()\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int cIptvUdpSocket::Read(unsigned char* *BufferAddr)
|
||||||
|
{
|
||||||
|
//debug("cIptvUdpSocket::Read()\n");
|
||||||
// Error out if socket not initialized
|
// Error out if socket not initialized
|
||||||
if (socketDesc <= 0) {
|
if (socketDesc <= 0) {
|
||||||
error("ERROR: Invalid socket in %s\n", __FUNCTION__);
|
error("ERROR: Invalid socket in %s\n", __FUNCTION__);
|
||||||
@ -147,3 +158,40 @@ int cIptvSocket::ReadUdpSocket(unsigned char* *BufferAddr)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TCP socket class
|
||||||
|
cIptvTcpSocket::cIptvTcpSocket()
|
||||||
|
{
|
||||||
|
debug("cIptvTcpSocket::cIptvTcpSocket()\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
cIptvTcpSocket::~cIptvTcpSocket()
|
||||||
|
{
|
||||||
|
debug("cIptvTcpSocket::~cIptvTcpSocket()\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int cIptvTcpSocket::Read(unsigned char* *BufferAddr)
|
||||||
|
{
|
||||||
|
//debug("cIptvTcpSocket::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);
|
||||||
|
// Set argument point to read buffer
|
||||||
|
*BufferAddr = readBuffer;
|
||||||
|
// Wait for data
|
||||||
|
int retval = select_single_desc(socketDesc, 500000, false);
|
||||||
|
// Check if error
|
||||||
|
if (retval < 0)
|
||||||
|
return retval;
|
||||||
|
// Check if data available
|
||||||
|
else if (retval) {
|
||||||
|
// Read data from socket
|
||||||
|
if (isActive)
|
||||||
|
return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
||||||
|
(struct sockaddr *)&sockAddr, &addrlen);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
17
socket.h
17
socket.h
@ -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: socket.h,v 1.1 2007/10/21 13:31:21 ajhseppa Exp $
|
* $Id: socket.h,v 1.2 2007/10/21 17:32:43 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __IPTV_SOCKET_H
|
#ifndef __IPTV_SOCKET_H
|
||||||
@ -23,12 +23,25 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
bool OpenSocket(const int Port, const bool isUdp);
|
bool OpenSocket(const int Port, const bool isUdp);
|
||||||
void CloseSocket(void);
|
void CloseSocket(void);
|
||||||
int ReadUdpSocket(unsigned char* *BufferAddr);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cIptvSocket();
|
cIptvSocket();
|
||||||
virtual ~cIptvSocket();
|
virtual ~cIptvSocket();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class cIptvUdpSocket : public cIptvSocket {
|
||||||
|
public:
|
||||||
|
cIptvUdpSocket();
|
||||||
|
virtual ~cIptvUdpSocket();
|
||||||
|
virtual int Read(unsigned char* *BufferAddr);
|
||||||
|
};
|
||||||
|
|
||||||
|
class cIptvTcpSocket : public cIptvSocket {
|
||||||
|
public:
|
||||||
|
cIptvTcpSocket();
|
||||||
|
virtual ~cIptvTcpSocket();
|
||||||
|
virtual int Read(unsigned char* *BufferAddr);
|
||||||
|
};
|
||||||
|
|
||||||
#endif // __IPTV_SOCKET_H
|
#endif // __IPTV_SOCKET_H
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user