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
|
/*
* series.h
*
* See the README file for copyright information
*
*/
#ifndef __SERIES_H_
#define __SERIES_H_
#include <string>
#include "lib/db.h"
#include "svdrpclient.h"
#define episodeFileExtension ".episodes"
//***************************************************************************
//
//***************************************************************************
enum SvdrRetrunCodes
{
codeCommunicationEnd = 0,
codeFileContent = 216,
codeTransferEnd = 217,
codeFileInfo = 218,
codeError = 500
/*
# 214 Help message
# 215 LIST or GET data
# 216 GET data, multiple data sets
# 217 End of multiple data sets
# 218 Info line for 215, 216
# 219 Info data
# 220 VDR service ready
# 221 VDR service closing transmission channel
# 225 Thank you
# 250 Requested VDR action okay, completed
# 354 Start sending lists data
# 451 Requested action aborted: local error in processing
# 500 Syntax error, command unrecognized
# 501 Syntax error in parameters or arguments
# 502 Command not implemented yet
# 504 Command parameter not implemented
# 550 Requested action not taken
# 554 Transaction failed
# 600 Authorize ok, access granted
# 601 Authorize fails, access denied
# 888 Compressed data of x bytes follow
# 900 Default plugin reply code
# 901..999 Plugin specific reply codes
// constable specific
# 602 Blocked
*/
};
//***************************************************************************
// Episode File
//***************************************************************************
class cEpisodeFile : public cListObject
{
public:
cEpisodeFile(std::string aName, std::string aLink, cList<cLine>* aLines = 0)
{ name = aName; link = aLink; lines = aLines; }
~cEpisodeFile() { if (lines) delete lines; }
int isLink() { return link.length() > 0; }
int storeToTable(cDbTable* episodeDb, const cList<cLine>* linkLines = 0);
int storeToFile(const char* aPath)
{
struct stat fs;
if (stat(aPath, &fs) != 0 || !S_ISDIR(fs.st_mode))
{
tell(0, "Initially creating directory '%s'", aPath);
if (mkdir(aPath, ACCESSPERMS) == -1)
tell(0, "Can't create directory, error was %s", strerror(errno));
}
if (isLink())
{
std::string ln = std::string(aPath) + "/" + std::string(link) + episodeFileExtension;
std::string file = std::string(name) + episodeFileExtension;
unlink(ln.c_str());
if (symlink(file.c_str(), ln.c_str()) != 0)
tell(0, "SERIES: Failed to create symlink '%s', error was '%s'",
ln.c_str(), strerror(errno));
}
else
{
std::string file = std::string(aPath) + "/" + std::string(name) + episodeFileExtension;
FILE* fp;
// open file for writing
if (!(fp = fopen(file.c_str(), "w+")))
{
tell(0, "SERIES: Store '%s' failed, '%s'", file.c_str(), strerror(errno));
return -1;
}
for (cLine* l = lines->First(); l; l = lines->Next(l))
{
fwrite(l->Text(), l->Length(), 1, fp);
fwrite("\n", 1, 1, fp);
}
fclose(fp);
}
return 0;
}
const cList<cLine>* getLines() { return lines; }
const char* getName() { return name.c_str(); }
const char* getLink() { return link.c_str(); }
protected:
std::string name;
std::string link;
cList<cLine>* lines;
};
//***************************************************************************
// cEpisodeFiles
//***************************************************************************
class cEpisodeFiles : public cList<cEpisodeFile>
{
public:
cEpisodeFile* findByLink(const char* aName)
{
for (cEpisodeFile* f = First(); f; f = Next(f))
{
if (!f->isLink() && strcmp(f->getName(), aName) == 0)
return f;
}
return 0;
}
int storeToFile(const char* aPath)
{
for (cEpisodeFile* f = First(); f; f = Next(f))
f->storeToFile(aPath);
return 0;
}
int storeToTable(cDbTable* episodeDb)
{
for (cEpisodeFile* f = First(); f; f = Next(f))
{
if (f->isLink())
{
if (cEpisodeFile* l = findByLink(f->getName()))
f->storeToTable(episodeDb, l->getLines());
else
tell(0, "Warning: Ignoring invalid link '%s' destination '%s' not found",
f->getLink(), f->getName());
}
else
{
f->storeToTable(episodeDb);
}
}
return 0;
}
};
//***************************************************************************
#endif // __SERIES_H_
|