summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Dolze <vdr@dolze.de>2011-07-09 21:04:13 +0200
committerJochen Dolze <vdr@dolze.de>2011-07-09 21:04:13 +0200
commitb48d063954c93bc6c35c2d07fce1530a7ce355d7 (patch)
tree5d0a4a4317bf1a4b9ffb988d2e2e8d823e8425b0
parent0fcdd46b05f096c0ab226db31ea4378efd1f446c (diff)
downloadvdr-plugin-xmltv2vdr-b48d063954c93bc6c35c2d07fce1530a7ce355d7.tar.gz
vdr-plugin-xmltv2vdr-b48d063954c93bc6c35c2d07fce1530a7ce355d7.tar.bz2
Configfiles are now stored in /var/lib/epgsources (grabber) and ConfigDir (plugin)
Added ability to copy and reset channel settings Added input field for pin Grabbers get now called with arguments (channellist)
-rw-r--r--README20
-rw-r--r--parse.cpp2
-rw-r--r--po/de_DE.po36
-rw-r--r--po/it_IT.po35
-rw-r--r--setup.cpp90
-rw-r--r--setup.h1
-rw-r--r--xmltv2vdr.cpp453
-rw-r--r--xmltv2vdr.h19
8 files changed, 438 insertions, 218 deletions
diff --git a/README b/README
index 0362086..dddf965 100644
--- a/README
+++ b/README
@@ -15,7 +15,7 @@ See the file COPYING for more information.
Description:
Add epg info from epg sources into vdr. xmltv2vdr just imports data in
-xmltv format which must be provided by an external source (wich is not
+xmltv format which must be provided by an external source (which is not
part of this package)
Interface for sources:
@@ -25,12 +25,14 @@ name of the source/source.xmltv (e.g. epgdata.xmltv -> epgdata).
In the first line you can decide if your source provides data by file
(file must be placed in /var/lib/epgsources with extension .xmltv) or
pipe (binary with the same name is called by xmltv2vdr-plugin, and
-must be in the path), the second line shows the days which will be
-read by the plugin, followed by the maximum days which will be provided.
+must be in the path). There can be additional fields in the first
+line seperated with semicolons. The second option gives the time when
+the epg data will be updated from the origin, the third option informs
+the plugin, if a pin is needed for this source (0/1).
+The second line shows the maximum days which will be provieded.
The next lines are unique channelnames, provided by the source.
There can be application dependend data after each channelname. Note,
-that the plugin/VDR must be able to change this control file (channels
-will be marked with an asterisk if choosen in the setup).
+that the plugin/VDR must be able to read this control file.
See this link for an list of unique channelnames (and please report
if there should be more)
@@ -39,20 +41,20 @@ http://vdr-wiki.de/wiki/index.php/Xmltv2vdr-plugin#Kanalliste
Examples of control files (in /var/lib/epgsources):
-pipe
-1;16
+pipe;00:00;1
+16
rtl.de;004
sat1.de;005
prosieben.de;006
pipe
-1;10
+10
rtl.de
sat1.de
prosieben.de
file
-1;7
+7
rtl.de;004
sat1.de;005
nickcomedy;190:417
diff --git a/parse.cpp b/parse.cpp
index 6ace8e7..858d6b5 100644
--- a/parse.cpp
+++ b/parse.cpp
@@ -1059,7 +1059,7 @@ cParse::cParse(const char *Name, cEPGMappings *Maps, cTEXTMappings *Texts)
CodeSet++;
}
}
- dsyslog("xmltv2vdr: '%s' codeset is '%s'",Name,CodeSet ? CodeSet : "US-ASCII//TRANSLIT");
+ dsyslog("xmltv2vdr: '%s' vdr codeset is '%s'",Name,CodeSet ? CodeSet : "US-ASCII//TRANSLIT");
conv = new cCharSetConv("UTF-8",CodeSet ? CodeSet : "US-ASCII//TRANSLIT");
name=strdup(Name);
maps=Maps;
diff --git a/po/de_DE.po b/po/de_DE.po
index 758ee81..93a3b00 100644
--- a/po/de_DE.po
+++ b/po/de_DE.po
@@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: vdr\n"
"Report-Msgid-Bugs-To: <see README>\n"
-"POT-Creation-Date: 2011-07-06 20:45+0200\n"
+"POT-Creation-Date: 2011-07-09 19:55+0200\n"
"PO-Revision-Date: 2010-12-23 23:59+0100\n"
"Last-Translator: Jochen Dolze <vdr@dolze.de>\n"
"Language-Team: <vdr@linuxtv.org>\n"
@@ -39,13 +39,13 @@ msgstr "EPG Quellkanäle"
msgid "mapped"
msgstr "zugewiesen"
-msgid "up"
+msgid "Button$Up"
msgstr "hoch"
-msgid "down"
+msgid "Button$Down"
msgstr "runter"
-msgid "edit"
+msgid "Button$Edit"
msgstr "editieren"
msgid "texts"
@@ -108,12 +108,21 @@ msgstr "Mitwirkende"
msgid "days in advance"
msgstr "Anzahl Tage"
+msgid "pin"
+msgstr "Pin"
+
msgid "channels provided"
msgstr "Verfügbare Kanäle"
msgid "selected"
msgstr "ausgewählt"
+msgid "Button$Reset"
+msgstr "rücksetzen"
+
+msgid "Button$Copy"
+msgstr "kopieren"
+
msgid "epg source channel options"
msgstr "EPG Quellkanal Optionen"
@@ -171,21 +180,24 @@ msgstr "EPG Quellkanalzuordnungen"
msgid "none"
msgstr "keine"
-msgid "unmap"
+msgid "Button$Unmap"
msgstr "entfernen"
-msgid "map"
+msgid "Button$Map"
msgstr "hinzufügen"
-msgid "choose"
-msgstr "Auswahl"
+msgid "Copy settings to all channels?"
+msgstr ""
+
+#, fuzzy
+msgid "Reset all channel settings?"
+msgstr "EPG Quellkanal Optionen"
+
+msgid "Button$Choose"
+msgstr "auswählen"
msgid "xmltv2vdr plugin still working"
msgstr "xmltv2vdr plugin ist noch aktiv"
msgid "Imports xmltv epg into vdr"
msgstr "Importiert xmltv epg in den VDR"
-
-#, fuzzy
-#~ msgid "update"
-#~ msgstr "Adapter"
diff --git a/po/it_IT.po b/po/it_IT.po
index 4b9a1d7..cde8b6f 100644
--- a/po/it_IT.po
+++ b/po/it_IT.po
@@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: vdr\n"
"Report-Msgid-Bugs-To: <see README>\n"
-"POT-Creation-Date: 2011-07-06 20:45+0200\n"
+"POT-Creation-Date: 2011-07-09 19:55+0200\n"
"PO-Revision-Date: 2011-03-05 15:45+0100\n"
"Last-Translator: Diego Pierotto <vdr-italian@tiscali.it>\n"
"Language-Team: <vdr@linuxtv.org>\n"
@@ -42,13 +42,13 @@ msgstr "Canali sorgente EPG"
msgid "mapped"
msgstr "Mappato"
-msgid "up"
+msgid "Button$Up"
msgstr "Su"
-msgid "down"
-msgstr "Giù"
+msgid "Button$Down"
+msgstr "Giu"
-msgid "edit"
+msgid "Button$Edit"
msgstr "Modifica"
msgid "texts"
@@ -111,12 +111,21 @@ msgstr "Crediti"
msgid "days in advance"
msgstr "Giorni in anticipo"
+msgid "pin"
+msgstr "Pin"
+
msgid "channels provided"
msgstr "Canali forniti"
msgid "selected"
msgstr "Selezionato"
+msgid "Button$Reset"
+msgstr ""
+
+msgid "Button$Copy"
+msgstr ""
+
msgid "epg source channel options"
msgstr "Opzioni canali sorgente EPG"
@@ -174,13 +183,20 @@ msgstr "Mappature canali sorgente EPG"
msgid "none"
msgstr "Nessuno"
-msgid "unmap"
+msgid "Button$Unmap"
msgstr "Non mappare"
-msgid "map"
-msgstr "Mappa"
+msgid "Button$Map"
+msgstr "Mappare"
-msgid "choose"
+msgid "Copy settings to all channels?"
+msgstr ""
+
+#, fuzzy
+msgid "Reset all channel settings?"
+msgstr "Opzioni canali sorgente EPG"
+
+msgid "Button$Choose"
msgstr "Scegli"
msgid "xmltv2vdr plugin still working"
@@ -188,4 +204,3 @@ msgstr "Plugin XMLTV2VDR ancora in esecuzione"
msgid "Imports xmltv epg into vdr"
msgstr "Importa EPG di XMLTV in VDR"
-
diff --git a/setup.cpp b/setup.cpp
index e8f4700..3959e11 100644
--- a/setup.cpp
+++ b/setup.cpp
@@ -239,20 +239,20 @@ eOSState cMenuSetupXmltv2vdr::ProcessKey (eKeys Key)
{
if ((sourcesEnd-sourcesBegin)>0)
{
- SetHelp(NULL,tr("up"),tr("down"),tr("edit"));
+ SetHelp(NULL,tr("Button$Up"),tr("Button$Down"),tr("Button$Edit"));
}
else
{
- SetHelp(NULL,NULL,NULL,tr("edit"));
+ SetHelp(NULL,NULL,NULL,tr("Button$Edit"));
}
}
else if (Current()==mappingEntry)
{
- SetHelp(NULL,NULL,NULL,tr("edit"));
+ SetHelp(NULL,NULL,NULL,tr("Button$Edit"));
}
else if ((Current()>=mappingBegin) && (Current()<=mappingEnd))
{
- SetHelp(NULL,NULL,NULL,tr("edit"));
+ SetHelp(NULL,NULL,NULL,tr("Button$Edit"));
}
else
{
@@ -636,6 +636,7 @@ cMenuSetupXmltv2vdrChannelSource::cMenuSetupXmltv2vdrChannelSource(cPluginXmltv2
baseplugin=Plugin;
sel=NULL;
days=0;
+ pin[0]=0;
epgsrc=baseplugin->EPGSource(Index);
if (!epgsrc) return;
@@ -645,7 +646,15 @@ cMenuSetupXmltv2vdrChannelSource::cMenuSetupXmltv2vdrChannelSource(cPluginXmltv2
Add(newtitle(tr("options")));
days=epgsrc->DaysInAdvance();
Add(new cMenuEditIntItem(tr("days in advance"),&days,1,epgsrc->DaysMax()));
-
+ if (epgsrc->NeedPin())
+ {
+ if (epgsrc->Pin())
+ {
+ strncpy(pin,epgsrc->Pin(),sizeof(pin)-1);
+ pin[sizeof(pin)-1]=0;
+ }
+ Add(new cMenuEditStrItem(tr("pin"),pin,sizeof(pin)));
+ }
Add(newtitle(tr("channels provided")));
cEPGChannels *channellist=epgsrc->ChannelList();
@@ -690,6 +699,8 @@ void cMenuSetupXmltv2vdrChannelSource::Store(void)
epgsrc->ChangeChannelSelection(sel);
epgsrc->ChangeDaysInAdvance(days);
+ if (epgsrc->NeedPin())
+ epgsrc->ChangePin(pin);
epgsrc->Store();
cEPGChannels *channellist=epgsrc->ChannelList();
@@ -763,6 +774,7 @@ cMenuSetupXmltv2vdrChannelMap::cMenuSetupXmltv2vdrChannelMap(cPluginXmltv2vdr *P
days=map->Days();
daysmax=getdaysmax();
c1=c2=c3=cm=0;
+ SetHelp(NULL,NULL,tr("Button$Reset"),tr("Button$Copy"));
output();
}
@@ -917,12 +929,12 @@ eOSState cMenuSetupXmltv2vdrChannelMap::ProcessKey (eKeys Key)
case kDown:
case kDown|k_Repeat:
if (Current()>=cm)
- SetHelp(tr("unmap"),tr("map"));
+ SetHelp(tr("Button$Unmap"),tr("Button$Map"));
break;
case kUp:
case kUp|k_Repeat:
if (Current()<cm)
- SetHelp(NULL,NULL);
+ SetHelp(NULL,NULL,tr("Button$Reset"),tr("Button$Copy"));
default:
break;
}
@@ -933,7 +945,7 @@ eOSState cMenuSetupXmltv2vdrChannelMap::ProcessKey (eKeys Key)
switch (Key)
{
case kOk:
- if ((Current()>=16) && (!hasmaps))
+ if ((Current()>=cm) && (!hasmaps))
{
return AddSubMenu(new cMenuSetupXmltv2vdrChannelsVDR(baseplugin,this,channel,title));
}
@@ -944,18 +956,66 @@ eOSState cMenuSetupXmltv2vdrChannelMap::ProcessKey (eKeys Key)
}
break;
case kRed:
- item=Get(Current());
- if (item)
+ if (Current()>=cm)
{
- if (map)
+ item=Get(Current());
+ if (item)
{
- map->RemoveChannel(atoi(item->Text()));
- output();
+ if (map)
+ {
+ map->RemoveChannel(atoi(item->Text()));
+ output();
+ }
}
}
break;
case kGreen:
- return AddSubMenu(new cMenuSetupXmltv2vdrChannelsVDR(baseplugin,this,channel,title));
+ if (Current()>=cm)
+ return AddSubMenu(new cMenuSetupXmltv2vdrChannelsVDR(baseplugin,this,channel,title));
+ break;
+ case kBlue: // copy
+ if ((Current()<cm) && (baseplugin))
+ {
+ if (Skins.Message(mtInfo,tr("Copy settings to all channels?"))==kOk)
+ {
+ const char *oldchannel=channel;
+ cEPGMapping *tmap=map;
+ for (int i=0; i<baseplugin->EPGMappingCount();i++)
+ {
+ if (strcmp(baseplugin->EPGMapping(i)->ChannelName(),channel))
+ {
+ channel=baseplugin->EPGMapping(i)->ChannelName();
+ map=baseplugin->EPGMapping(i);
+ Store();
+ }
+ }
+ map=tmap;
+ channel=oldchannel;
+ state=osContinue;
+ }
+ }
+ break;
+ case kYellow: // reset
+ if (Current()<cm)
+ {
+ if (Skins.Message(mtInfo,tr("Reset all channel settings?"))==kOk)
+ {
+ const char *oldchannel=channel;
+ cEPGMapping *tmap=map;
+ flags=0;
+ days=1;
+ for (int i=0; i<baseplugin->EPGMappingCount();i++)
+ {
+ channel=baseplugin->EPGMapping(i)->ChannelName();
+ map=baseplugin->EPGMapping(i);
+ Store();
+ }
+ map=tmap;
+ channel=oldchannel;
+ output();
+ state=osContinue;
+ }
+ }
break;
default:
break;
@@ -1062,7 +1122,7 @@ cMenuSetupXmltv2vdrChannelsVDR::cMenuSetupXmltv2vdrChannelsVDR(cPluginXmltv2vdr
{
baseplugin=Plugin;
map=Map;
- SetHelp(NULL,NULL,tr("choose"));
+ SetHelp(NULL,NULL,tr("Button$Choose"));
SetTitle(Title);
for (cChannel *channel = Channels.First(); channel; channel=Channels.Next(channel))
diff --git a/setup.h b/setup.h
index 003f540..a787db7 100644
--- a/setup.h
+++ b/setup.h
@@ -98,6 +98,7 @@ private:
cEPGSource *epgsrc;
int *sel;
int days;
+ char pin[255];
cOsdItem *newtitle (const char *s);
public:
cMenuSetupXmltv2vdrChannelSource(cPluginXmltv2vdr *Plugin, cMenuSetupXmltv2vdr *Menu, int Index);
diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp
index 7a2a83d..9f79c01 100644
--- a/xmltv2vdr.cpp
+++ b/xmltv2vdr.cpp
@@ -47,16 +47,16 @@ cEPGExecutor::cEPGExecutor(cEPGSources *Sources) : cThread("xmltv2vdr importer")
void cEPGExecutor::Action()
{
if (!sources) return;
- bool ret=false;
+ int ret=0;
for (cEPGSource *epgs=sources->First(); epgs; epgs=sources->Next(epgs))
{
int retries=0;
while (retries<2)
{
ret=epgs->Execute();
- if ((ret!=0) && (ret<128))
+ if ((ret>0) && (ret<126))
{
- dsyslog("xmltv2vdr: waiting 60 seconds (%i)",retries);
+ dsyslog("xmltv2vdr: '%s' waiting 60 seconds",epgs->Name());
sleep(60);
retries++;
}
@@ -65,6 +65,7 @@ void cEPGExecutor::Action()
break;
}
}
+ if (retries>=2) esyslog("xmltv2vdr: '%s' ERROR skipping after %i retries",epgs->Name(),retries);
if (!ret) break; // TODO: check if we must execute second/third source!
}
if (!ret) cSchedules::Cleanup(true);
@@ -72,11 +73,14 @@ void cEPGExecutor::Action()
// -------------------------------------------------------------
-cEPGSource::cEPGSource(const char *Name, cEPGMappings *Maps, cTEXTMappings *Texts)
+cEPGSource::cEPGSource(const char *Name, const char *ConfDir, cEPGMappings *Maps, cTEXTMappings *Texts)
{
dsyslog("xmltv2vdr: '%s' added epgsource",Name);
name=strdup(Name);
+ confdir=strdup(ConfDir);
+ pin=NULL;
pipe=false;
+ needpin=false;
daysinadvance=0;
ready2parse=ReadConfig();
parse=new cParse(Name, Maps, Texts);
@@ -87,80 +91,172 @@ cEPGSource::~cEPGSource()
{
dsyslog("xmltv2vdr: '%s' epgsource removed",name);
free((void *) name);
+ free((void *) confdir);
+ if (pin) free((void *) pin);
if (parse) delete parse;
}
bool cEPGSource::ReadConfig()
{
- dsyslog("xmltv2vdr: '%s' reading config",name);
char *fname=NULL;
- if (asprintf(&fname,"%s/%s",EPGSOURCES,name)!=-1)
+ if (asprintf(&fname,"%s/%s",EPGSOURCES,name)==-1)
+ {
+ esyslog("xmltv2vdr: '%s' out of memory",name);
+ return false;
+ }
+ FILE *f=fopen(fname,"r+");
+ if (!f)
+ {
+ esyslog("xmltv2vdr: '%s' ERROR cannot read config file %s",name,fname);
+ free(fname);
+ return false;
+ }
+ dsyslog("xmltv2vdr: '%s' reading source config",name);
+ size_t lsize;
+ char *line=NULL;
+ int linenr=1;
+ while (getline(&line,&lsize,f)!=-1)
{
- FILE *f=fopen(fname,"r+");
- if (f)
+ if (linenr==1)
{
- size_t lsize;
- char *line=NULL;
- int linenr=1;
- while (getline(&line,&lsize,f)!=-1)
+ if (!strncmp(line,"pipe",4))
{
- if (linenr==1)
- {
- if (!strncmp(line,"pipe",4))
- {
- dsyslog("xmltv2vdr: '%s' is providing data through a pipe",name);
- pipe=true;
- }
- else
- {
- dsyslog("xmltv2vdr: '%s' is providing data through a file",name);
- pipe=false;
- }
- }
- if (linenr==2)
+ dsyslog("xmltv2vdr: '%s' is providing data through a pipe",name);
+ pipe=true;
+ }
+ else
+ {
+ dsyslog("xmltv2vdr: '%s' is providing data through a file",name);
+ pipe=false;
+ }
+ char *ndt=strchr(line,';');
+ if (ndt)
+ {
+ *ndt=0;
+ ndt++;
+ char *pn=strchr(ndt,';');
+ if (pn)
{
- char *semicolon=strchr(line,';');
- if (semicolon)
- {
- *semicolon=0;
- semicolon++;
- daysinadvance=atoi(line);
- daysmax=atoi(semicolon);
- dsyslog("xmltv2vdr: '%s' days=%i/%i",name,daysinadvance,daysmax);
- }
+ *pn=0;
+ pn++;
}
- if (linenr>2)
+ /*
+ newdatatime=atoi(ndt);
+ if (!newdatatime) dsyslog("xmltv2vdr: '%s' updates source data @%02i:%02i",name,1,2);
+ */
+ if (pn)
{
- // channels
- char *semicolon=strchr(line,';');
- if (semicolon) *semicolon=0;
- char *lf=strchr(line,10);
- if (lf) *lf=0;
- bool used=false;
- char *cname=line;
- if (line[0]=='*')
+ pn=compactspace(pn);
+ if (pn[0]=='1')
{
- cname++;
- used=true;
+ dsyslog("xmltv2vdr: '%s' is needing a pin",name);
+ needpin=true;
}
- cEPGChannel *epgchannel= new cEPGChannel(cname,used);
- if (epgchannel) channels.Add(epgchannel);
}
- linenr++;
}
- if (line) free(line);
- channels.Sort();
- fclose(f);
+ }
+ if (linenr==2)
+ {
+ char *semicolon=strchr(line,';');
+ if (semicolon)
+ {
+ // backward compatibility
+ *semicolon=0;
+ semicolon++;
+ daysmax=atoi(semicolon);
+ }
+ else
+ {
+ daysmax=atoi(line);
+ }
+ dsyslog("xmltv2vdr: '%s' daysmax=%i",name,daysmax);
+ }
+ if (linenr>2)
+ {
+ // channels
+ char *semicolon=strchr(line,';');
+ if (semicolon) *semicolon=0;
+ char *lf=strchr(line,10);
+ if (lf) *lf=0;
+ char *cname=line;
+ if (line[0]=='*')
+ {
+ // backward compatibility
+ cname++;
+ }
+ cEPGChannel *epgchannel= new cEPGChannel(cname,false);
+ if (epgchannel) channels.Add(epgchannel);
+ }
+ linenr++;
+ }
+ if (line) free(line);
+ channels.Sort();
+ fclose(f);
+ free(fname);
+
+ /* --------------- */
+
+ if (asprintf(&fname,"%s/%s",confdir,name)==-1)
+ {
+ esyslog("xmltv2vdr: '%s' out of memory",name);
+ return false;
+ }
+ f=fopen(fname,"r+");
+ if (!f)
+ {
+ if (errno!=ENOENT)
+ {
+ esyslog("xmltv2vdr: '%s' ERROR cannot read config file %s",name,fname);
free(fname);
return true;
}
- else
+ /* still no config? -> ok */
+ free(fname);
+ return true;
+ }
+ dsyslog("xmltv2vdr: '%s' reading plugin config",name);
+ line=NULL;
+ linenr=1;
+ while (getline(&line,&lsize,f)!=-1)
+ {
+ if ((linenr==1) && (needpin))
{
- esyslog("xmltv2vdr: '%s' cannot read config file",name);
+ char *lf=strchr(line,10);
+ if (lf) *lf=0;
+ if (strcmp(line,"#no pin"))
+ {
+ ChangePin(line);
+ dsyslog("xmltv2vdr: '%s' pin set",name);
+ }
}
- free(fname);
+ if (linenr==2)
+ {
+ daysinadvance=atoi(line);
+ dsyslog("xmltv2vdr: '%s' daysinadvance=%i",name,daysinadvance);
+ }
+ if (linenr>2)
+ {
+ // channels
+ char *lf=strchr(line,10);
+ if (lf) *lf=0;
+
+ for (int x=0; x<channels.Count(); x++)
+ {
+ if (!strcmp(line,channels.Get(x)->Name()))
+ {
+ channels.Get(x)->SetUsage(true);
+ break;
+ }
+ }
+ }
+ linenr++;
}
- return false;
+ if (line) free(line);
+ channels.Sort();
+ fclose(f);
+ free(fname);
+
+ return true;
}
int cEPGSource::Execute()
@@ -171,102 +267,143 @@ int cEPGSource::Execute()
int l=0;
int ret=0;
- if (pipe)
+ cExtPipe p;
+
+ char *cmd=NULL;
+ if (asprintf(&cmd,"%s %i '%s'",name,daysinadvance,pin ? pin : "")==-1)
{
- cExtPipe p;
- if (p.Open(name,"r"))
+ esyslog("xmltv2vdr: '%s' ERROR out of memory",name);
+ return 134;
+ }
+
+ for (int x=0; x<channels.Count(); x++)
+ {
+ if (channels.Get(x)->InUse())
{
- dsyslog("xmltv2vdr: '%s' executing epgsource",name);
- int c;
- while ((c=fgetc(p.Out()))!=EOF)
+ int len=strlen(cmd);
+ int clen=strlen(channels.Get(x)->Name());
+ char *ncmd=(char *) realloc(cmd,len+clen+5);
+ if (!ncmd)
{
- if (l%20==0) result=(char *) realloc(result, l+21);
- result[l++]=c;
+ free(cmd);
+ esyslog("xmltv2vdr: '%s' ERROR out of memory",name);
+ return 134;
}
- int status;
- if (p.Close(status)>0)
+ cmd=ncmd;
+ strcat(cmd," ");
+ strcat(cmd,channels.Get(x)->Name());
+ strcat(cmd," ");
+ }
+ }
+ dsyslog("xmltv2vdr: '%s' %s",name,cmd);
+ if (!p.Open(cmd,"r"))
+ {
+ free(cmd);
+ esyslog("xmltv2vdr: '%s' ERROR failed to open pipe",name);
+ return 141;
+ }
+ free(cmd);
+ dsyslog("xmltv2vdr: '%s' executing epgsource",name);
+ if (pipe)
+ {
+ int c;
+ while ((c=fgetc(p.Out()))!=EOF)
+ {
+ if (l%20==0) result=(char *) realloc(result, l+21);
+ result[l++]=c;
+ }
+ int status;
+ if (p.Close(status)>0)
+ {
+ int returncode=WEXITSTATUS(status);
+ if ((!returncode) && (result))
{
- int returncode=WEXITSTATUS(status);
- if ((!returncode) && (result))
+ dsyslog("xmltv2vdr: '%s' parsing output",name);
+ result[l]=0;
+ if (!parse->Process(result,l))
{
- dsyslog("xmltv2vdr: '%s' parsing output",name);
- result[l]=0;
- if (!parse->Process(result,l))
- {
- esyslog("xmltv2vdr: '%s' ERROR failed to parse output",name);
- ret=141;
- }
- }
- else
- {
- esyslog("xmltv2vdr: '%s' ERROR epgsource returned %i",name,returncode);
- ret=returncode;
+ esyslog("xmltv2vdr: '%s' ERROR failed to parse output",name);
+ ret=141;
}
}
else
{
- esyslog("xmltv2vdr: '%s' ERROR failed to execute",name);
- ret=126;
+ esyslog("xmltv2vdr: '%s' ERROR epgsource returned %i",name,returncode);
+ ret=returncode;
}
- if (result) free(result);
}
else
{
- esyslog("xmltv2vdr: '%s' ERROR failed to open pipe",name);
- ret=141;
+ esyslog("xmltv2vdr: '%s' ERROR failed to execute",name);
+ ret=126;
}
+ if (result) free(result);
}
else
{
- char *fname=NULL;
- if (asprintf(&fname,"%s/%s.xmltv",EPGSOURCES,name)!=-1)
- {
- dsyslog("xmltv2vdr: '%s' reading from '%s'",name,fname);
+ while ((fgetc(p.Out()))!=EOF) { }
- int fd=open(fname,O_RDONLY);
- if (fd!=-1)
+ int status;
+ if (p.Close(status)>0)
+ {
+ int returncode=WEXITSTATUS(status);
+ if (!returncode)
{
+ char *fname=NULL;
+ if (asprintf(&fname,"%s/%s.xmltv",EPGSOURCES,name)==-1)
+ {
+ esyslog("xmltv2vdr: '%s' ERROR out of memory",name);
+ return 134;
+ }
+ dsyslog("xmltv2vdr: '%s' reading from '%s'",name,fname);
+
+ int fd=open(fname,O_RDONLY);
+ if (fd==-1)
+ {
+ esyslog("xmltv2vdr: '%s' ERROR failed to open '%s'",name,fname);
+ free(fname);
+ return 157;
+ }
+
struct stat statbuf;
- if (fstat(fd,&statbuf)!=-1)
+ if (fstat(fd,&statbuf)==-1)
{
- l=statbuf.st_size;
- result=(char *) malloc(l+1);
- if (result)
- {
- if (read(fd,result,statbuf.st_size)==statbuf.st_size)
- {
- if (!parse->Process(result,l))
- {
- esyslog("xmltv2vdr: '%s' failed to parse output",name);
- ret=149;
- }
- }
- else
- {
- esyslog("xmltv2vdr: '%s' ERROR failed to read '%s'",name,fname);
- ret=149;
- }
- free(result);
- }
- else
+ esyslog("xmltv2vdr: '%s' ERROR failed to stat '%s'",name,fname);
+ close(fd);
+ free(fname);
+ return 157;
+ }
+ l=statbuf.st_size;
+ result=(char *) malloc(l+1);
+ if (!result)
+ {
+ close(fd);
+ free(fname);
+ esyslog("xmltv2vdr: '%s' ERROR out of memory",name);
+ return 134;
+ }
+ if (read(fd,result,statbuf.st_size)==statbuf.st_size)
+ {
+ if (!parse->Process(result,l))
{
- esyslog("xmltv2vdr: '%s' ERROR out of memory",name);
- ret=134;
+ esyslog("xmltv2vdr: '%s' failed to parse output",name);
+ ret=149;
}
}
else
{
- esyslog("xmltv2vdr: '%s' ERROR failed to stat '%s'",name,fname);
- ret=157;
+ esyslog("xmltv2vdr: '%s' ERROR failed to read '%s'",name,fname);
+ ret=149;
}
+ free(result);
close(fd);
+ free(fname);
}
else
{
- esyslog("xmltv2vdr: '%s' ERROR failed to open '%s'",name,fname);
- ret=157;
+ esyslog("xmltv2vdr: '%s' ERROR epgsource returned %i",name,returncode);
+ ret=returncode;
}
- free(fname);
}
}
return ret;
@@ -284,79 +421,48 @@ void cEPGSource::Store(void)
{
char *fname1=NULL;
char *fname2=NULL;
- if (asprintf(&fname1,"%s/%s",EPGSOURCES,name)==-1) return;
- if (asprintf(&fname2,"%s/%s.new",EPGSOURCES,name)==-1)
+ if (asprintf(&fname1,"%s/%s",confdir,name)==-1) return;
+ if (asprintf(&fname2,"%s/%s.new",confdir,name)==-1)
{
esyslog("xmltv2vdr: '%s' out of memory",name);
free(fname1);
return;
}
- FILE *r=fopen(fname1,"r+");
- if (!r)
- {
- esyslog("xmltv2vdr: '%s' cannot read %s",name,fname1);
- free(fname1);
- free(fname2);
- return;
- }
- int oldmask=umask(0664);
FILE *w=fopen(fname2,"w+");
- umask(oldmask);
if (!w)
{
esyslog("xmltv2vdr: '%s' cannot create %s",name,fname2);
- fclose(r);
unlink(fname2);
free(fname1);
free(fname2);
return;
}
- char *line=NULL;
- size_t lsize;
- int linenr=1;
- while (getline(&line,&lsize,r)!=-1)
+ if (pin)
{
- if (linenr==2)
- {
- fprintf(w,"%i;%i\n",DaysInAdvance(),DaysMax());
- }
- else if (linenr>2)
- {
- char *txt=line;
- if (txt[0]=='*') txt++;
- for (int i=0; i<ChannelList()->Count(); i++)
- {
- if (!strncmp(txt,ChannelList()->Get(i)->Name(),strlen(ChannelList()->Get(i)->Name())))
- {
- if (ChannelList()->Get(i)->InUse())
- {
- fprintf(w,"*%s",txt);
- }
- else
- {
- fprintf(w,"%s",txt);
- }
- break;
- }
- }
- }
- else
+ fprintf(w,"%s\n",pin);
+ }
+ else
+ {
+ fprintf(w,"#no pin\n");
+ }
+ fprintf(w,"%i\n",DaysInAdvance());
+ for (int i=0; i<ChannelList()->Count(); i++)
+ {
+ if (ChannelList()->Get(i)->InUse())
{
- fprintf(w,"%s",line);
+ fprintf(w,"%s\n",ChannelList()->Get(i)->Name());
}
- linenr++;
}
- if (line) free(line);
+ fclose(w);
+
struct stat statbuf;
- if (fstat(fileno(r),&statbuf)!=-1)
+ if (stat(confdir,&statbuf)!=-1)
{
- if (fchown(fileno(w),statbuf.st_uid,statbuf.st_gid)) {};
- if (fchmod(fileno(w),statbuf.st_mode | S_IRGRP | S_IWGRP)) {};
+ if (chown(fname2,statbuf.st_uid,statbuf.st_gid)) {}
}
- fclose(w);
- fclose(r);
+
rename(fname2,fname1);
free(fname1);
free(fname2);
@@ -451,7 +557,7 @@ void cPluginXmltv2vdr::ReadInEPGSources(bool Reload)
id[4]=0;
if (!strcmp(id,"file") || !strcmp(id,"pipe"))
{
- epgsources.Add(new cEPGSource(dirent->d_name,&epgmappings,&textmappings));
+ epgsources.Add(new cEPGSource(dirent->d_name,confdir,&epgmappings,&textmappings));
}
else
{
@@ -488,6 +594,7 @@ cPluginXmltv2vdr::cPluginXmltv2vdr(void) : epgexecutor(&epgsources)
// Initialize any member variables here.
// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
+ confdir=NULL;
WakeUp=0;
UpStart=0;
last_exectime_t=0;
@@ -536,6 +643,7 @@ bool cPluginXmltv2vdr::Initialize(void)
bool cPluginXmltv2vdr::Start(void)
{
// Start any background activities the plugin shall perform.
+ confdir=strdup(ConfigDirectory(PLUGIN_NAME_I18N)); // creates internally the confdir!
cParse::InitLibXML();
ReadInEPGSources();
if (UpStart)
@@ -557,6 +665,11 @@ void cPluginXmltv2vdr::Stop(void)
removeepgmappings();
removetextmappings();
cParse::CleanupLibXML();
+ if (confdir)
+ {
+ free(confdir);
+ confdir=NULL;
+ }
}
void cPluginXmltv2vdr::Housekeeping(void)
diff --git a/xmltv2vdr.h b/xmltv2vdr.h
index 3287a6a..1b63eab 100644
--- a/xmltv2vdr.h
+++ b/xmltv2vdr.h
@@ -46,15 +46,18 @@ class cEPGSource : public cListObject
{
private:
const char *name;
+ const char *confdir;
+ const char *pin;
cParse *parse;
bool ready2parse;
bool pipe;
+ bool needpin;
int daysinadvance;
int daysmax;
bool ReadConfig();
cEPGChannels channels;
public:
- cEPGSource(const char *Name,cEPGMappings *Maps,cTEXTMappings *Texts);
+ cEPGSource(const char *Name,const char *ConfDir,cEPGMappings *Maps,cTEXTMappings *Texts);
~cEPGSource();
int Execute();
void Store(void);
@@ -71,14 +74,27 @@ public:
{
return daysinadvance;
}
+ bool NeedPin()
+ {
+ return needpin;
+ }
const char *Name()
{
return name;
}
+ const char *Pin()
+ {
+ return pin;
+ }
void ChangeDaysInAdvance(int NewDaysInAdvance)
{
daysinadvance=NewDaysInAdvance;
}
+ void ChangePin(const char *NewPin)
+ {
+ if (pin) free((void *) pin);
+ pin=strdup(NewPin);
+ }
};
class cEPGSources : public cList<cEPGSource> {};
@@ -105,6 +121,7 @@ private:
bool epgsourceexists(const char *name);
int exectime;
time_t exectime_t,last_exectime_t;
+ char *confdir;
public:
int ExecTime()
{