vdr-plugin-iptv/source.c

184 lines
5.5 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 <ctype.h>
2015-03-08 13:33:18 +01:00
2010-03-04 16:34:21 +01:00
#include "common.h"
2015-03-08 13:33:18 +01:00
#include "log.h"
2010-03-04 16:34:21 +01:00
#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
{
2015-03-08 13:33:18 +01:00
debug1("%s (%s)", __PRETTY_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
{
2015-03-08 13:33:18 +01:00
debug1("%s (%c)", __PRETTY_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
{
2015-03-08 13:33:18 +01:00
debug1("%s (%s)", __PRETTY_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);
2014-01-02 20:47:43 +01:00
char *p = str;
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 (toupper(*token)) {
2010-03-08 20:12:06 +01:00
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
2014-01-02 20:47:43 +01:00
error("Invalid channel parameters: %s", p);
2014-01-02 20:47:43 +01:00
free(p);
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),
ridM(0),
dataM(),
itpM()
2010-03-04 16:34:21 +01:00
{
2015-03-08 13:33:18 +01:00
debug1("%s (%c, %s)", __PRETTY_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
{
2015-03-08 13:33:18 +01:00
debug1("%s (%s)", __PRETTY_FUNCTION__, channelP->Parameters());
2013-02-23 14:31:11 +01:00
dataM = *channelP;
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
{
2015-03-08 13:33:18 +01:00
debug1("%s (%s)", __PRETTY_FUNCTION__, channelP->Parameters());
channelP->SetTransponderData(channelP->Source(), channelP->Frequency(), dataM.Srate(), itpM.ToString(Source()), true);
2015-09-19 16:20:56 +02:00
channelP->SetId(NULL, channelP->Nid(), channelP->Tid(), channelP->Sid(), ridM);
2010-03-04 16:34:21 +01:00
}
cOsdItem *cIptvSourceParam::GetOsdItem(void)
{
2015-03-08 13:33:18 +01:00
debug1("%s", __PRETTY_FUNCTION__);
2013-02-23 14:31:11 +01:00
switch (paramM++) {
2014-03-16 15:46:21 +01:00
case 0: return new cMenuEditIntItem( tr("Rid"), &ridM, 0);
case 1: return new cMenuEditBoolItem(tr("Scan section ids"), &itpM.sidScanM);
case 2: return new cMenuEditBoolItem(tr("Scan pids"), &itpM.pidScanM);
case 3: return new cMenuEditStraItem(tr("Protocol"), &itpM.protocolM, ELEMENTS(protocolsM), protocolsM);
case 4: return new cMenuEditStrItem( tr("Address"), itpM.addressM, sizeof(itpM.addressM), allowedProtocolCharsS);
case 5: return new cMenuEditIntItem( tr("Parameter"), &itpM.parameterM, 0, 0xFFFF);
2010-03-04 16:34:21 +01:00
default: return NULL;
}
return NULL;
}