Skip to content

Commit 314f95e

Browse files
committed
copied cPUTEHandler from vdr's svdrp.c
1 parent e7fa01f commit 314f95e

File tree

1 file changed

+63
-4
lines changed

1 file changed

+63
-4
lines changed

epg.c

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,69 @@ namespace cDBusEpgHelper
197197
}
198198
};
199199

200+
#if VDRVERSNUM > 20300
201+
// copied from svdrp.c, maybe it will be available in future versions?
202+
// --- cPUTEhandler ----------------------------------------------------------
203+
204+
class cPUTEhandler {
205+
private:
206+
FILE *f;
207+
int status;
208+
const char *message;
209+
public:
210+
cPUTEhandler(void);
211+
~cPUTEhandler();
212+
bool Process(const char *s);
213+
int Status(void) { return status; }
214+
const char *Message(void) { return message; }
215+
};
216+
217+
cPUTEhandler::cPUTEhandler(void)
218+
{
219+
if ((f = tmpfile()) != NULL) {
220+
status = 354;
221+
message = "Enter EPG data, end with \".\" on a line by itself";
222+
}
223+
else {
224+
LOG_ERROR;
225+
status = 554;
226+
message = "Error while opening temporary file";
227+
}
228+
}
229+
230+
cPUTEhandler::~cPUTEhandler()
231+
{
232+
if (f)
233+
fclose(f);
234+
}
235+
236+
bool cPUTEhandler::Process(const char *s)
237+
{
238+
if (f) {
239+
if (strcmp(s, ".") != 0) {
240+
fputs(s, f);
241+
fputc('\n', f);
242+
return true;
243+
}
244+
else {
245+
rewind(f);
246+
if (cSchedules::Read(f)) {
247+
cSchedules::Cleanup(true);
248+
status = 250;
249+
message = "EPG data processed";
250+
}
251+
else {
252+
status = 451;
253+
message = "Error while processing EPG data";
254+
}
255+
fclose(f);
256+
f = NULL;
257+
}
258+
}
259+
return false;
260+
}
261+
#endif
262+
200263
static void PutEntry(cDBusObject *Object, GVariant *Parameters, GDBusMethodInvocation *Invocation)
201264
{
202265
gsize len = 0;
@@ -208,9 +271,6 @@ namespace cDBusEpgHelper
208271
return;
209272
}
210273

211-
#if VDRVERSNUM > 20300
212-
cDBusHelper::SendReply(Invocation, 554, "cPUTEHandler not available in vdr 2.3.1");
213-
#else
214274
cPUTEhandler *handler = new cPUTEhandler();
215275
if (handler->Status() == 354) {
216276
for (gsize i = 0; i < len; i++) {
@@ -225,7 +285,6 @@ namespace cDBusEpgHelper
225285
}
226286
cDBusHelper::SendReply(Invocation, handler->Status(), handler->Message());
227287
delete handler;
228-
#endif
229288
g_free(line);
230289
};
231290

0 commit comments

Comments
 (0)