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

187 lines
5.7 KiB
C
Raw Normal View History

2010-03-04 16:34:21 +01:00
/*
* source.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include "common.h"
#include "source.h"
// --- cIptvTransponderParameters --------------------------------------------
2013-02-23 14:31:11 +01:00
cIptvTransponderParameters::cIptvTransponderParameters(const char *parametersP)
: sidScanM(0),
pidScanM(0),
protocolM(eProtocolUDP),
parameterM(0)
2010-03-04 16:34:21 +01:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvTransponderParameters::%s(%s)", __FUNCTION__, parametersP);
2010-03-04 16:34:21 +01:00
2013-02-23 14:31:11 +01:00
memset(&addressM, 0, sizeof(addressM));
Parse(parametersP);
2010-03-04 16:34:21 +01:00
}
2013-02-23 14:31:11 +01:00
cString cIptvTransponderParameters::ToString(char typeP) const
2010-03-04 16:34:21 +01:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvTransponderParameters::%s(%c)", __FUNCTION__, typeP);
2010-03-04 16:34:21 +01:00
const char *protocolstr;
2013-02-23 14:31:11 +01:00
switch (protocolM) {
2010-03-04 16:34:21 +01:00
case eProtocolEXT:
protocolstr = "EXT";
break;
case eProtocolCURL:
protocolstr = "CURL";
break;
2010-03-04 16:34:21 +01:00
case eProtocolHTTP:
protocolstr = "HTTP";
break;
case eProtocolFILE:
protocolstr = "FILE";
break;
default:
case eProtocolUDP:
protocolstr = "UDP";
break;
}
2013-02-23 14:31:11 +01:00
return cString::sprintf("S=%d|P=%d|F=%s|U=%s|A=%d", sidScanM, pidScanM, protocolstr, addressM, parameterM);
2010-03-04 16:34:21 +01:00
}
2013-02-23 14:31:11 +01:00
bool cIptvTransponderParameters::Parse(const char *strP)
2010-03-04 16:34:21 +01:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvTransponderParameters::%s(%s)", __FUNCTION__, strP);
2010-03-08 20:12:06 +01:00
bool result = false;
2013-02-23 14:31:11 +01:00
if (strP && *strP) {
2010-03-08 20:12:06 +01:00
const char *delim = "|";
2013-02-23 14:31:11 +01:00
char *str = strdup(strP);
2010-03-08 20:12:06 +01:00
char *saveptr = NULL;
char *token = NULL;
bool found_s = false;
bool found_p = false;
bool found_f = false;
bool found_u = false;
bool found_a = false;
while ((token = strtok_r(str, delim, &saveptr)) != NULL) {
char *data = token;
2010-03-04 16:34:21 +01:00
++data;
2010-03-08 20:12:06 +01:00
if (data && (*data == '=')) {
++data;
switch (*token) {
case 'S':
2013-02-23 14:31:11 +01:00
sidScanM = (int)strtol(data, (char **)NULL, 10);
2010-03-08 20:12:06 +01:00
found_s = true;
break;
case 'P':
2013-02-23 14:31:11 +01:00
pidScanM = (int)strtol(data, (char **)NULL, 10);
2010-03-08 20:12:06 +01:00
found_p = true;
break;
case 'F':
if (strstr(data, "UDP")) {
2013-02-23 14:31:11 +01:00
protocolM = eProtocolUDP;
2010-03-08 20:12:06 +01:00
found_f = true;
}
else if (strstr(data, "CURL")) {
2013-02-23 14:31:11 +01:00
protocolM = eProtocolCURL;
found_f = true;
}
2010-03-08 20:12:06 +01:00
else if (strstr(data, "HTTP")) {
2013-02-23 14:31:11 +01:00
protocolM = eProtocolHTTP;
2010-03-08 20:12:06 +01:00
found_f = true;
}
else if (strstr(data, "FILE")) {
2013-02-23 14:31:11 +01:00
protocolM = eProtocolFILE;
2010-03-08 20:12:06 +01:00
found_f = true;
}
else if (strstr(data, "EXT")) {
2013-02-23 14:31:11 +01:00
protocolM = eProtocolEXT;
2010-03-08 20:12:06 +01:00
found_f = true;
}
break;
case 'U':
2013-02-23 14:31:11 +01:00
strn0cpy(addressM, data, sizeof(addressM));
2010-03-08 20:12:06 +01:00
found_u = true;
break;
case 'A':
2013-02-23 14:31:11 +01:00
parameterM = (int)strtol(data, (char **)NULL, 10);
2010-03-08 20:12:06 +01:00
found_a = true;
break;
default:
break;
}
}
str = NULL;
2010-03-08 10:49:41 +01:00
}
2010-03-04 16:34:21 +01:00
2010-03-08 20:12:06 +01:00
if (found_s && found_p && found_f && found_u && found_a)
result = true;
else
error("Invalid channel parameters: %s\n", str);
free(str);
2010-03-08 20:12:06 +01:00
}
2010-03-04 16:34:21 +01:00
2010-03-08 20:12:06 +01:00
return (result);
2010-03-04 16:34:21 +01:00
}
// --- cIptvSourceParam ------------------------------------------------------
const char *cIptvSourceParam::allowedProtocolCharsS = " abcdefghijklmnopqrstuvwxyz0123456789-.,#~\\^$[]()*+?{}/%@&=";
2013-02-23 14:31:11 +01:00
cIptvSourceParam::cIptvSourceParam(char sourceP, const char *descriptionP)
: cSourceParam(sourceP, descriptionP),
paramM(0),
nidM(0),
tidM(0),
ridM(0),
dataM(),
itpM()
2010-03-04 16:34:21 +01:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvSourceParam::%s(%c, %s)", __FUNCTION__, sourceP, descriptionP);
2010-03-04 16:34:21 +01:00
2013-02-23 14:31:11 +01:00
protocolsM[cIptvTransponderParameters::eProtocolUDP] = tr("UDP");
protocolsM[cIptvTransponderParameters::eProtocolCURL] = tr("CURL");
protocolsM[cIptvTransponderParameters::eProtocolHTTP] = tr("HTTP");
protocolsM[cIptvTransponderParameters::eProtocolFILE] = tr("FILE");
protocolsM[cIptvTransponderParameters::eProtocolEXT] = tr("EXT");
2010-03-04 16:34:21 +01:00
}
2013-02-23 14:31:11 +01:00
void cIptvSourceParam::SetData(cChannel *channelP)
2010-03-04 16:34:21 +01:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvSourceParam::%s(%s)", __FUNCTION__, channelP->Parameters());
2013-02-23 14:31:11 +01:00
dataM = *channelP;
nidM = dataM.Nid();
tidM = dataM.Tid();
ridM = dataM.Rid();
itpM.Parse(dataM.Parameters());
paramM = 0;
2010-03-04 16:34:21 +01:00
}
2013-02-23 14:31:11 +01:00
void cIptvSourceParam::GetData(cChannel *channelP)
2010-03-04 16:34:21 +01:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvSourceParam::%s(%s)", __FUNCTION__, channelP->Parameters());
2013-02-23 14:31:11 +01:00
dataM.SetTransponderData(channelP->Source(), channelP->Frequency(), dataM.Srate(), itpM.ToString(Source()), true);
dataM.SetId(nidM, tidM, channelP->Sid(), ridM);
*channelP = dataM;
2010-03-04 16:34:21 +01:00
}
cOsdItem *cIptvSourceParam::GetOsdItem(void)
{
2013-02-23 16:12:46 +01:00
debug("cIptvSourceParam::%s()", __FUNCTION__);
2013-02-23 14:31:11 +01:00
switch (paramM++) {
case 0: return new cMenuEditIntItem( tr("Nid"), &nidM, 0);
case 1: return new cMenuEditIntItem( tr("Tid"), &tidM, 0);
case 2: return new cMenuEditIntItem( tr("Rid"), &ridM, 0);
case 3: return new cMenuEditBoolItem(tr("Scan section ids"), &itpM.sidScanM);
case 4: return new cMenuEditBoolItem(tr("Scan pids"), &itpM.pidScanM);
case 5: return new cMenuEditStraItem(tr("Protocol"), &itpM.protocolM, ELEMENTS(protocolsM), protocolsM);
case 6: return new cMenuEditStrItem( tr("Address"), itpM.addressM, sizeof(itpM.addressM), allowedProtocolCharsS);
case 7: return new cMenuEditIntItem( tr("Parameter"), &itpM.parameterM, 0, 0xFFFF);
2010-03-04 16:34:21 +01:00
default: return NULL;
}
return NULL;
}