-
Notifications
You must be signed in to change notification settings - Fork 0
/
epgd.h
279 lines (216 loc) · 7.99 KB
/
epgd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* epgd.h
*
* See the README file for copyright information and how to reach the author.
*
*/
#pragma once
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
#include <libexslt/exslt.h>
#include <unistd.h>
#include <vector>
#include "lib/common.h"
#include "lib/db.h"
#include "lib/epgservice.h"
#include "lib/configuration.h"
#include "lib/searchtimer.h"
#include "epgdconfig.h"
#include "series.h"
#include "tvdbmanager.h"
#include "moviedbmanager.h"
#include "HISTORY.h"
#define confDirDefault "/etc/epgd"
extern const char* confDir;
//***************************************************************************
// Statistic
//***************************************************************************
struct Statistic
{
int bytes {0};
int files {0};
int rejected {0};
int nonUpdates {0};
};
class cEpgd;
//***************************************************************************
// Plugin
//***************************************************************************
class Plugin
{
public:
Plugin() {}
virtual ~Plugin() {}
virtual int init(cEpgd* aObject, int aUtf8)
{
obj = aObject;
utf8 = aUtf8;
return success;
}
virtual int exit() { return done; }
virtual int initDb() { return done; }
virtual int exitDb() { return done; }
virtual int atConfigItem(const char* Name, const char* Value) = 0;
virtual const char* getSource() = 0;
virtual int hasSource(const char* source) { return strcmp(getSource(), source) == 0; }
virtual int getPicture(const char* imagename, const char* fileRef, MemoryStruct* data) = 0;
virtual char* fsNameOfPicture(const char* imagename) // caller has to free the result!
{
char* buffer = strdup(imagename);
replaceChars(buffer, "<>:\"/\\:|?*", '_');
return buffer;
}
virtual int processDay(int day, int fullupdate, Statistic* stat) = 0;
virtual int cleanupBefore() { return done; }
virtual int cleanupAfter() { return done; }
virtual int ready() = 0;
protected:
cEpgd* obj {};
bool utf8 {true};
};
//***************************************************************************
// Plugin Loader
//***************************************************************************
class PluginLoader
{
public:
explicit PluginLoader(const char* name, Plugin* p = nullptr);
virtual ~PluginLoader();
int load();
Plugin* getPlugin() { return plugin; }
private:
char* fileName {};
void* handle {};
Plugin* plugin {};
};
//***************************************************************************
// EPG Deamon
//***************************************************************************
class cEpgd : public cFrame, public cSystemNotification
{
public:
cEpgd();
virtual ~cEpgd();
int init();
int initUuid();
void loop();
void scheduleAutoUpdate(int wait = 0);
int atConfigItem(const char* Name, const char* Value) override;
int parseEvent(cDbRow* event, xmlNode* node);
int dbConnected(int force = no)
{ return connection && connection->isConnected() && (!force || connection->check() == success); }
// static stuff
static void downF(int signal) { tell(eloWarning, "Shutdown triggered with signal %d", signal); shutdown = true; }
static bool doShutDown() { return shutdown; }
static void triggerF(int aSignal);
int wakeupVdr(const char* uuid);
int triggerVdrs(const char* trg, const char* plug = 0, const char* options = 0);
int __attribute__ ((format(printf, 5, 6))) message(int level, char type, const char* title, const char* format, ...) override;
int sendTccMail(const std::string& mailBody);
int sendTccTestMail();
xmlDocPtr transformXml(const char* buffer, int size, xsltStylesheetPtr stylesheet, const char* fileRef);
int storeToFs(MemoryStruct* data, const char* filename, const char* subPath);
int loadFromFs(MemoryStruct* data, const char* filename, const char* subPath);
int downloadFile(const char* url, int& size, MemoryStruct* data, int timeout = 30, const char* userAgent = "libcurl-agent/1.0");
// public for plugins access
cDbConnection* connection {};
cDbTable* eventsDb {};
cDbTable* useeventsDb {};
cDbTable* compDb {};
cDbTable* fileDb {};
cDbTable* imageDb {};
cDbTable* imageRefDb {};
cDbTable* episodeDb {};
cDbTable* mapDb {};
cDbTable* vdrDb {};
cDbTable* parameterDb {};
cDbTable* recordingListDb {};
cDbTable* timerDb {};
cDbTable* messageDb {};
cDbStatement* selectAllMap {};
cDbStatement* selectMapByUpdFlg {};
cDbStatement* selectMapByExt {};
cDbStatement* selectByCompTitle {};
cDbStatement* selectMaxUpdSp {};
cDbStatement* selectDistCompname {};
cDbStatement* selectByCompName {};
cDbStatement* selectByCompNames {};
cDbStatement* selectByCompNamesCombined {};
cDbStatement* selectByCompNamesCombinedLv {};
cDbStatement* updateEpisodeAtEvents {};
cDbStatement* updateScrReference {};
cDbStatement* selectMaxMapOrd {};
cDbStatement* selectMapOrdOf {};
cDbStatement* countDvbChanges {};
cDbStatement* selectNewRecordings {};
cDbStatement* countNewRecordings {};
cDbStatement* selectRecordingEvent {};
cDbStatement* selectRecOtherClient {};
cDbStatement* selectActiveVdrs {};
cDbStatement* selectWebUsers {};
cDbStatement* cleanupTimerActions {};
cDbStatement* selectNotAssumedTimers {};
cDbValue changeCount;
cDbValue newRecCount;
cDbValue maxLvDistance;
cDbProcedure* procMergeEpg {};
cDbProcedure* procUser {};
private:
int initDb();
int exitDb();
int checkDbDdl();
int migrateFromDbApi6();
int migrateFromDbApi7();
int tryFillEmptyRecTableFields();
int checkProcedure(const char* name, cDBS::ProcType type, cDbProcedure* fp = 0);
int checkView(const char* name, const char* file);
int registerMe();
int loadPlugins();
int initPlugins();
int initPluginDb();
int exitPluginDb();
void setState(cEpgdState::State state, time_t lastUpdate = 0, int silent = no);
int loadChannelmap();
int updateMapRow(char* extid, const char* source, const char* chan, int merge, int vps);
int applyChannelmapChanges();
int checkConnection();
// work
int update();
int cleanupEvents();
int cleanupPictures();
int updateSearchTimers(int force = yes, const char* reason = "");
int getPictures();
int storeImageRefs(tEventId evtId, const char* source, const char* images, const char* ext, const char* fileref);
int scrapNewEvents();
int cleanupSeriesAndMovies();
void scrapNewRecordings(int count);
// plugin interface
int cleanupBefore();
int cleanupAfter();
int getPicture(const char* source, const char* imagename, const char* fileRef, MemoryStruct* data);
int processDay(int day, int fullupdate, Statistic* stat);
// series
int evaluateEpisodes();
int updateEpisodes();
int lookupSeriesDataForRecording(cDbRow* recording, cTVDBManager::SeriesLookupData& lookupData);
// scraper stuff
int initScrapers();
void exitScrapers();
bool checkEventsForRecording(int eventId, const std::string& channelId, int& seriesId, int& episodeId, int& movieId);
// data
bool withutf8 {false};
bool scrapAndExit {false};
time_t nextUpdateAt {0};
time_t lastUpdateAt {0};
time_t lastMergeAt {0};
bool fullupdate {false};
bool fullreload {false};
std::vector<PluginLoader*> plugins;
cTVDBManager* tvdbManager {};
cMovieDBManager* movieDbManager {};
cSearchTimer* search {};
static bool shutdown;
static bool epgTrigger;
static bool searchTimerTrigger;
static bool recTableFixTrigger;
};