diff options
author | Jochen Dolze <vdr@dolze.de> | 2012-04-14 17:47:44 +0200 |
---|---|---|
committer | Jochen Dolze <vdr@dolze.de> | 2012-04-14 17:47:44 +0200 |
commit | 8233bd640dca1c2b856039a223a4d4e916a3aaf0 (patch) | |
tree | a76b61eeeee3e1abdfde6a05057af163a19eafff | |
parent | c2fa8e301d8266225ffcd735cd120bc4a1ffd234 (diff) | |
download | vdr-plugin-xmltv2vdr-8233bd640dca1c2b856039a223a4d4e916a3aaf0.tar.gz vdr-plugin-xmltv2vdr-8233bd640dca1c2b856039a223a4d4e916a3aaf0.tar.bz2 |
Added more checks
-rw-r--r-- | import.cpp | 103 | ||||
-rw-r--r-- | import.h | 9 | ||||
-rw-r--r-- | xmltv2vdr.cpp | 50 |
3 files changed, 100 insertions, 62 deletions
@@ -844,11 +844,14 @@ bool cImport::FetchXMLTVEvent(sqlite3_stmt *stmt, cXMLTVEvent *xevent) cXMLTVEvent *cImport::PrepareAndReturn(sqlite3 *db, char *sql, sqlite3_stmt *stmt) { + if (!db) return NULL; + if (!sql) return NULL; + if (!stmt) return NULL; + int ret=sqlite3_prepare_v2(db,sql,strlen(sql),&stmt,NULL); if (ret!=SQLITE_OK) { esyslog("xmltv2vdr: ERROR %i %s",ret,sqlite3_errmsg(db)); - esyslog("xmltv2vdr: ERROR failed to prepare %s",sql); free(sql); return NULL; } @@ -864,10 +867,15 @@ cXMLTVEvent *cImport::PrepareAndReturn(sqlite3 *db, char *sql, sqlite3_stmt *stm return xevent; } -cXMLTVEvent *cImport::AddXMLTVEvent(sqlite3 *Db, const char *ChannelID, const cEvent *Event, +cXMLTVEvent *cImport::AddXMLTVEvent(cEPGSource *Source,sqlite3 *Db, const char *ChannelID, const cEvent *Event, const char *EITDescription) { if (!Db) return NULL; + if (!Source) return NULL; + if (!ChannelID) return NULL; + if (!Event) return NULL; + if (!EITDescription) return NULL; + struct passwd pwd,*pwdbuf; char buf[1024],*epdir=NULL; iconv_t conv=(iconv_t) -1; @@ -910,7 +918,7 @@ cXMLTVEvent *cImport::AddXMLTVEvent(sqlite3 *Db, const char *ChannelID, const cE cXMLTVEvent *xevent = new cXMLTVEvent(); if (!xevent) { - esyslog("xmltv2vdr: ERROR out of memory"); + Source->Elog("out of memory"); free(epdir); iconv_close(conv); return NULL; @@ -927,25 +935,19 @@ cXMLTVEvent *cImport::AddXMLTVEvent(sqlite3 *Db, const char *ChannelID, const cE xevent->SetSeason(season); xevent->SetEpisode(episode); - if (!pendingtransaction) + if (!Begin(Source,Db)) { - char *errmsg; - if (sqlite3_exec(Db,"BEGIN",NULL,NULL,&errmsg)!=SQLITE_OK) - { - esyslog("xmltv2vdr: ERROR BEGIN -> %s",errmsg); - sqlite3_free(errmsg); - } - else - { - pendingtransaction=true; - } + delete xevent; + free(epdir); + iconv_close(conv); + return NULL; } - const char *sql=xevent->GetSQL((const char *) EITSOURCE,99,ChannelID); + const char *sql=xevent->GetSQL(Source->Name(),Source->Index(),ChannelID); char *errmsg; if (sqlite3_exec(Db,sql,NULL,NULL,&errmsg)!=SQLITE_OK) { - esyslog("xmltv2vdr: ERROR %s",errmsg); + Source->Elog("%s",errmsg); sqlite3_free(errmsg); delete xevent; xevent=NULL; @@ -955,23 +957,14 @@ cXMLTVEvent *cImport::AddXMLTVEvent(sqlite3 *Db, const char *ChannelID, const cE return xevent; } -void cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Event, +bool cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Event, tEventID EventID, tEventID EITEventID, const char *EITDescription) { - if (!Source) return; - if (!pendingtransaction) - { - char *errmsg; - if (sqlite3_exec(Db,"BEGIN",NULL,NULL,&errmsg)!=SQLITE_OK) - { - Source->Elog("BEGIN -> %s",errmsg); - sqlite3_free(errmsg); - } - else - { - pendingtransaction=true; - } - } + if (!Source) return false; + if (!Db) return false; + if (!Event) return false; + + if (!Begin(Source,Db)) return false; char *sql=NULL; if (EITDescription) @@ -980,7 +973,7 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Ev if (!eitdescription) { Source->Elog("out of memory"); - return; + return false; } string ed=eitdescription; @@ -998,7 +991,7 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Ev { free(eitdescription); Source->Elog("out of memory"); - return; + return false; } free(eitdescription); @@ -1023,7 +1016,7 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Ev (long int) EITEventID,(long int) EventID,Source->Name())==-1) { Source->Elog("out of memory"); - return; + return false; } } @@ -1033,16 +1026,15 @@ void cImport::UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Ev Source->Elog("%s -> %s",sql,errmsg); free(sql); sqlite3_free(errmsg); - return; + return false; } free(sql); - return; + return true; } cXMLTVEvent *cImport::SearchXMLTVEvent(sqlite3 **Db, const char *ChannelID, const cEvent *Event) { - if (!Event) return NULL; if (!Db) return NULL; if (!*Db) @@ -1116,9 +1108,30 @@ cXMLTVEvent *cImport::SearchXMLTVEvent(sqlite3 **Db, const char *ChannelID, cons return NULL; } -void cImport::Commit(cEPGSource *Source, sqlite3 *Db) +bool cImport::Begin(cEPGSource *Source, sqlite3 *Db) { - if (!Db) return; + if (!Source) return false; + if (!Db) return false; + if (!pendingtransaction) + { + char *errmsg; + if (sqlite3_exec(Db,"BEGIN",NULL,NULL,&errmsg)!=SQLITE_OK) + { + Source->Elog("sqlite3: BEGIN -> %s",errmsg); + sqlite3_free(errmsg); + return false; + } + else + { + pendingtransaction=true; + } + } + return true; +} + +bool cImport::Commit(cEPGSource *Source, sqlite3 *Db) +{ + if (!Db) return false; if (pendingtransaction) { char *errmsg; @@ -1126,16 +1139,18 @@ void cImport::Commit(cEPGSource *Source, sqlite3 *Db) { if (Source) { - Source->Elog("sqlite3: %s",errmsg); + Source->Elog("sqlite3: COMMIT -> %s",errmsg); } else { - esyslog("sqlite3: %s", errmsg); + esyslog("sqlite3: ERROR COMMIT -> %s",errmsg); } sqlite3_free(errmsg); + return false; } pendingtransaction=false; } + return true; } int cImport::Process(cEPGSource *Source, cEPGExecutor &myExecutor) @@ -1266,8 +1281,10 @@ int cImport::Process(cEPGSource *Source, cEPGExecutor &myExecutor) } } - Commit(Source,db); - Source->Dlog("processed %i xmltv events",cnt); + if (Commit(Source,db)) + { + Source->Dlog("processed %i xmltv events",cnt); + } sqlite3_finalize(stmt); sqlite3_close(db); @@ -64,14 +64,15 @@ public: cImport(const char *EPGFile, cEPGMappings *Maps, cTEXTMappings *Texts); ~cImport(); int Process(cEPGSource *Source, cEPGExecutor &myExecutor); - void Commit(cEPGSource *Source, sqlite3 *Db); + bool Begin(cEPGSource *Source, sqlite3 *Db); + bool Commit(cEPGSource *Source, sqlite3 *Db); bool PutEvent(cEPGSource *Source, sqlite3 *Db, cSchedule* Schedule, cEvent *Event, cXMLTVEvent *xEvent, int Flags, int Option=IMPORT_ALL); - void UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Event, + bool UpdateXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const cEvent *Event, tEventID EventID, tEventID EITEventID, const char *EITDescription=NULL); cXMLTVEvent *SearchXMLTVEvent(sqlite3 **Db, const char *ChannelID, const cEvent *Event); - cXMLTVEvent *AddXMLTVEvent(sqlite3 *Db, const char *ChannelID, const cEvent *Event, - const char *EITDescription); + cXMLTVEvent *AddXMLTVEvent(cEPGSource *Source, sqlite3 *Db, const char *ChannelID, + const cEvent *Event, const char *EITDescription); bool WasChanged(cEvent *Event); }; diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp index 15e67d9..5ab5a0d 100644 --- a/xmltv2vdr.cpp +++ b/xmltv2vdr.cpp @@ -155,13 +155,19 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description) } cXMLTVEvent *xevent=import->SearchXMLTVEvent(&db,ChannelID,Event); + cEPGSource *source=NULL; if (!xevent) { if (!epall) return false; - xevent=import->AddXMLTVEvent(db,ChannelID,Event,Description); + source=sources->GetSource(EITSOURCE); + xevent=import->AddXMLTVEvent(source,db,ChannelID,Event,Description); if (!xevent) return false; } - cEPGSource *source=sources->GetSource(xevent->Source()); + else + { + source=sources->GetSource(xevent->Source()); + } + if (!source) return false; last.Set(source,xevent,Flags); } else @@ -182,18 +188,16 @@ bool cEPGHandler::SetDescription(cEvent* Event, const char* Description) if (update) { - import->UpdateXMLTVEvent(last.Source(),db,Event,last.xEvent()->EventID(), - Event->EventID(),Description); + if (!import->UpdateXMLTVEvent(last.Source(),db,Event,last.xEvent()->EventID(), + Event->EventID(),Description)) + { + return false; + } } - bool ret=import->PutEvent(last.Source(),db, - (cSchedule *) Event->Schedule(), - Event,last.xEvent(),last.Flags(),IMPORT_DESCRIPTION); - if (!ret) - { - dsyslog("xmltv2vdr: failed to put event description!"); - } - return ret; + return import->PutEvent(last.Source(),db, + (cSchedule *) Event->Schedule(), + Event,last.xEvent(),last.Flags(),IMPORT_DESCRIPTION); } bool cEPGHandler::SetParentalRating(cEvent* Event, int ParentalRating) @@ -221,9 +225,20 @@ bool cEPGHandler::SetParentalRating(cEvent* Event, int ParentalRating) if (!xevent) return false; cEPGSource *source=sources->GetSource(xevent->Source()); + if (!source) + { + delete xevent; + return false; + } - if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,db,Event,xevent->EventID(), - Event->EventID()); + if (!xevent->EITEventID()) + { + if (!import->UpdateXMLTVEvent(source,db,Event,xevent->EventID(),Event->EventID())) + { + delete xevent; + return false; + } + } last.Set(source,xevent,map->Flags()); } else @@ -269,6 +284,11 @@ bool cEPGHandler::SetShortText(cEvent* Event, const char* UNUSED(ShortText)) if (!xevent) return false; cEPGSource *source=sources->GetSource(xevent->Source()); + if (!source) + { + delete xevent; + return false; + } if (!xevent->EITEventID()) import->UpdateXMLTVEvent(source,db,Event,xevent->EventID(), Event->EventID()); @@ -354,7 +374,7 @@ void cEPGTimer::Action() cXMLTVEvent *xevent=import->SearchXMLTVEvent(&db,ChannelID,event); if (!xevent) { - xevent=import->AddXMLTVEvent(db,ChannelID,event,event->Description()); + xevent=import->AddXMLTVEvent(source,db,ChannelID,event,event->Description()); if (!xevent) continue; } |