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
2014-01-02 21:47:43 +02:00

188 lines
5.8 KiB
C

/*
* source.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <ctype.h>
#include "common.h"
#include "source.h"
// --- cIptvTransponderParameters --------------------------------------------
cIptvTransponderParameters::cIptvTransponderParameters(const char *parametersP)
: sidScanM(0),
pidScanM(0),
protocolM(eProtocolUDP),
parameterM(0)
{
debug("cIptvTransponderParameters::%s(%s)", __FUNCTION__, parametersP);
memset(&addressM, 0, sizeof(addressM));
Parse(parametersP);
}
cString cIptvTransponderParameters::ToString(char typeP) const
{
debug("cIptvTransponderParameters::%s(%c)", __FUNCTION__, typeP);
const char *protocolstr;
switch (protocolM) {
case eProtocolEXT:
protocolstr = "EXT";
break;
case eProtocolCURL:
protocolstr = "CURL";
break;
case eProtocolHTTP:
protocolstr = "HTTP";
break;
case eProtocolFILE:
protocolstr = "FILE";
break;
default:
case eProtocolUDP:
protocolstr = "UDP";
break;
}
return cString::sprintf("S=%d|P=%d|F=%s|U=%s|A=%d", sidScanM, pidScanM, protocolstr, addressM, parameterM);
}
bool cIptvTransponderParameters::Parse(const char *strP)
{
debug("cIptvTransponderParameters::%s(%s)", __FUNCTION__, strP);
bool result = false;
if (strP && *strP) {
const char *delim = "|";
char *str = strdup(strP);
char *p = str;
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;
++data;
if (data && (*data == '=')) {
++data;
switch (toupper(*token)) {
case 'S':
sidScanM = (int)strtol(data, (char **)NULL, 10);
found_s = true;
break;
case 'P':
pidScanM = (int)strtol(data, (char **)NULL, 10);
found_p = true;
break;
case 'F':
if (strstr(data, "UDP")) {
protocolM = eProtocolUDP;
found_f = true;
}
else if (strstr(data, "CURL")) {
protocolM = eProtocolCURL;
found_f = true;
}
else if (strstr(data, "HTTP")) {
protocolM = eProtocolHTTP;
found_f = true;
}
else if (strstr(data, "FILE")) {
protocolM = eProtocolFILE;
found_f = true;
}
else if (strstr(data, "EXT")) {
protocolM = eProtocolEXT;
found_f = true;
}
break;
case 'U':
strn0cpy(addressM, data, sizeof(addressM));
found_u = true;
break;
case 'A':
parameterM = (int)strtol(data, (char **)NULL, 10);
found_a = true;
break;
default:
break;
}
}
str = NULL;
}
if (found_s && found_p && found_f && found_u && found_a)
result = true;
else
error("Invalid channel parameters: %s", p);
free(p);
}
return (result);
}
// --- cIptvSourceParam ------------------------------------------------------
const char *cIptvSourceParam::allowedProtocolCharsS = " abcdefghijklmnopqrstuvwxyz0123456789-.,#~\\^$[]()*+?{}/%@&=";
cIptvSourceParam::cIptvSourceParam(char sourceP, const char *descriptionP)
: cSourceParam(sourceP, descriptionP),
paramM(0),
nidM(0),
tidM(0),
ridM(0),
dataM(),
itpM()
{
debug("cIptvSourceParam::%s(%c, %s)", __FUNCTION__, sourceP, descriptionP);
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");
}
void cIptvSourceParam::SetData(cChannel *channelP)
{
debug("cIptvSourceParam::%s(%s)", __FUNCTION__, channelP->Parameters());
dataM = *channelP;
nidM = dataM.Nid();
tidM = dataM.Tid();
ridM = dataM.Rid();
itpM.Parse(dataM.Parameters());
paramM = 0;
}
void cIptvSourceParam::GetData(cChannel *channelP)
{
debug("cIptvSourceParam::%s(%s)", __FUNCTION__, channelP->Parameters());
channelP->SetTransponderData(channelP->Source(), channelP->Frequency(), dataM.Srate(), itpM.ToString(Source()), true);
channelP->SetId(nidM, tidM, channelP->Sid(), ridM);
}
cOsdItem *cIptvSourceParam::GetOsdItem(void)
{
debug("cIptvSourceParam::%s()", __FUNCTION__);
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);
default: return NULL;
}
return NULL;
}