vdr 2.7.8
svdrp.c
Go to the documentation of this file.
1/*
2 * svdrp.c: Simple Video Disk Recorder Protocol
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * The "Simple Video Disk Recorder Protocol" (SVDRP) was inspired
8 * by the "Simple Mail Transfer Protocol" (SMTP) and is fully ASCII
9 * text based. Therefore you can simply 'telnet' to your VDR port
10 * and interact with the Video Disk Recorder - or write a full featured
11 * graphical interface that sits on top of an SVDRP connection.
12 *
13 * $Id: svdrp.c 5.15 2026/01/14 10:19:11 kls Exp $
14 */
15
16#include "svdrp.h"
17#include <arpa/inet.h>
18#include <ctype.h>
19#include <errno.h>
20#include <fcntl.h>
21#include <ifaddrs.h>
22#include <netinet/in.h>
23#include <stdarg.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <sys/socket.h>
28#include <sys/time.h>
29#include <unistd.h>
30#include "channels.h"
31#include "config.h"
32#include "device.h"
33#include "eitscan.h"
34#include "keys.h"
35#include "menu.h"
36#include "plugin.h"
37#include "recording.h"
38#include "remote.h"
39#include "skins.h"
40#include "timers.h"
41#include "videodir.h"
42
43static bool DumpSVDRPDataTransfer = false;
44
45#define dbgsvdrp(a...) if (DumpSVDRPDataTransfer) fprintf(stderr, a)
46
47static int SVDRPTcpPort = 0;
48static int SVDRPUdpPort = 0;
49
51 sffNone = 0b00000000,
52 sffConn = 0b00000001,
53 sffPing = 0b00000010,
54 sffTimers = 0b00000100,
55 };
56
57// --- cIpAddress ------------------------------------------------------------
58
60private:
62 int port;
64public:
65 cIpAddress(void);
66 cIpAddress(const char *Address, int Port);
67 const char *Address(void) const { return address; }
68 int Port(void) const { return port; }
69 void Set(const char *Address, int Port);
70 void Set(const sockaddr *SockAddr);
71 const char *Connection(void) const { return connection; }
72 };
73
75{
76 Set(INADDR_ANY, 0);
77}
78
80{
82}
83
84void cIpAddress::Set(const char *Address, int Port)
85{
87 port = Port;
89}
90
91void cIpAddress::Set(const sockaddr *SockAddr)
92{
93 const sockaddr_in *Addr = (sockaddr_in *)SockAddr;
94 Set(inet_ntoa(Addr->sin_addr), ntohs(Addr->sin_port));
95}
96
97// --- cSocket ---------------------------------------------------------------
98
99#define MAXUDPBUF 1024
100
101class cSocket {
102private:
103 int port;
104 bool tcp;
105 int sock;
107public:
108 cSocket(int Port, bool Tcp);
109 ~cSocket();
110 bool Listen(void);
111 bool Connect(const char *Address);
112 void Close(void);
113 int Port(void) const { return port; }
114 int Socket(void) const { return sock; }
115 static bool SendDgram(const char *Dgram, int Port);
116 int Accept(void);
117 cString Discover(void);
118 const cIpAddress *LastIpAddress(void) const { return &lastIpAddress; }
119 };
120
121cSocket::cSocket(int Port, bool Tcp)
122{
123 port = Port;
124 tcp = Tcp;
125 sock = -1;
126}
127
129{
130 Close();
131}
132
134{
135 if (sock >= 0) {
136 close(sock);
137 sock = -1;
138 }
139}
140
142{
143 if (sock < 0) {
144 isyslog("SVDRP %s opening port %d/%s", Setup.SVDRPHostName, port, tcp ? "tcp" : "udp");
145 // create socket:
146 sock = tcp ? socket(PF_INET, SOCK_STREAM, IPPROTO_IP) : socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
147 if (sock < 0) {
148 LOG_ERROR;
149 return false;
150 }
151 // allow it to always reuse the same port:
152 int ReUseAddr = 1;
153 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &ReUseAddr, sizeof(ReUseAddr));
154 // configure port and ip:
155 sockaddr_in Addr;
156 memset(&Addr, 0, sizeof(Addr));
157 Addr.sin_family = AF_INET;
158 Addr.sin_port = htons(port);
159 Addr.sin_addr.s_addr = SVDRPhosts.LocalhostOnly() ? htonl(INADDR_LOOPBACK) : htonl(INADDR_ANY);
160 if (bind(sock, (sockaddr *)&Addr, sizeof(Addr)) < 0) {
161 LOG_ERROR;
162 Close();
163 return false;
164 }
165 // make it non-blocking:
166 int Flags = fcntl(sock, F_GETFL, 0);
167 if (Flags < 0) {
168 LOG_ERROR;
169 return false;
170 }
171 Flags |= O_NONBLOCK;
172 if (fcntl(sock, F_SETFL, Flags) < 0) {
173 LOG_ERROR;
174 return false;
175 }
176 if (tcp) {
177 // listen to the socket:
178 if (listen(sock, 1) < 0) {
179 LOG_ERROR;
180 return false;
181 }
182 }
183 isyslog("SVDRP %s listening on port %d/%s", Setup.SVDRPHostName, port, tcp ? "tcp" : "udp");
184 }
185 return true;
186}
187
188bool cSocket::Connect(const char *Address)
189{
190 if (sock < 0 && tcp) {
191 // create socket:
192 sock = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
193 if (sock < 0) {
194 LOG_ERROR;
195 return false;
196 }
197 // configure port and ip:
198 sockaddr_in Addr;
199 memset(&Addr, 0, sizeof(Addr));
200 Addr.sin_family = AF_INET;
201 Addr.sin_port = htons(port);
202 Addr.sin_addr.s_addr = inet_addr(Address);
203 if (connect(sock, (sockaddr *)&Addr, sizeof(Addr)) < 0) {
204 LOG_ERROR;
205 Close();
206 return false;
207 }
208 // make it non-blocking:
209 int Flags = fcntl(sock, F_GETFL, 0);
210 if (Flags < 0) {
211 LOG_ERROR;
212 return false;
213 }
214 Flags |= O_NONBLOCK;
215 if (fcntl(sock, F_SETFL, Flags) < 0) {
216 LOG_ERROR;
217 return false;
218 }
219 dbgsvdrp("> %s:%d server connection established\n", Address, port);
220 isyslog("SVDRP %s > %s:%d server connection established", Setup.SVDRPHostName, Address, port);
221 return true;
222 }
223 return false;
224}
225
226bool cSocket::SendDgram(const char *Dgram, int Port)
227{
228 // Create a socket:
229 int Socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
230 if (Socket < 0) {
231 LOG_ERROR;
232 return false;
233 }
234 // Enable broadcast:
235 int One = 1;
236 if (setsockopt(Socket, SOL_SOCKET, SO_BROADCAST, &One, sizeof(One)) < 0) {
237 LOG_ERROR;
238 close(Socket);
239 return false;
240 }
241 // Configure port and ip:
242 sockaddr_in Addr;
243 memset(&Addr, 0, sizeof(Addr));
244 Addr.sin_family = AF_INET;
245 Addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
246 Addr.sin_port = htons(Port);
247 // Send datagram:
248 dbgsvdrp("> %s:%d %s\n", inet_ntoa(Addr.sin_addr), Port, Dgram);
249 int Length = strlen(Dgram);
250 int Sent = sendto(Socket, Dgram, Length, 0, (sockaddr *)&Addr, sizeof(Addr));
251 if (Sent < 0)
252 LOG_ERROR;
253 close(Socket);
254 return Sent == Length;
255}
256
258{
259 if (sock >= 0 && tcp) {
260 sockaddr_in Addr;
261 uint Size = sizeof(Addr);
262 int NewSock = accept(sock, (sockaddr *)&Addr, &Size);
263 if (NewSock >= 0) {
264 bool Accepted = SVDRPhosts.Acceptable(Addr.sin_addr.s_addr);
265 if (!Accepted) {
266 const char *s = "Access denied!\n";
267 if (write(NewSock, s, strlen(s)) < 0)
268 LOG_ERROR;
269 close(NewSock);
270 NewSock = -1;
271 }
272 lastIpAddress.Set((sockaddr *)&Addr);
273 dbgsvdrp("< %s client connection %s\n", lastIpAddress.Connection(), Accepted ? "accepted" : "DENIED");
274 isyslog("SVDRP %s < %s client connection %s", Setup.SVDRPHostName, lastIpAddress.Connection(), Accepted ? "accepted" : "DENIED");
275 }
276 else if (FATALERRNO)
277 LOG_ERROR;
278 return NewSock;
279 }
280 return -1;
281}
282
284{
285 if (sock >= 0 && !tcp) {
286 char buf[MAXUDPBUF];
287 sockaddr_in Addr;
288 uint Size = sizeof(Addr);
289 int NumBytes = recvfrom(sock, buf, sizeof(buf), 0, (sockaddr *)&Addr, &Size);
290 if (NumBytes >= 0) {
291 buf[NumBytes] = 0;
292 lastIpAddress.Set((sockaddr *)&Addr);
293 if (!SVDRPhosts.Acceptable(Addr.sin_addr.s_addr)) {
294 dsyslog("SVDRP %s < %s discovery ignored (%s)", Setup.SVDRPHostName, lastIpAddress.Connection(), buf);
295 return NULL;
296 }
297 if (!startswith(buf, "SVDRP:discover")) {
298 dsyslog("SVDRP %s < %s discovery unrecognized (%s)", Setup.SVDRPHostName, lastIpAddress.Connection(), buf);
299 return NULL;
300 }
301 if (strcmp(strgetval(buf, "name", ':'), Setup.SVDRPHostName) != 0) { // ignore our own broadcast
302 dbgsvdrp("< %s discovery received (%s)\n", lastIpAddress.Connection(), buf);
303 return buf;
304 }
305 }
306 else if (FATALERRNO)
307 LOG_ERROR;
308 }
309 return NULL;
310}
311
312// --- cSVDRPClient ----------------------------------------------------------
313
315private:
320 char *input;
326 bool Send(const char *Command);
327public:
328 cSVDRPClient(const char *Address, int Port, const char *ServerName, int Timeout);
330 void Close(void);
331 const char *ServerName(void) const { return serverName; }
332 const char *Connection(void) const { return serverIpAddress.Connection(); }
333 bool HasAddress(const char *Address, int Port) const;
334 bool Process(cStringList *Response = NULL);
335 bool Execute(const char *Command, cStringList *Response = NULL);
336 bool Connected(void) const { return connected; }
337 void SetFetchFlag(int Flag);
338 bool HasFetchFlag(int Flag);
339 bool GetRemoteTimers(cStringList &Response);
340 };
341
343
344cSVDRPClient::cSVDRPClient(const char *Address, int Port, const char *ServerName, int Timeout)
345:serverIpAddress(Address, Port)
346,socket(Port, true)
347{
349 length = BUFSIZ;
350 input = MALLOC(char, length);
351 timeout = Timeout * 1000 * 9 / 10; // ping after 90% of timeout
352 pingTime.Set(timeout);
354 connected = false;
355 if (socket.Connect(Address)) {
356 if (file.Open(socket.Socket())) {
357 SVDRPClientPoller.Add(file, false);
358 dsyslog("SVDRP %s > %s client created for '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName);
359 return;
360 }
361 }
362 esyslog("SVDRP %s > %s ERROR: failed to create client for '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName);
363}
364
366{
367 Close();
368 free(input);
369 dsyslog("SVDRP %s > %s client destroyed for '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName);
370}
371
373{
374 if (file.IsOpen()) {
375 SVDRPClientPoller.Del(file, false);
376 file.Close();
377 socket.Close();
378 }
379}
380
381bool cSVDRPClient::HasAddress(const char *Address, int Port) const
382{
383 return strcmp(serverIpAddress.Address(), Address) == 0 && serverIpAddress.Port() == Port;
384}
385
386bool cSVDRPClient::Send(const char *Command)
387{
388 pingTime.Set(timeout);
389 dbgsvdrp("> C %s: %s\n", *serverName, Command);
390 if (safe_write(file, Command, strlen(Command) + 1) < 0) {
391 LOG_ERROR;
392 return false;
393 }
394 return true;
395}
396
398{
399 if (file.IsOpen()) {
400 int numChars = 0;
401#define SVDRPResonseTimeout 5000 // ms
403 for (;;) {
404 if (file.Ready(false)) {
405 unsigned char c;
406 int r = safe_read(file, &c, 1);
407 if (r > 0) {
408 if (c == '\n' || c == 0x00) {
409 // strip trailing whitespace:
410 while (numChars > 0 && strchr(" \t\r\n", input[numChars - 1]))
411 input[--numChars] = 0;
412 // make sure the string is terminated:
413 input[numChars] = 0;
414 dbgsvdrp("< C %s: %s\n", *serverName, input);
415 if (Response)
416 Response->Append(strdup(input));
417 else {
418 switch (atoi(input)) {
419 case 220: if (numChars > 4) {
420 char *n = input + 4;
421 if (char *t = strchr(n, ' ')) {
422 *t = 0;
423 if (strcmp(n, serverName) != 0) {
424 serverName = n;
425 dsyslog("SVDRP %s < %s remote server name is '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName);
426 }
428 connected = true;
429 }
430 }
431 break;
432 case 221: dsyslog("SVDRP %s < %s remote server closed connection to '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName);
433 connected = false;
434 Close();
435 break;
436 }
437 }
438 if (numChars >= 4 && input[3] != '-') // no more lines will follow
439 break;
440 numChars = 0;
441 }
442 else {
443 if (numChars >= length - 1) {
444 int NewLength = length + BUFSIZ;
445 if (char *NewBuffer = (char *)realloc(input, NewLength)) {
446 length = NewLength;
447 input = NewBuffer;
448 }
449 else {
450 esyslog("SVDRP %s < %s ERROR: out of memory", Setup.SVDRPHostName, serverIpAddress.Connection());
451 Close();
452 break;
453 }
454 }
455 input[numChars++] = c;
456 input[numChars] = 0;
457 }
458 Timeout.Set(SVDRPResonseTimeout);
459 }
460 else if (r <= 0) {
461 isyslog("SVDRP %s < %s lost connection to remote server '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName);
462 Close();
463 return false;
464 }
465 }
466 else if (Timeout.TimedOut()) {
467 esyslog("SVDRP %s < %s timeout while waiting for response from '%s'", Setup.SVDRPHostName, serverIpAddress.Connection(), *serverName);
468 Close();
469 return false;
470 }
471 else if (!Response && numChars == 0)
472 break; // we read all or nothing!
473 }
474 if (pingTime.TimedOut())
476 }
477 return file.IsOpen();
478}
479
480bool cSVDRPClient::Execute(const char *Command, cStringList *Response)
481{
482 cStringList Dummy;
483 if (Response)
484 Response->Clear();
485 else
486 Response = &Dummy;
487 return Send(Command) && Process(Response);
488}
489
491{
492 fetchFlags |= Flags;
493}
494
496{
497 bool Result = (fetchFlags & Flag);
498 fetchFlags &= ~Flag;
499 return Result;
500}
501
503{
504 if (Execute("LSTT ID", &Response)) {
505 for (int i = 0; i < Response.Size(); i++) {
506 char *s = Response[i];
507 int Code = SVDRPCode(s);
508 if (Code == 250)
509 strshift(s, 4);
510 else if (Code == 550)
511 Response.Clear();
512 else {
513 esyslog("ERROR: %s: %s", ServerName(), s);
514 return false;
515 }
516 }
517 Response.SortNumerically();
518 return true;
519 }
520 return false;
521}
522
523// --- cSVDRPServerParams ----------------------------------------------------
524
526private:
528 int port;
534public:
535 cSVDRPServerParams(const char *Params);
536 const char *Name(void) const { return name; }
537 const int Port(void) const { return port; }
538 const char *VdrVersion(void) const { return vdrversion; }
539 const char *ApiVersion(void) const { return apiversion; }
540 const int Timeout(void) const { return timeout; }
541 const char *Host(void) const { return host; }
542 bool Ok(void) const { return !*error; }
543 const char *Error(void) const { return error; }
544 };
545
547{
548 if (Params && *Params) {
549 name = strgetval(Params, "name", ':');
550 if (*name) {
551 cString p = strgetval(Params, "port", ':');
552 if (*p) {
553 port = atoi(p);
554 vdrversion = strgetval(Params, "vdrversion", ':');
555 if (*vdrversion) {
556 apiversion = strgetval(Params, "apiversion", ':');
557 if (*apiversion) {
558 cString t = strgetval(Params, "timeout", ':');
559 if (*t) {
560 timeout = atoi(t);
561 if (timeout > 10) { // don't let it get too small
562 host = strgetval(Params, "host", ':');
563 // no error if missing - this parameter is optional!
564 }
565 else
566 error = "invalid timeout";
567 }
568 else
569 error = "missing server timeout";
570 }
571 else
572 error = "missing server apiversion";
573 }
574 else
575 error = "missing server vdrversion";
576 }
577 else
578 error = "missing server port";
579 }
580 else
581 error = "missing server name";
582 }
583 else
584 error = "missing server parameters";
585}
586
587// --- cSVDRPClientHandler ---------------------------------------------------
588
590
592private:
597 void SendDiscover(void);
598 void HandleClientConnection(void);
599 void ProcessConnections(void);
600 cSVDRPClient *GetClientForServer(const char *ServerName);
601protected:
602 virtual void Action(void) override;
603public:
604 cSVDRPClientHandler(int TcpPort, int UdpPort);
605 virtual ~cSVDRPClientHandler() override;
606 void AddClient(cSVDRPServerParams &ServerParams, const char *IpAddress);
607 void CloseClient(const char *ServerName);
608 bool Execute(const char *ServerName, const char *Command, cStringList *Response = NULL);
609 bool GetServerNames(cStringList *ServerNames);
610 bool TriggerFetchingTimers(const char *ServerName);
611 };
612
614
616:cThread("SVDRP client handler", true)
617,udpSocket(UdpPort, false)
618{
619 tcpPort = TcpPort;
620}
621
623{
624 Cancel(3);
625 for (int i = 0; i < clientConnections.Size(); i++)
626 delete clientConnections[i];
627}
628
630{
631 for (int i = 0; i < clientConnections.Size(); i++) {
632 if (strcmp(clientConnections[i]->ServerName(), ServerName) == 0)
633 return clientConnections[i];
634 }
635 return NULL;
636}
637
639{
640 cString Dgram = cString::sprintf("SVDRP:discover name:%s port:%d vdrversion:%d apiversion:%d timeout:%d%s", Setup.SVDRPHostName, tcpPort, VDRVERSNUM, APIVERSNUM, Setup.SVDRPTimeout, (Setup.SVDRPPeering == spmOnly && *Setup.SVDRPDefaultHost) ? *cString::sprintf(" host:%s", Setup.SVDRPDefaultHost) : "");
641 udpSocket.SendDgram(Dgram, udpSocket.Port());
642}
643
645{
646 cString PollTimersCmd;
648 PollTimersCmd = cString::sprintf("POLL %s TIMERS", Setup.SVDRPHostName);
650 }
651 else if (StateKeySVDRPRemoteTimersPoll.TimedOut())
652 return; // try again next time
653 for (int i = 0; i < clientConnections.Size(); i++) {
654 cSVDRPClient *Client = clientConnections[i];
655 if (Client->Process()) {
656 if (Client->HasFetchFlag(sffConn))
657 Client->Execute(cString::sprintf("CONN name:%s port:%d vdrversion:%d apiversion:%d timeout:%d", Setup.SVDRPHostName, SVDRPTcpPort, VDRVERSNUM, APIVERSNUM, Setup.SVDRPTimeout));
658 if (Client->HasFetchFlag(sffPing))
659 Client->Execute("PING");
660 if (Client->HasFetchFlag(sffTimers)) {
661 cStringList RemoteTimers;
662 if (Client->GetRemoteTimers(RemoteTimers)) {
664 bool TimersModified = Timers->StoreRemoteTimers(Client->ServerName(), &RemoteTimers);
665 StateKeySVDRPRemoteTimersPoll.Remove(TimersModified);
666 }
667 else
668 Client->SetFetchFlag(sffTimers); // try again next time
669 }
670 }
671 if (*PollTimersCmd) {
672 if (!Client->Execute(PollTimersCmd))
673 esyslog("ERROR: can't send '%s' to '%s'", *PollTimersCmd, Client->ServerName());
674 }
675 }
676 else {
678 bool TimersModified = Timers->StoreRemoteTimers(Client->ServerName(), NULL);
679 StateKeySVDRPRemoteTimersPoll.Remove(TimersModified);
680 delete Client;
681 clientConnections.Remove(i);
682 i--;
683 }
684 }
685}
686
687void cSVDRPClientHandler::AddClient(cSVDRPServerParams &ServerParams, const char *IpAddress)
688{
689 cMutexLock MutexLock(&mutex);
690 for (int i = 0; i < clientConnections.Size(); i++) {
691 if (clientConnections[i]->HasAddress(IpAddress, ServerParams.Port()))
692 return;
693 }
694 if (Setup.SVDRPPeering == spmOnly && strcmp(ServerParams.Name(), Setup.SVDRPDefaultHost) != 0)
695 return; // we only want to peer with the default host, but this isn't the default host
696 if (ServerParams.Host() && strcmp(ServerParams.Host(), Setup.SVDRPHostName) != 0)
697 return; // the remote VDR requests a specific host, but it's not us
698 clientConnections.Append(new cSVDRPClient(IpAddress, ServerParams.Port(), ServerParams.Name(), ServerParams.Timeout()));
699}
700
701void cSVDRPClientHandler::CloseClient(const char *ServerName)
702{
703 cMutexLock MutexLock(&mutex);
704 for (int i = 0; i < clientConnections.Size(); i++) {
705 if (strcmp(clientConnections[i]->ServerName(), ServerName) == 0) {
706 clientConnections[i]->Close();
707 break;
708 }
709 }
710}
711
713{
714 cString NewDiscover = udpSocket.Discover();
715 if (*NewDiscover) {
716 cSVDRPServerParams ServerParams(NewDiscover);
717 if (ServerParams.Ok())
718 AddClient(ServerParams, udpSocket.LastIpAddress()->Address());
719 else
720 esyslog("SVDRP %s < %s ERROR: %s", Setup.SVDRPHostName, udpSocket.LastIpAddress()->Connection(), ServerParams.Error());
721 }
722}
723
725{
726 if (udpSocket.Listen()) {
727 SVDRPClientPoller.Add(udpSocket.Socket(), false);
728 time_t LastDiscover = 0;
729#define SVDRPDiscoverDelta 60 // seconds
730 while (Running()) {
731 time_t Now = time(NULL);
732 if (Now - LastDiscover >= SVDRPDiscoverDelta) {
733 SendDiscover();
734 LastDiscover = Now;
735 }
736 SVDRPClientPoller.Poll(1000);
737 cMutexLock MutexLock(&mutex);
740 }
741 SVDRPClientPoller.Del(udpSocket.Socket(), false);
742 udpSocket.Close();
743 }
744}
745
746bool cSVDRPClientHandler::Execute(const char *ServerName, const char *Command, cStringList *Response)
747{
748 cMutexLock MutexLock(&mutex);
749 if (cSVDRPClient *Client = GetClientForServer(ServerName))
750 return Client->Execute(Command, Response);
751 return false;
752}
753
755{
756 cMutexLock MutexLock(&mutex);
757 ServerNames->Clear();
758 for (int i = 0; i < clientConnections.Size(); i++) {
759 cSVDRPClient *Client = clientConnections[i];
760 if (Client->Connected())
761 ServerNames->Append(strdup(Client->ServerName()));
762 }
763 return ServerNames->Size() > 0;
764}
765
767{
768 cMutexLock MutexLock(&mutex);
769 if (cSVDRPClient *Client = GetClientForServer(ServerName)) {
770 Client->SetFetchFlag(sffTimers);
771 return true;
772 }
773 return false;
774}
775
776// --- cPUTEhandler ----------------------------------------------------------
777
779private:
780 FILE *f;
782 const char *message;
783public:
784 cPUTEhandler(void);
786 bool Process(const char *s);
787 int Status(void) { return status; }
788 const char *Message(void) { return message; }
789 };
790
792{
793 if ((f = tmpfile()) != NULL) {
794 status = 354;
795 message = "Enter EPG data, end with \".\" on a line by itself";
796 }
797 else {
798 LOG_ERROR;
799 status = 554;
800 message = "Error while opening temporary file";
801 }
802}
803
805{
806 if (f)
807 fclose(f);
808}
809
810bool cPUTEhandler::Process(const char *s)
811{
812 if (f) {
813 if (strcmp(s, ".") != 0) {
814 fputs(s, f);
815 fputc('\n', f);
816 return true;
817 }
818 else {
819 rewind(f);
820 if (cSchedules::Read(f)) {
822 status = 250;
823 message = "EPG data processed";
824 }
825 else {
826 status = 451;
827 message = "Error while processing EPG data";
828 }
829 fclose(f);
830 f = NULL;
831 }
832 }
833 return false;
834}
835
836// --- cSVDRPServer ----------------------------------------------------------
837
838#define MAXHELPTOPIC 10
839#define EITDISABLETIME 10 // seconds until EIT processing is enabled again after a CLRE command
840 // adjust the help for CLRE accordingly if changing this!
841
842const char *HelpPages[] = {
843 "AUDI [ <number> ]\n"
844 " Lists the currently available audio tracks in the format 'number language description'.\n"
845 " The number indicates the track type (1..32 = MP2, 33..48 = Dolby).\n"
846 " The currently selected track has its description prefixed with '*'.\n"
847 " If a number is given (which must be one of the track numbers listed)\n"
848 " audio is switched to that track.\n"
849 " Note that the list may not be fully available or current immediately after\n"
850 " switching the channel or starting a replay.",
851 "CHAN [ + | - | <number> | <name> | <id> ]\n"
852 " Switch channel up, down or to the given channel number, name or id.\n"
853 " Without option (or after successfully switching to the channel)\n"
854 " it returns the current channel number and name.",
855 "CLRE [ <number> | <name> | <id> ]\n"
856 " Clear the EPG list of the given channel number, name or id.\n"
857 " Without option it clears the entire EPG list.\n"
858 " After a CLRE command, no further EPG processing is done for 10\n"
859 " seconds, so that data sent with subsequent PUTE commands doesn't\n"
860 " interfere with data from the broadcasters.",
861 "CONN name:<name> port:<port> vdrversion:<vdrversion> apiversion:<apiversion> timeout:<timeout>\n"
862 " Used by peer-to-peer connections between VDRs to tell the other VDR\n"
863 " to establish a connection to this VDR. The name is the SVDRP host name\n"
864 " of this VDR, which may differ from its DNS name.",
865 "CPYR <number> <new name>\n"
866 " Copy the recording with the given number. Before a recording can be\n"
867 " copied, an LSTR command must have been executed in order to retrieve\n"
868 " the recording numbers.\n",
869 "DELC <number> | <id>\n"
870 " Delete the channel with the given number or channel id.",
871 "DELR <id>\n"
872 " Delete the recording with the given id. Before a recording can be\n"
873 " deleted, an LSTR command should have been executed in order to retrieve\n"
874 " the recording ids. The ids are unique and don't change while this\n"
875 " instance of VDR is running.\n"
876 " CAUTION: THERE IS NO CONFIRMATION PROMPT WHEN DELETING A\n"
877 " RECORDING - BE SURE YOU KNOW WHAT YOU ARE DOING!",
878 "DELT <id>\n"
879 " Delete the timer with the given id. If this timer is currently recording,\n"
880 " the recording will be stopped without any warning.",
881 "EDIT <id>\n"
882 " Edit the recording with the given id. Before a recording can be\n"
883 " edited, an LSTR command should have been executed in order to retrieve\n"
884 " the recording ids.",
885 "GRAB <filename> [ <quality> [ <sizex> <sizey> ] ]\n"
886 " Grab the current frame and save it to the given file. Images can\n"
887 " be stored as JPEG or PNM, depending on the given file name extension.\n"
888 " The quality of the grabbed image can be in the range 0..100, where 100\n"
889 " (the default) means \"best\" (only applies to JPEG). The size parameters\n"
890 " define the size of the resulting image (default is full screen).\n"
891 " If the file name is just an extension (.jpg, .jpeg or .pnm) the image\n"
892 " data will be sent to the SVDRP connection encoded in base64. The same\n"
893 " happens if '-' (a minus sign) is given as file name, in which case the\n"
894 " image format defaults to JPEG.",
895 "HELP [ <topic> ]\n"
896 " The HELP command gives help info.",
897 "HITK [ <key> ... ]\n"
898 " Hit the given remote control key. Without option a list of all\n"
899 " valid key names is given. If more than one key is given, they are\n"
900 " entered into the remote control queue in the given sequence. There\n"
901 " can be up to 31 keys.",
902 "LSTC [ :ids ] [ :groups | <number> | <name> | <id> ]\n"
903 " List channels. Without option, all channels are listed. Otherwise\n"
904 " only the given channel is listed. If a name is given, all channels\n"
905 " containing the given string as part of their name are listed.\n"
906 " If ':groups' is given, all channels are listed including group\n"
907 " separators. The channel number of a group separator is always 0.\n"
908 " With ':ids' the channel ids are listed following the channel numbers.\n"
909 " The special number 0 can be given to list the current channel.",
910 "LSTD\n"
911 " List all available devices. Each device is listed with its name and\n"
912 " whether it is currently the primary device ('P') or it implements a\n"
913 " decoder ('D') and can be used as output device.",
914 "LSTE [ <channel> ] [ now | next | at <time> ]\n"
915 " List EPG data. Without any parameters all data of all channels is\n"
916 " listed. If a channel is given (either by number or by channel ID),\n"
917 " only data for that channel is listed. 'now', 'next', or 'at <time>'\n"
918 " restricts the returned data to present events, following events, or\n"
919 " events at the given time (which must be in time_t form).",
920 "LSTR [ <id> [ path ] ]\n"
921 " List recordings. Without option, all recordings are listed. Otherwise\n"
922 " the information for the given recording is listed. If a recording\n"
923 " id and the keyword 'path' is given, the actual file name of that\n"
924 " recording's directory is listed.\n"
925 " Note that the ids of the recordings are not necessarily given in\n"
926 " numeric order.",
927 "LSTT [ <id> ] [ id ]\n"
928 " List timers. Without option, all timers are listed. Otherwise\n"
929 " only the timer with the given id is listed. If the keyword 'id' is\n"
930 " given, the channels will be listed with their unique channel ids\n"
931 " instead of their numbers. This command lists only the timers that are\n"
932 " defined locally on this VDR, not any remote timers from other VDRs.",
933 "MESG <message>\n"
934 " Displays the given message on the OSD. The message will be queued\n"
935 " and displayed whenever this is suitable.\n",
936 "MODC <number> <settings>\n"
937 " Modify a channel. Settings must be in the same format as returned\n"
938 " by the LSTC command.",
939 "MODT <id> on | off | <settings>\n"
940 " Modify a timer. Settings must be in the same format as returned\n"
941 " by the LSTT command. The special keywords 'on' and 'off' can be\n"
942 " used to easily activate or deactivate a timer.",
943 "MOVC <number> <to>\n"
944 " Move a channel to a new position.",
945 "MOVR <id> <new name>\n"
946 " Move the recording with the given id. Before a recording can be\n"
947 " moved, an LSTR command should have been executed in order to retrieve\n"
948 " the recording ids. The ids don't change during subsequent MOVR\n"
949 " commands.\n",
950 "NEWC <settings>\n"
951 " Create a new channel. Settings must be in the same format as returned\n"
952 " by the LSTC command.",
953 "NEWT <settings>\n"
954 " Create a new timer. Settings must be in the same format as returned\n"
955 " by the LSTT command. If a timer with the same channel, day, start\n"
956 " and stop time already exists, the data of the existing timer is returned\n"
957 " with code 550.",
958 "NEXT [ abs | rel ]\n"
959 " Show the next timer event. If no option is given, the output will be\n"
960 " in human readable form. With option 'abs' the absolute time of the next\n"
961 " event will be given as the number of seconds since the epoch (time_t\n"
962 " format), while with option 'rel' the relative time will be given as the\n"
963 " number of seconds from now until the event. If the absolute time given\n"
964 " is smaller than the current time, or if the relative time is less than\n"
965 " zero, this means that the timer is currently recording and has started\n"
966 " at the given time. The first value in the resulting line is the id\n"
967 " of the timer.",
968 "PING\n"
969 " Used by peer-to-peer connections between VDRs to keep the connection\n"
970 " from timing out. May be used at any time and simply returns a line of\n"
971 " the form '<hostname> is alive'.",
972 "PLAY [ <id> [ begin | <position> ] ]\n"
973 " Play the recording with the given id. Before a recording can be\n"
974 " played, an LSTR command should have been executed in order to retrieve\n"
975 " the recording ids.\n"
976 " The keyword 'begin' plays the recording from its very beginning, while\n"
977 " a <position> (given as hh:mm:ss[.ff] or framenumber) starts at that\n"
978 " position. If neither 'begin' nor a <position> are given, replay is resumed\n"
979 " at the position where any previous replay was stopped, or from the beginning\n"
980 " by default. To control or stop the replay session, use the usual remote\n"
981 " control keypresses via the HITK command.\n"
982 " Without any parameters PLAY returns the id and title of the recording that\n"
983 " is currently being played (if any).",
984 "PLUG <name> [ help | main ] [ <command> [ <options> ]]\n"
985 " Send a command to a plugin.\n"
986 " The PLUG command without any parameters lists all plugins.\n"
987 " If only a name is given, all commands known to that plugin are listed.\n"
988 " If a command is given (optionally followed by parameters), that command\n"
989 " is sent to the plugin, and the result will be displayed.\n"
990 " The keyword 'help' lists all the SVDRP commands known to the named plugin.\n"
991 " If 'help' is followed by a command, the detailed help for that command is\n"
992 " given. The keyword 'main' initiates a call to the main menu function of the\n"
993 " given plugin.\n",
994 "POLL <name> timers\n"
995 " Used by peer-to-peer connections between VDRs to inform other machines\n"
996 " about changes to timers. The receiving VDR shall use LSTT to query the\n"
997 " remote machine with the given name about its timers and update its list\n"
998 " of timers accordingly.\n",
999 "PRIM [ <number> ]\n"
1000 " Make the device with the given number the primary device.\n"
1001 " Without option it returns the currently active primary device in the same\n"
1002 " format as used by the LSTD command.",
1003 "PUTE [ <file> ]\n"
1004 " Put data into the EPG list. The data entered has to strictly follow the\n"
1005 " format defined in vdr(5) for the 'epg.data' file. A '.' on a line\n"
1006 " by itself terminates the input and starts processing of the data (all\n"
1007 " entered data is buffered until the terminating '.' is seen).\n"
1008 " If a file name is given, epg data will be read from this file (which\n"
1009 " must be accessible under the given name from the machine VDR is running\n"
1010 " on). In case of file input, no terminating '.' shall be given.\n",
1011 "REMO [ on | off ]\n"
1012 " Turns the remote control on or off. Without a parameter, the current\n"
1013 " status of the remote control is reported.",
1014 "SCAN\n"
1015 " Forces an EPG scan. If this is a single DVB device system, the scan\n"
1016 " will be done on the primary device unless it is currently recording.",
1017 "STAT disk\n"
1018 " Return information about disk usage (total, free, percent).",
1019 "UPDT <settings>\n"
1020 " Updates a timer. Settings must be in the same format as returned\n"
1021 " by the LSTT command. If a timer with the same channel, day, start\n"
1022 " and stop time does not yet exist, it will be created.",
1023 "UPDR\n"
1024 " Initiates a re-read of the recordings directory, which is the SVDRP\n"
1025 " equivalent to 'touch .update'.",
1026 "VOLU [ <number> | + | - | mute ]\n"
1027 " Set the audio volume to the given number (which is limited to the range\n"
1028 " 0...255). If the special options '+' or '-' are given, the volume will\n"
1029 " be turned up or down, respectively. The option 'mute' will toggle the\n"
1030 " audio muting. If no option is given, the current audio volume level will\n"
1031 " be returned.",
1032 "QUIT\n"
1033 " Exit vdr (SVDRP).\n"
1034 " You can also hit Ctrl-D to exit.",
1035 NULL
1036 };
1037
1038/* SVDRP Reply Codes:
1039
1040 214 Help message
1041 215 EPG or recording data record
1042 216 Image grab data (base 64)
1043 220 VDR service ready
1044 221 VDR service closing transmission channel
1045 250 Requested VDR action okay, completed
1046 354 Start sending EPG data
1047 451 Requested action aborted: local error in processing
1048 500 Syntax error, command unrecognized
1049 501 Syntax error in parameters or arguments
1050 502 Command not implemented
1051 504 Command parameter not implemented
1052 550 Requested action not taken
1053 554 Transaction failed
1054 900 Default plugin reply code
1055 901..999 Plugin specific reply codes
1056
1057*/
1058
1059const char *GetHelpTopic(const char *HelpPage)
1060{
1061 static char topic[MAXHELPTOPIC];
1062 const char *q = HelpPage;
1063 while (*q) {
1064 if (isspace(*q)) {
1065 uint n = q - HelpPage;
1066 if (n >= sizeof(topic))
1067 n = sizeof(topic) - 1;
1068 strncpy(topic, HelpPage, n);
1069 topic[n] = 0;
1070 return topic;
1071 }
1072 q++;
1073 }
1074 return NULL;
1075}
1076
1077const char *GetHelpPage(const char *Cmd, const char **p)
1078{
1079 if (p) {
1080 while (*p) {
1081 const char *t = GetHelpTopic(*p);
1082 if (strcasecmp(Cmd, t) == 0)
1083 return *p;
1084 p++;
1085 }
1086 }
1087 return NULL;
1088}
1089
1091
1093private:
1101 char *cmdLine;
1103 void Close(bool SendReply = false, bool Timeout = false);
1104 bool Send(const char *s);
1105 void Reply(int Code, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
1106 void PrintHelpTopics(const char **hp);
1107 void CmdAUDI(const char *Option);
1108 void CmdCHAN(const char *Option);
1109 void CmdCLRE(const char *Option);
1110 void CmdCONN(const char *Option);
1111 void CmdCPYR(const char *Option);
1112 void CmdDELC(const char *Option);
1113 void CmdDELR(const char *Option);
1114 void CmdDELT(const char *Option);
1115 void CmdEDIT(const char *Option);
1116 void CmdGRAB(const char *Option);
1117 void CmdHELP(const char *Option);
1118 void CmdHITK(const char *Option);
1119 void CmdLSTC(const char *Option);
1120 void CmdLSTD(const char *Option);
1121 void CmdLSTE(const char *Option);
1122 void CmdLSTR(const char *Option);
1123 void CmdLSTT(const char *Option);
1124 void CmdMESG(const char *Option);
1125 void CmdMODC(const char *Option);
1126 void CmdMODT(const char *Option);
1127 void CmdMOVC(const char *Option);
1128 void CmdMOVR(const char *Option);
1129 void CmdNEWC(const char *Option);
1130 void CmdNEWT(const char *Option);
1131 void CmdNEXT(const char *Option);
1132 void CmdPING(const char *Option);
1133 void CmdPLAY(const char *Option);
1134 void CmdPLUG(const char *Option);
1135 void CmdPOLL(const char *Option);
1136 void CmdPRIM(const char *Option);
1137 void CmdPUTE(const char *Option);
1138 void CmdREMO(const char *Option);
1139 void CmdSCAN(const char *Option);
1140 void CmdSTAT(const char *Option);
1141 void CmdUPDT(const char *Option);
1142 void CmdUPDR(const char *Option);
1143 void CmdVOLU(const char *Option);
1144 void Execute(char *Cmd);
1145public:
1146 cSVDRPServer(int Socket, const cIpAddress *ClientIpAddress);
1147 ~cSVDRPServer();
1148 const char *ClientName(void) const { return clientName; }
1149 bool HasConnection(void) { return file.IsOpen(); }
1150 bool Process(void);
1151 };
1152
1154
1155cSVDRPServer::cSVDRPServer(int Socket, const cIpAddress *ClientIpAddress)
1156{
1157 socket = Socket;
1158 clientIpAddress = *ClientIpAddress;
1159 clientName = clientIpAddress.Connection(); // will be set to actual name by a CONN command
1160 PUTEhandler = NULL;
1161 numChars = 0;
1162 length = BUFSIZ;
1163 cmdLine = MALLOC(char, length);
1164 lastActivity = time(NULL);
1165 if (file.Open(socket)) {
1166 time_t now = time(NULL);
1167 Reply(220, "%s SVDRP VideoDiskRecorder %s; %s; %s", Setup.SVDRPHostName, VDRVERSION, *TimeToString(now), cCharSetConv::SystemCharacterTable() ? cCharSetConv::SystemCharacterTable() : "UTF-8");
1168 SVDRPServerPoller.Add(file, false);
1169 }
1170 dsyslog("SVDRP %s > %s server created", Setup.SVDRPHostName, *clientName);
1171}
1172
1174{
1175 Close(true);
1176 free(cmdLine);
1177 dsyslog("SVDRP %s < %s server destroyed", Setup.SVDRPHostName, *clientName);
1178}
1179
1180void cSVDRPServer::Close(bool SendReply, bool Timeout)
1181{
1182 if (file.IsOpen()) {
1183 if (SendReply) {
1184 Reply(221, "%s closing connection%s", Setup.SVDRPHostName, Timeout ? " (timeout)" : "");
1185 }
1186 isyslog("SVDRP %s < %s connection closed", Setup.SVDRPHostName, *clientName);
1187 SVDRPServerPoller.Del(file, false);
1188 file.Close();
1190 }
1191 close(socket);
1192}
1193
1194bool cSVDRPServer::Send(const char *s)
1195{
1196 dbgsvdrp("> S %s: %s", *clientName, s); // terminating newline is already in the string!
1197 if (safe_write(file, s, strlen(s)) < 0) {
1198 LOG_ERROR;
1199 Close();
1200 return false;
1201 }
1202 return true;
1203}
1204
1205void cSVDRPServer::Reply(int Code, const char *fmt, ...)
1206{
1207 if (file.IsOpen()) {
1208 if (Code != 0) {
1209 char *buffer = NULL;
1210 va_list ap;
1211 va_start(ap, fmt);
1212 if (vasprintf(&buffer, fmt, ap) >= 0) {
1213 char *s = buffer;
1214 while (s && *s) {
1215 char *n = strchr(s, '\n');
1216 if (n)
1217 *n = 0;
1218 char cont = ' ';
1219 if (Code < 0 || n && *(n + 1)) // trailing newlines don't count!
1220 cont = '-';
1221 if (!Send(cString::sprintf("%03d%c%s\r\n", abs(Code), cont, s)))
1222 break;
1223 s = n ? n + 1 : NULL;
1224 }
1225 }
1226 else {
1227 Reply(451, "Bad format - looks like a programming error!");
1228 esyslog("SVDRP %s < %s bad format!", Setup.SVDRPHostName, *clientName);
1229 }
1230 va_end(ap);
1231 free(buffer);
1232 }
1233 else {
1234 Reply(451, "Zero return code - looks like a programming error!");
1235 esyslog("SVDRP %s < %s zero return code!", Setup.SVDRPHostName, *clientName);
1236 }
1237 }
1238}
1239
1241{
1242 int NumPages = 0;
1243 if (hp) {
1244 while (*hp) {
1245 NumPages++;
1246 hp++;
1247 }
1248 hp -= NumPages;
1249 }
1250 const int TopicsPerLine = 5;
1251 int x = 0;
1252 for (int y = 0; (y * TopicsPerLine + x) < NumPages; y++) {
1253 char buffer[TopicsPerLine * MAXHELPTOPIC + 5];
1254 char *q = buffer;
1255 q += sprintf(q, " ");
1256 for (x = 0; x < TopicsPerLine && (y * TopicsPerLine + x) < NumPages; x++) {
1257 const char *topic = GetHelpTopic(hp[(y * TopicsPerLine + x)]);
1258 if (topic)
1259 q += sprintf(q, "%*s", -MAXHELPTOPIC, topic);
1260 }
1261 x = 0;
1262 Reply(-214, "%s", buffer);
1263 }
1264}
1265
1266void cSVDRPServer::CmdAUDI(const char *Option)
1267{
1268 if (*Option) {
1269 if (isnumber(Option)) {
1270 int o = strtol(Option, NULL, 10);
1271 if (o >= ttAudioFirst && o <= ttDolbyLast) {
1272 const tTrackId *TrackId = cDevice::PrimaryDevice()->GetTrack(eTrackType(o));
1273 if (TrackId && TrackId->id) {
1275 Reply(250, "%d %s %s", eTrackType(o), *TrackId->language ? TrackId->language : "---", *TrackId->description ? TrackId->description : "-");
1276 }
1277 else
1278 Reply(501, "Audio track \"%s\" not available", Option);
1279 }
1280 else
1281 Reply(501, "Invalid audio track \"%s\"", Option);
1282 }
1283 else
1284 Reply(501, "Error in audio track \"%s\"", Option);
1285 }
1286 else {
1289 cString s;
1290 for (int i = ttAudioFirst; i <= ttDolbyLast; i++) {
1291 const tTrackId *TrackId = cDevice::PrimaryDevice()->GetTrack(eTrackType(i));
1292 if (TrackId && TrackId->id) {
1293 if (*s)
1294 Reply(-250, "%s", *s);
1295 s = cString::sprintf("%d %s %s%s", eTrackType(i), *TrackId->language ? TrackId->language : "---", i == CurrentAudioTrack ? "*" : "", *TrackId->description ? TrackId->description : "-");
1296 }
1297 }
1298 if (*s)
1299 Reply(250, "%s", *s);
1300 else
1301 Reply(550, "No audio tracks available");
1302 }
1303}
1304
1305void cSVDRPServer::CmdCHAN(const char *Option)
1306{
1308 if (*Option) {
1309 int n = -1;
1310 int d = 0;
1311 if (isnumber(Option)) {
1312 int o = strtol(Option, NULL, 10);
1313 if (o >= 1 && o <= cChannels::MaxNumber())
1314 n = o;
1315 }
1316 else if (strcmp(Option, "-") == 0) {
1318 if (n > 1) {
1319 n--;
1320 d = -1;
1321 }
1322 }
1323 else if (strcmp(Option, "+") == 0) {
1325 if (n < cChannels::MaxNumber()) {
1326 n++;
1327 d = 1;
1328 }
1329 }
1330 else if (const cChannel *Channel = Channels->GetByChannelID(tChannelID::FromString(Option)))
1331 n = Channel->Number();
1332 else {
1333 for (const cChannel *Channel = Channels->First(); Channel; Channel = Channels->Next(Channel)) {
1334 if (!Channel->GroupSep()) {
1335 if (strcasecmp(Channel->Name(), Option) == 0) {
1336 n = Channel->Number();
1337 break;
1338 }
1339 }
1340 }
1341 }
1342 if (n < 0) {
1343 Reply(501, "Undefined channel \"%s\"", Option);
1344 return;
1345 }
1346 if (!d) {
1347 if (const cChannel *Channel = Channels->GetByNumber(n)) {
1348 if (!cDevice::PrimaryDevice()->SwitchChannel(Channel, true)) {
1349 Reply(554, "Error switching to channel \"%d\"", Channel->Number());
1350 return;
1351 }
1352 }
1353 else {
1354 Reply(550, "Unable to find channel \"%s\"", Option);
1355 return;
1356 }
1357 }
1358 else
1360 }
1361 if (const cChannel *Channel = Channels->GetByNumber(cDevice::CurrentChannel()))
1362 Reply(250, "%d %s", Channel->Number(), Channel->Name());
1363 else
1364 Reply(550, "Unable to find channel \"%d\"", cDevice::CurrentChannel());
1365}
1366
1367void cSVDRPServer::CmdCLRE(const char *Option)
1368{
1369 if (*Option) {
1373 if (isnumber(Option)) {
1374 int o = strtol(Option, NULL, 10);
1375 if (o >= 1 && o <= cChannels::MaxNumber()) {
1376 if (const cChannel *Channel = Channels->GetByNumber(o))
1377 ChannelID = Channel->GetChannelID();
1378 }
1379 }
1380 else {
1381 ChannelID = tChannelID::FromString(Option);
1382 if (ChannelID == tChannelID::InvalidID) {
1383 for (const cChannel *Channel = Channels->First(); Channel; Channel = Channels->Next(Channel)) {
1384 if (!Channel->GroupSep()) {
1385 if (strcasecmp(Channel->Name(), Option) == 0) {
1386 ChannelID = Channel->GetChannelID();
1387 break;
1388 }
1389 }
1390 }
1391 }
1392 }
1393 if (!(ChannelID == tChannelID::InvalidID)) {
1395 cSchedule *Schedule = NULL;
1396 ChannelID.ClrRid();
1397 for (cSchedule *p = Schedules->First(); p; p = Schedules->Next(p)) {
1398 if (p->ChannelID() == ChannelID) {
1399 Schedule = p;
1400 break;
1401 }
1402 }
1403 if (Schedule) {
1404 for (cTimer *Timer = Timers->First(); Timer; Timer = Timers->Next(Timer)) {
1405 if (ChannelID == Timer->Channel()->GetChannelID().ClrRid())
1406 Timer->SetEvent(NULL);
1407 }
1408 Schedule->Cleanup(INT_MAX);
1410 Reply(250, "EPG data of channel \"%s\" cleared", Option);
1411 }
1412 else {
1413 Reply(550, "No EPG data found for channel \"%s\"", Option);
1414 return;
1415 }
1416 }
1417 else
1418 Reply(501, "Undefined channel \"%s\"", Option);
1419 }
1420 else {
1423 for (cTimer *Timer = Timers->First(); Timer; Timer = Timers->Next(Timer))
1424 Timer->SetEvent(NULL); // processing all timers here (local *and* remote)
1425 for (cSchedule *Schedule = Schedules->First(); Schedule; Schedule = Schedules->Next(Schedule))
1426 Schedule->Cleanup(INT_MAX);
1428 Reply(250, "EPG data cleared");
1429 }
1430}
1431
1432void cSVDRPServer::CmdCONN(const char *Option)
1433{
1434 if (*Option) {
1435 if (SVDRPClientHandler) {
1436 cSVDRPServerParams ServerParams(Option);
1437 if (ServerParams.Ok()) {
1438 clientName = ServerParams.Name();
1439 Reply(250, "OK"); // must finish this transaction before creating the new client
1440 SVDRPClientHandler->AddClient(ServerParams, clientIpAddress.Address());
1441 }
1442 else
1443 Reply(501, "Error in server parameters: %s", ServerParams.Error());
1444 }
1445 else
1446 Reply(451, "No SVDRP client handler");
1447 }
1448 else
1449 Reply(501, "Missing server parameters");
1450}
1451
1452void cSVDRPServer::CmdDELC(const char *Option)
1453{
1454 if (*Option) {
1457 Channels->SetExplicitModify();
1458 cChannel *Channel = NULL;
1459 if (isnumber(Option))
1460 Channel = Channels->GetByNumber(strtol(Option, NULL, 10));
1461 else
1462 Channel = Channels->GetByChannelID(tChannelID::FromString(Option));
1463 if (Channel) {
1464 if (const cTimer *Timer = Timers->UsesChannel(Channel)) {
1465 Reply(550, "Channel \"%s\" is in use by timer %s", Option, *Timer->ToDescr());
1466 return;
1467 }
1468 int CurrentChannelNr = cDevice::CurrentChannel();
1469 cChannel *CurrentChannel = Channels->GetByNumber(CurrentChannelNr);
1470 if (CurrentChannel && Channel == CurrentChannel) {
1471 int n = Channels->GetNextNormal(CurrentChannel->Index());
1472 if (n < 0)
1473 n = Channels->GetPrevNormal(CurrentChannel->Index());
1474 if (n < 0) {
1475 Reply(501, "Can't delete channel \"%s\" - list would be empty", Option);
1476 return;
1477 }
1478 CurrentChannel = Channels->Get(n);
1479 CurrentChannelNr = 0; // triggers channel switch below
1480 }
1481 Channels->Del(Channel);
1482 Channels->ReNumber();
1483 Channels->SetModifiedByUser();
1484 Channels->SetModified();
1485 isyslog("SVDRP %s < %s deleted channel %s", Setup.SVDRPHostName, *clientName, Option);
1486 if (CurrentChannel && CurrentChannel->Number() != CurrentChannelNr) {
1487 if (!cDevice::PrimaryDevice()->Replaying() || cDevice::PrimaryDevice()->Transferring())
1488 Channels->SwitchTo(CurrentChannel->Number());
1489 else
1490 cDevice::SetCurrentChannel(CurrentChannel->Number());
1491 }
1492 Reply(250, "Channel \"%s\" deleted", Option);
1493 }
1494 else
1495 Reply(501, "Channel \"%s\" not defined", Option);
1496 }
1497 else
1498 Reply(501, "Missing channel number or id");
1499}
1500
1501static cString RecordingInUseMessage(int Reason, const char *RecordingId, cRecording *Recording)
1502{
1503 cRecordControl *rc;
1504 if ((Reason & ruTimer) != 0 && (rc = cRecordControls::GetRecordControl(Recording->FileName())) != NULL)
1505 return cString::sprintf("Recording \"%s\" is in use by timer %d", RecordingId, rc->Timer()->Id());
1506 else if ((Reason & ruReplay) != 0)
1507 return cString::sprintf("Recording \"%s\" is being replayed", RecordingId);
1508 else if ((Reason & ruCut) != 0)
1509 return cString::sprintf("Recording \"%s\" is being edited", RecordingId);
1510 else if ((Reason & (ruMove | ruCopy)) != 0)
1511 return cString::sprintf("Recording \"%s\" is being copied/moved", RecordingId);
1512 else if (Reason)
1513 return cString::sprintf("Recording \"%s\" is in use", RecordingId);
1514 return NULL;
1515}
1516
1517void cSVDRPServer::CmdCPYR(const char *Option)
1518{
1519 if (*Option) {
1520 char *opt = strdup(Option);
1521 char *num = skipspace(opt);
1522 char *option = num;
1523 while (*option && !isspace(*option))
1524 option++;
1525 char c = *option;
1526 *option = 0;
1527 if (isnumber(num)) {
1529 Recordings->SetExplicitModify();
1530 if (cRecording *Recording = Recordings->Get(strtol(num, NULL, 10) - 1)) {
1531 if (int RecordingInUse = Recording->IsInUse())
1532 Reply(550, "%s", *RecordingInUseMessage(RecordingInUse, Option, Recording));
1533 else {
1534 if (c)
1535 option = skipspace(++option);
1536 if (*option) {
1537 cString newName = option;
1539 if (strcmp(newName, Recording->Name())) {
1540 cString fromName = cString(ExchangeChars(strdup(Recording->Name()), true), true);
1541 cString toName = cString(ExchangeChars(strdup(*newName), true), true);
1542 cString fileName = cString(strreplace(strdup(Recording->FileName()), *fromName, *toName), true);
1543 if (MakeDirs(fileName, true) && !RecordingsHandler.Add(ruCopy, Recording->FileName(), fileName)) {
1544 Recordings->AddByName(fileName);
1545 Reply(250, "Recording \"%s\" copied to \"%s\"", Recording->Name(), *newName);
1546 }
1547 else
1548 Reply(554, "Error while copying recording \"%s\" to \"%s\"!", Recording->Name(), *newName);
1549 }
1550 else
1551 Reply(501, "Identical new recording name");
1552 }
1553 else
1554 Reply(501, "Missing new recording name");
1555 }
1556 }
1557 else
1558 Reply(550, "Recording \"%s\" not found", num);
1559 }
1560 else
1561 Reply(501, "Error in recording number \"%s\"", num);
1562 free(opt);
1563 }
1564 else
1565 Reply(501, "Missing recording number");
1566}
1567
1568void cSVDRPServer::CmdDELR(const char *Option)
1569{
1570 if (*Option) {
1571 if (isnumber(Option)) {
1573 Recordings->SetExplicitModify();
1574 if (cRecording *Recording = Recordings->GetById(strtol(Option, NULL, 10))) {
1575 if (int RecordingInUse = Recording->IsInUse())
1576 Reply(550, "%s", *RecordingInUseMessage(RecordingInUse, Option, Recording));
1577 else {
1578 if (Recording->Delete()) {
1579 Recordings->DelByName(Recording->FileName());
1580 Recordings->SetModified();
1581 isyslog("SVDRP %s < %s deleted recording %s", Setup.SVDRPHostName, *clientName, Option);
1582 Reply(250, "Recording \"%s\" deleted", Option);
1583 }
1584 else
1585 Reply(554, "Error while deleting recording!");
1586 }
1587 }
1588 else
1589 Reply(550, "Recording \"%s\" not found", Option);
1590 }
1591 else
1592 Reply(501, "Error in recording id \"%s\"", Option);
1593 }
1594 else
1595 Reply(501, "Missing recording id");
1596}
1597
1598void cSVDRPServer::CmdDELT(const char *Option)
1599{
1600 if (*Option) {
1601 if (isnumber(Option)) {
1603 Timers->SetExplicitModify();
1604 if (cTimer *Timer = Timers->GetById(strtol(Option, NULL, 10))) {
1605 if (Timer->Recording()) {
1606 Timer->Skip();
1607 cRecordControls::Process(Timers, time(NULL));
1608 }
1609 Timer->TriggerRespawn();
1610 Timers->Del(Timer);
1611 Timers->SetModified();
1612 isyslog("SVDRP %s < %s deleted timer %s", Setup.SVDRPHostName, *clientName, *Timer->ToDescr());
1613 Reply(250, "Timer \"%s\" deleted", Option);
1614 }
1615 else
1616 Reply(501, "Timer \"%s\" not defined", Option);
1617 }
1618 else
1619 Reply(501, "Error in timer number \"%s\"", Option);
1620 }
1621 else
1622 Reply(501, "Missing timer number");
1623}
1624
1625void cSVDRPServer::CmdEDIT(const char *Option)
1626{
1627 if (*Option) {
1628 if (isnumber(Option)) {
1630 if (const cRecording *Recording = Recordings->GetById(strtol(Option, NULL, 10))) {
1631 cMarks Marks;
1632 if (Marks.Load(Recording->FileName(), Recording->FramesPerSecond(), Recording->IsPesRecording()) && Marks.Count()) {
1633 if (!EnoughFreeDiskSpaceForEdit(Recording->FileName()))
1634 Reply(550, "Not enough free disk space to start editing process");
1635 else if (RecordingsHandler.Add(ruCut, Recording->FileName()))
1636 Reply(250, "Editing recording \"%s\" [%s]", Option, Recording->Title());
1637 else
1638 Reply(554, "Can't start editing process");
1639 }
1640 else
1641 Reply(554, "No editing marks defined");
1642 }
1643 else
1644 Reply(550, "Recording \"%s\" not found", Option);
1645 }
1646 else
1647 Reply(501, "Error in recording id \"%s\"", Option);
1648 }
1649 else
1650 Reply(501, "Missing recording id");
1651}
1652
1653void cSVDRPServer::CmdGRAB(const char *Option)
1654{
1655 const char *FileName = NULL;
1656 bool Jpeg = true;
1657 int Quality = -1, SizeX = -1, SizeY = -1;
1658 if (*Option) {
1659 char buf[strlen(Option) + 1];
1660 char *p = strcpy(buf, Option);
1661 const char *delim = " \t";
1662 char *strtok_next;
1663 FileName = strtok_r(p, delim, &strtok_next);
1664 // image type:
1665 const char *Extension = strrchr(FileName, '.');
1666 if (Extension) {
1667 if (strcasecmp(Extension, ".jpg") == 0 || strcasecmp(Extension, ".jpeg") == 0)
1668 Jpeg = true;
1669 else if (strcasecmp(Extension, ".pnm") == 0)
1670 Jpeg = false;
1671 else {
1672 Reply(501, "Unknown image type \"%s\"", Extension + 1);
1673 return;
1674 }
1675 if (Extension == FileName)
1676 FileName = NULL;
1677 }
1678 else if (strcmp(FileName, "-") == 0)
1679 FileName = NULL;
1680 // image quality (and obsolete type):
1681 if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
1682 if (strcasecmp(p, "JPEG") == 0 || strcasecmp(p, "PNM") == 0) {
1683 // tolerate for backward compatibility
1684 p = strtok_r(NULL, delim, &strtok_next);
1685 }
1686 if (p) {
1687 if (isnumber(p))
1688 Quality = atoi(p);
1689 else {
1690 Reply(501, "Invalid quality \"%s\"", p);
1691 return;
1692 }
1693 }
1694 }
1695 // image size:
1696 if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
1697 if (isnumber(p))
1698 SizeX = atoi(p);
1699 else {
1700 Reply(501, "Invalid sizex \"%s\"", p);
1701 return;
1702 }
1703 if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
1704 if (isnumber(p))
1705 SizeY = atoi(p);
1706 else {
1707 Reply(501, "Invalid sizey \"%s\"", p);
1708 return;
1709 }
1710 }
1711 else {
1712 Reply(501, "Missing sizey");
1713 return;
1714 }
1715 }
1716 if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
1717 Reply(501, "Unexpected parameter \"%s\"", p);
1718 return;
1719 }
1720 // canonicalize the file name:
1721 char RealFileName[PATH_MAX];
1722 if (FileName) {
1723 if (*grabImageDir) {
1724 cString s(FileName);
1725 FileName = s;
1726 const char *slash = strrchr(FileName, '/');
1727 if (!slash) {
1728 s = AddDirectory(grabImageDir, FileName);
1729 FileName = s;
1730 }
1731 slash = strrchr(FileName, '/'); // there definitely is one
1732 cString t(s);
1733 t.Truncate(slash - FileName);
1734 char *r = realpath(t, RealFileName);
1735 if (!r) {
1736 LOG_ERROR_STR(FileName);
1737 Reply(501, "Invalid file name \"%s\"", FileName);
1738 return;
1739 }
1740 strcat(RealFileName, slash);
1741 FileName = RealFileName;
1742 if (strncmp(FileName, grabImageDir, strlen(grabImageDir)) != 0) {
1743 Reply(501, "Invalid file name \"%s\"", FileName);
1744 return;
1745 }
1746 }
1747 else {
1748 Reply(550, "Grabbing to file not allowed (use \"GRAB -\" instead)");
1749 return;
1750 }
1751 }
1752 // actual grabbing:
1753 int ImageSize;
1754 uchar *Image = cDevice::PrimaryDevice()->GrabImage(ImageSize, Jpeg, Quality, SizeX, SizeY);
1755 if (Image) {
1756 if (FileName) {
1757 int fd = open(FileName, O_WRONLY | O_CREAT | O_NOFOLLOW | O_TRUNC, DEFFILEMODE);
1758 if (fd >= 0) {
1759 if (safe_write(fd, Image, ImageSize) == ImageSize) {
1760 dsyslog("SVDRP %s < %s grabbed image to %s", Setup.SVDRPHostName, *clientName, FileName);
1761 Reply(250, "Grabbed image %s", Option);
1762 }
1763 else {
1764 LOG_ERROR_STR(FileName);
1765 Reply(451, "Can't write to '%s'", FileName);
1766 }
1767 close(fd);
1768 }
1769 else {
1770 LOG_ERROR_STR(FileName);
1771 Reply(451, "Can't open '%s'", FileName);
1772 }
1773 }
1774 else {
1775 cBase64Encoder Base64(Image, ImageSize);
1776 const char *s;
1777 while ((s = Base64.NextLine()) != NULL)
1778 Reply(-216, "%s", s);
1779 Reply(216, "Grabbed image %s", Option);
1780 }
1781 free(Image);
1782 }
1783 else
1784 Reply(451, "Grab image failed");
1785 }
1786 else
1787 Reply(501, "Missing filename");
1788}
1789
1790void cSVDRPServer::CmdHELP(const char *Option)
1791{
1792 if (*Option) {
1793 const char *hp = GetHelpPage(Option, HelpPages);
1794 if (hp)
1795 Reply(-214, "%s", hp);
1796 else {
1797 Reply(504, "HELP topic \"%s\" unknown", Option);
1798 return;
1799 }
1800 }
1801 else {
1802 Reply(-214, "This is VDR version %s", VDRVERSION);
1803 Reply(-214, "Topics:");
1805 cPlugin *plugin;
1806 for (int i = 0; (plugin = cPluginManager::GetPlugin(i)) != NULL; i++) {
1807 const char **hp = plugin->SVDRPHelpPages();
1808 if (hp)
1809 Reply(-214, "Plugin %s v%s - %s", plugin->Name(), plugin->Version(), plugin->Description());
1810 PrintHelpTopics(hp);
1811 }
1812 Reply(-214, "To report bugs in the implementation send email to");
1813 Reply(-214, " vdr-bugs@tvdr.de");
1814 }
1815 Reply(214, "End of HELP info");
1816}
1817
1818void cSVDRPServer::CmdHITK(const char *Option)
1819{
1820 if (*Option) {
1821 if (!cRemote::Enabled()) {
1822 Reply(550, "Remote control currently disabled (key \"%s\" discarded)", Option);
1823 return;
1824 }
1825 char buf[strlen(Option) + 1];
1826 strcpy(buf, Option);
1827 const char *delim = " \t";
1828 char *strtok_next;
1829 char *p = strtok_r(buf, delim, &strtok_next);
1830 int NumKeys = 0;
1831 while (p) {
1832 eKeys k = cKey::FromString(p);
1833 if (k != kNone) {
1834 if (!cRemote::Put(k)) {
1835 Reply(451, "Too many keys in \"%s\" (only %d accepted)", Option, NumKeys);
1836 return;
1837 }
1838 }
1839 else {
1840 Reply(504, "Unknown key: \"%s\"", p);
1841 return;
1842 }
1843 NumKeys++;
1844 p = strtok_r(NULL, delim, &strtok_next);
1845 }
1846 Reply(250, "Key%s \"%s\" accepted", NumKeys > 1 ? "s" : "", Option);
1847 }
1848 else {
1849 Reply(-214, "Valid <key> names for the HITK command:");
1850 for (int i = 0; i < kNone; i++) {
1851 Reply(-214, " %s", cKey::ToString(eKeys(i)));
1852 }
1853 Reply(214, "End of key list");
1854 }
1855}
1856
1857void cSVDRPServer::CmdLSTC(const char *Option)
1858{
1860 bool WithChannelIds = startswith(Option, ":ids") && (Option[4] == ' ' || Option[4] == 0);
1861 if (WithChannelIds)
1862 Option = skipspace(Option + 4);
1863 bool WithGroupSeps = strcasecmp(Option, ":groups") == 0;
1864 if (*Option && !WithGroupSeps) {
1865 if (isnumber(Option)) {
1866 int n = strtol(Option, NULL, 10);
1867 if (n == 0)
1869 if (const cChannel *Channel = Channels->GetByNumber(n))
1870 Reply(250, "%d%s%s %s", Channel->Number(), WithChannelIds ? " " : "", WithChannelIds ? *Channel->GetChannelID().ToString() : "", *Channel->ToText());
1871 else
1872 Reply(501, "Channel \"%s\" not defined", Option);
1873 }
1874 else {
1875 const cChannel *Next = Channels->GetByChannelID(tChannelID::FromString(Option));
1876 if (!Next) {
1877 for (const cChannel *Channel = Channels->First(); Channel; Channel = Channels->Next(Channel)) {
1878 if (!Channel->GroupSep()) {
1879 if (strcasestr(Channel->Name(), Option)) {
1880 if (Next)
1881 Reply(-250, "%d%s%s %s", Next->Number(), WithChannelIds ? " " : "", WithChannelIds ? *Next->GetChannelID().ToString() : "", *Next->ToText());
1882 Next = Channel;
1883 }
1884 }
1885 }
1886 }
1887 if (Next)
1888 Reply(250, "%d%s%s %s", Next->Number(), WithChannelIds ? " " : "", WithChannelIds ? *Next->GetChannelID().ToString() : "", *Next->ToText());
1889 else
1890 Reply(501, "Channel \"%s\" not defined", Option);
1891 }
1892 }
1893 else if (cChannels::MaxNumber() >= 1) {
1894 for (const cChannel *Channel = Channels->First(); Channel; Channel = Channels->Next(Channel)) {
1895 if (WithGroupSeps)
1896 Reply(Channel->Next() ? -250: 250, "%d%s%s %s", Channel->GroupSep() ? 0 : Channel->Number(), (WithChannelIds && !Channel->GroupSep()) ? " " : "", (WithChannelIds && !Channel->GroupSep()) ? *Channel->GetChannelID().ToString() : "", *Channel->ToText());
1897 else if (!Channel->GroupSep())
1898 Reply(Channel->Number() < cChannels::MaxNumber() ? -250 : 250, "%d%s%s %s", Channel->Number(), WithChannelIds ? " " : "", WithChannelIds ? *Channel->GetChannelID().ToString() : "", *Channel->ToText());
1899 }
1900 }
1901 else
1902 Reply(550, "No channels defined");
1903}
1904
1905void cSVDRPServer::CmdLSTD(const char *Option)
1906{
1907 if (cDevice::NumDevices()) {
1908 for (int i = 0; i < cDevice::NumDevices(); i++) {
1909 if (const cDevice *d = cDevice::GetDevice(i))
1910 Reply(d->DeviceNumber() + 1 == cDevice::NumDevices() ? 250 : -250, "%d [%s%s] %s", d->DeviceNumber() + 1, d->HasDecoder() ? "D" : "-", d->DeviceNumber() + 1 == Setup.PrimaryDVB ? "P" : "-", *d->DeviceName());
1911 }
1912 }
1913 else
1914 Reply(550, "No devices found");
1915}
1916
1917void cSVDRPServer::CmdLSTE(const char *Option)
1918{
1921 const cSchedule* Schedule = NULL;
1922 eDumpMode DumpMode = dmAll;
1923 time_t AtTime = 0;
1924 if (*Option) {
1925 char buf[strlen(Option) + 1];
1926 strcpy(buf, Option);
1927 const char *delim = " \t";
1928 char *strtok_next;
1929 char *p = strtok_r(buf, delim, &strtok_next);
1930 while (p && DumpMode == dmAll) {
1931 if (strcasecmp(p, "NOW") == 0)
1932 DumpMode = dmPresent;
1933 else if (strcasecmp(p, "NEXT") == 0)
1934 DumpMode = dmFollowing;
1935 else if (strcasecmp(p, "AT") == 0) {
1936 DumpMode = dmAtTime;
1937 if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
1938 if (isnumber(p))
1939 AtTime = strtol(p, NULL, 10);
1940 else {
1941 Reply(501, "Invalid time");
1942 return;
1943 }
1944 }
1945 else {
1946 Reply(501, "Missing time");
1947 return;
1948 }
1949 }
1950 else if (!Schedule) {
1951 const cChannel* Channel = NULL;
1952 if (isnumber(p))
1953 Channel = Channels->GetByNumber(strtol(Option, NULL, 10));
1954 else
1955 Channel = Channels->GetByChannelID(tChannelID::FromString(Option));
1956 if (Channel) {
1957 Schedule = Schedules->GetSchedule(Channel);
1958 if (!Schedule) {
1959 Reply(550, "No schedule found");
1960 return;
1961 }
1962 }
1963 else {
1964 Reply(550, "Channel \"%s\" not defined", p);
1965 return;
1966 }
1967 }
1968 else {
1969 Reply(501, "Unknown option: \"%s\"", p);
1970 return;
1971 }
1972 p = strtok_r(NULL, delim, &strtok_next);
1973 }
1974 }
1975 int fd = dup(file);
1976 if (fd) {
1977 FILE *f = fdopen(fd, "w");
1978 if (f) {
1979 if (Schedule)
1980 Schedule->Dump(Channels, f, "215-", DumpMode, AtTime);
1981 else
1982 Schedules->Dump(f, "215-", DumpMode, AtTime);
1983 fflush(f);
1984 Reply(215, "End of EPG data");
1985 fclose(f);
1986 }
1987 else {
1988 Reply(451, "Can't open file connection");
1989 close(fd);
1990 }
1991 }
1992 else
1993 Reply(451, "Can't dup stream descriptor");
1994}
1995
1996void cSVDRPServer::CmdLSTR(const char *Option)
1997{
1998 int Number = 0;
1999 bool Path = false;
2001 if (*Option) {
2002 char buf[strlen(Option) + 1];
2003 strcpy(buf, Option);
2004 const char *delim = " \t";
2005 char *strtok_next;
2006 char *p = strtok_r(buf, delim, &strtok_next);
2007 while (p) {
2008 if (!Number) {
2009 if (isnumber(p))
2010 Number = strtol(p, NULL, 10);
2011 else {
2012 Reply(501, "Error in recording id \"%s\"", Option);
2013 return;
2014 }
2015 }
2016 else if (strcasecmp(p, "PATH") == 0)
2017 Path = true;
2018 else {
2019 Reply(501, "Unknown option: \"%s\"", p);
2020 return;
2021 }
2022 p = strtok_r(NULL, delim, &strtok_next);
2023 }
2024 if (Number) {
2025 if (const cRecording *Recording = Recordings->GetById(strtol(Option, NULL, 10))) {
2026 FILE *f = fdopen(file, "w");
2027 if (f) {
2028 if (Path)
2029 Reply(250, "%s", Recording->FileName());
2030 else {
2031 Recording->Info()->Write(f, "215-");
2032 fflush(f);
2033 Reply(215, "End of recording information");
2034 }
2035 // don't 'fclose(f)' here!
2036 }
2037 else
2038 Reply(451, "Can't open file connection");
2039 }
2040 else
2041 Reply(550, "Recording \"%s\" not found", Option);
2042 }
2043 }
2044 else if (Recordings->Count()) {
2045 const cRecording *Recording = Recordings->First();
2046 while (Recording) {
2047 Reply(Recording == Recordings->Last() ? 250 : -250, "%d %s", Recording->Id(), Recording->Title(' ', true));
2048 Recording = Recordings->Next(Recording);
2049 }
2050 }
2051 else
2052 Reply(550, "No recordings available");
2053}
2054
2055void cSVDRPServer::CmdLSTT(const char *Option)
2056{
2057 int Id = 0;
2058 bool UseChannelId = false;
2059 if (*Option) {
2060 char buf[strlen(Option) + 1];
2061 strcpy(buf, Option);
2062 const char *delim = " \t";
2063 char *strtok_next;
2064 char *p = strtok_r(buf, delim, &strtok_next);
2065 while (p) {
2066 if (isnumber(p))
2067 Id = strtol(p, NULL, 10);
2068 else if (strcasecmp(p, "ID") == 0)
2069 UseChannelId = true;
2070 else {
2071 Reply(501, "Unknown option: \"%s\"", p);
2072 return;
2073 }
2074 p = strtok_r(NULL, delim, &strtok_next);
2075 }
2076 }
2078 if (Id) {
2079 for (const cTimer *Timer = Timers->First(); Timer; Timer = Timers->Next(Timer)) {
2080 if (!Timer->Remote()) {
2081 if (Timer->Id() == Id) {
2082 Reply(250, "%d %s", Timer->Id(), *Timer->ToText(UseChannelId));
2083 return;
2084 }
2085 }
2086 }
2087 Reply(501, "Timer \"%s\" not defined", Option);
2088 return;
2089 }
2090 else {
2091 const cTimer *LastLocalTimer = Timers->Last();
2092 while (LastLocalTimer) {
2093 if (LastLocalTimer->Remote())
2094 LastLocalTimer = Timers->Prev(LastLocalTimer);
2095 else
2096 break;
2097 }
2098 if (LastLocalTimer) {
2099 for (const cTimer *Timer = Timers->First(); Timer; Timer = Timers->Next(Timer)) {
2100 if (!Timer->Remote())
2101 Reply(Timer != LastLocalTimer ? -250 : 250, "%d %s", Timer->Id(), *Timer->ToText(UseChannelId));
2102 if (Timer == LastLocalTimer)
2103 break;
2104 }
2105 return;
2106 }
2107 }
2108 Reply(550, "No timers defined");
2109}
2110
2111void cSVDRPServer::CmdMESG(const char *Option)
2112{
2113 if (*Option) {
2114 isyslog("SVDRP %s < %s message '%s'", Setup.SVDRPHostName, *clientName, Option);
2115 Skins.QueueMessage(mtInfo, Option);
2116 Reply(250, "Message queued");
2117 }
2118 else
2119 Reply(501, "Missing message");
2120}
2121
2122void cSVDRPServer::CmdMODC(const char *Option)
2123{
2124 if (*Option) {
2125 char *tail;
2126 int n = strtol(Option, &tail, 10);
2127 if (tail && tail != Option) {
2128 tail = skipspace(tail);
2130 Channels->SetExplicitModify();
2131 if (cChannel *Channel = Channels->GetByNumber(n)) {
2132 cChannel ch;
2133 if (ch.Parse(tail)) {
2134 if (Channels->HasUniqueChannelID(&ch, Channel)) {
2135 *Channel = ch;
2136 Channels->ReNumber();
2137 Channels->SetModifiedByUser();
2138 Channels->SetModified();
2139 isyslog("SVDRP %s < %s modified channel %d %s", Setup.SVDRPHostName, *clientName, Channel->Number(), *Channel->ToText());
2140 Reply(250, "%d %s", Channel->Number(), *Channel->ToText());
2141 }
2142 else
2143 Reply(501, "Channel settings are not unique");
2144 }
2145 else
2146 Reply(501, "Error in channel settings");
2147 }
2148 else
2149 Reply(501, "Channel \"%d\" not defined", n);
2150 }
2151 else
2152 Reply(501, "Error in channel number");
2153 }
2154 else
2155 Reply(501, "Missing channel settings");
2156}
2157
2158void cSVDRPServer::CmdMODT(const char *Option)
2159{
2160 if (*Option) {
2161 char *tail;
2162 int Id = strtol(Option, &tail, 10);
2163 if (tail && tail != Option) {
2164 tail = skipspace(tail);
2166 Timers->SetExplicitModify();
2167 if (cTimer *Timer = Timers->GetById(Id)) {
2168 bool IsRecording = Timer->HasFlags(tfRecording);
2169 cTimer t = *Timer;
2170 if (strcasecmp(tail, "ON") == 0)
2171 t.SetFlags(tfActive);
2172 else if (strcasecmp(tail, "OFF") == 0)
2173 t.ClrFlags(tfActive);
2174 else if (!t.Parse(tail)) {
2175 Reply(501, "Error in timer settings");
2176 return;
2177 }
2178 if (IsRecording && t.IsPatternTimer()) {
2179 Reply(550, "Timer is recording");
2180 return;
2181 }
2182 *Timer = t;
2183 if (IsRecording)
2184 Timer->SetFlags(tfRecording);
2185 else
2186 Timer->ClrFlags(tfRecording);
2187 Timers->SetModified();
2188 isyslog("SVDRP %s < %s modified timer %s (%s)", Setup.SVDRPHostName, *clientName, *Timer->ToDescr(), Timer->HasFlags(tfActive) ? "active" : "inactive");
2189 if (Timer->IsPatternTimer())
2190 Timer->SetEvent(NULL);
2191 Timer->TriggerRespawn();
2192 Reply(250, "%d %s", Timer->Id(), *Timer->ToText(true));
2193 }
2194 else
2195 Reply(501, "Timer \"%d\" not defined", Id);
2196 }
2197 else
2198 Reply(501, "Error in timer id");
2199 }
2200 else
2201 Reply(501, "Missing timer settings");
2202}
2203
2204void cSVDRPServer::CmdMOVC(const char *Option)
2205{
2206 if (*Option) {
2207 char *tail;
2208 int From = strtol(Option, &tail, 10);
2209 if (tail && tail != Option) {
2210 tail = skipspace(tail);
2211 if (tail && tail != Option) {
2212 LOCK_TIMERS_READ; // necessary to keep timers and channels in sync!
2214 Channels->SetExplicitModify();
2215 int To = strtol(tail, NULL, 10);
2216 int CurrentChannelNr = cDevice::CurrentChannel();
2217 const cChannel *CurrentChannel = Channels->GetByNumber(CurrentChannelNr);
2218 cChannel *FromChannel = Channels->GetByNumber(From);
2219 if (FromChannel) {
2220 cChannel *ToChannel = Channels->GetByNumber(To);
2221 if (ToChannel) {
2222 int FromNumber = FromChannel->Number();
2223 int ToNumber = ToChannel->Number();
2224 if (FromNumber != ToNumber) {
2225 if (Channels->MoveNeedsDecrement(FromChannel, ToChannel))
2226 ToChannel = Channels->Prev(ToChannel); // cListBase::Move() doesn't know about the channel list's numbered groups!
2227 Channels->Move(FromChannel, ToChannel);
2228 Channels->ReNumber();
2229 Channels->SetModifiedByUser();
2230 Channels->SetModified();
2231 if (CurrentChannel && CurrentChannel->Number() != CurrentChannelNr) {
2232 if (!cDevice::PrimaryDevice()->Replaying() || cDevice::PrimaryDevice()->Transferring())
2233 Channels->SwitchTo(CurrentChannel->Number());
2234 else
2235 cDevice::SetCurrentChannel(CurrentChannel->Number());
2236 }
2237 isyslog("SVDRP %s < %s moved channel %d to %d", Setup.SVDRPHostName, *clientName, FromNumber, ToNumber);
2238 Reply(250,"Channel \"%d\" moved to \"%d\"", From, To);
2239 }
2240 else
2241 Reply(501, "Can't move channel to same position");
2242 }
2243 else
2244 Reply(501, "Channel \"%d\" not defined", To);
2245 }
2246 else
2247 Reply(501, "Channel \"%d\" not defined", From);
2248 }
2249 else
2250 Reply(501, "Error in channel number");
2251 }
2252 else
2253 Reply(501, "Error in channel number");
2254 }
2255 else
2256 Reply(501, "Missing channel number");
2257}
2258
2259void cSVDRPServer::CmdMOVR(const char *Option)
2260{
2261 if (*Option) {
2262 char *opt = strdup(Option);
2263 char *num = skipspace(opt);
2264 char *option = num;
2265 while (*option && !isspace(*option))
2266 option++;
2267 char c = *option;
2268 *option = 0;
2269 if (isnumber(num)) {
2271 Recordings->SetExplicitModify();
2272 if (cRecording *Recording = Recordings->GetById(strtol(num, NULL, 10))) {
2273 if (int RecordingInUse = Recording->IsInUse())
2274 Reply(550, "%s", *RecordingInUseMessage(RecordingInUse, Option, Recording));
2275 else {
2276 if (c)
2277 option = skipspace(++option);
2278 if (*option) {
2279 cString oldName = Recording->Name();
2280 if ((Recording = Recordings->GetByName(Recording->FileName())) != NULL && Recording->ChangeName(option)) {
2281 Recordings->SetModified();
2282 Recordings->TouchUpdate();
2283 Reply(250, "Recording \"%s\" moved to \"%s\"", *oldName, Recording->Name());
2284 }
2285 else
2286 Reply(554, "Error while moving recording \"%s\" to \"%s\"!", *oldName, option);
2287 }
2288 else
2289 Reply(501, "Missing new recording name");
2290 }
2291 }
2292 else
2293 Reply(550, "Recording \"%s\" not found", num);
2294 }
2295 else
2296 Reply(501, "Error in recording id \"%s\"", num);
2297 free(opt);
2298 }
2299 else
2300 Reply(501, "Missing recording id");
2301}
2302
2303void cSVDRPServer::CmdNEWC(const char *Option)
2304{
2305 if (*Option) {
2306 cChannel ch;
2307 if (ch.Parse(Option)) {
2309 Channels->SetExplicitModify();
2310 if (Channels->HasUniqueChannelID(&ch)) {
2311 cChannel *channel = new cChannel;
2312 *channel = ch;
2313 Channels->Add(channel);
2314 Channels->ReNumber();
2315 Channels->SetModifiedByUser();
2316 Channels->SetModified();
2317 isyslog("SVDRP %s < %s new channel %d %s", Setup.SVDRPHostName, *clientName, channel->Number(), *channel->ToText());
2318 Reply(250, "%d %s", channel->Number(), *channel->ToText());
2319 }
2320 else
2321 Reply(501, "Channel settings are not unique");
2322 }
2323 else
2324 Reply(501, "Error in channel settings");
2325 }
2326 else
2327 Reply(501, "Missing channel settings");
2328}
2329
2330void cSVDRPServer::CmdNEWT(const char *Option)
2331{
2332 if (*Option) {
2333 cTimer *Timer = new cTimer;
2334 if (Timer->Parse(Option)) {
2336 const cTimer *t = Timers->GetTimer(Timer);
2337 if (!t) {
2338 Timer->ClrFlags(tfRecording);
2339 Timers->Add(Timer);
2340 isyslog("SVDRP %s < %s added timer %s", Setup.SVDRPHostName, *clientName, *Timer->ToDescr());
2341 Reply(250, "%d %s", Timer->Id(), *Timer->ToText(true));
2342 }
2343 else {
2344 isyslog("SVDRP %s < %s attempted to add timer %s", Setup.SVDRPHostName, *clientName, *Timer->ToDescr());
2345 isyslog("SVDRP %s < %s timer already exists as %s", Setup.SVDRPHostName, *clientName, *t->ToDescr());
2346 delete Timer;
2347 Reply(550, "%d %s", t->Id(), *t->ToText(true));
2348 }
2349 return;
2350 }
2351 else
2352 Reply(501, "Error in timer settings");
2353 delete Timer;
2354 }
2355 else
2356 Reply(501, "Missing timer settings");
2357}
2358
2359void cSVDRPServer::CmdNEXT(const char *Option)
2360{
2362 if (const cTimer *t = Timers->GetNextActiveTimer()) {
2363 time_t Start = t->StartTime();
2364 int Id = t->Id();
2365 if (!*Option)
2366 Reply(250, "%d %s", Id, *TimeToString(Start));
2367 else if (strcasecmp(Option, "ABS") == 0)
2368 Reply(250, "%d %jd", Id, intmax_t(Start));
2369 else if (strcasecmp(Option, "REL") == 0)
2370 Reply(250, "%d %jd", Id, intmax_t(Start - time(NULL)));
2371 else
2372 Reply(501, "Unknown option: \"%s\"", Option);
2373 }
2374 else
2375 Reply(550, "No active timers");
2376}
2377
2378void cSVDRPServer::CmdPING(const char *Option)
2379{
2380 Reply(250, "%s is alive", Setup.SVDRPHostName);
2381}
2382
2383void cSVDRPServer::CmdPLAY(const char *Option)
2384{
2385 if (*Option) {
2386 char *opt = strdup(Option);
2387 char *num = skipspace(opt);
2388 char *option = num;
2389 while (*option && !isspace(*option))
2390 option++;
2391 char c = *option;
2392 *option = 0;
2393 if (isnumber(num)) {
2394 cStateKey StateKey;
2395 if (const cRecordings *Recordings = cRecordings::GetRecordingsRead(StateKey)) {
2396 if (const cRecording *Recording = Recordings->GetById(strtol(num, NULL, 10))) {
2397 cString FileName = Recording->FileName();
2398 cString Title = Recording->Title();
2399 int FramesPerSecond = Recording->FramesPerSecond();
2400 bool IsPesRecording = Recording->IsPesRecording();
2401 StateKey.Remove(); // must give up the lock for the call to cControl::Shutdown()
2402 if (c)
2403 option = skipspace(++option);
2406 if (*option) {
2407 int pos = 0;
2408 if (strcasecmp(option, "BEGIN") != 0)
2409 pos = HMSFToIndex(option, FramesPerSecond);
2410 cResumeFile Resume(FileName, IsPesRecording);
2411 if (pos <= 0)
2412 Resume.Delete();
2413 else
2414 Resume.Save(pos);
2415 }
2419 Reply(250, "Playing recording \"%s\" [%s]", num, *Title);
2420 }
2421 else {
2422 StateKey.Remove();
2423 Reply(550, "Recording \"%s\" not found", num);
2424 }
2425 }
2426 }
2427 else
2428 Reply(501, "Error in recording id \"%s\"", num);
2429 free(opt);
2430 }
2431 else if (const char *FileName = cReplayControl::NowReplaying()) {
2433 if (const cRecording *Recording = Recordings->GetByName(FileName))
2434 Reply(250, "%d %s", Recording->Id(), Recording->Title(' ', true));
2435 else
2436 Reply(550, "Recording \"%s\" not found", FileName);
2437 }
2438 else
2439 Reply(550, "Not playing");
2440}
2441
2442void cSVDRPServer::CmdPLUG(const char *Option)
2443{
2444 if (*Option) {
2445 char *opt = strdup(Option);
2446 char *name = skipspace(opt);
2447 char *option = name;
2448 while (*option && !isspace(*option))
2449 option++;
2450 char c = *option;
2451 *option = 0;
2452 cPlugin *plugin = cPluginManager::GetPlugin(name);
2453 if (plugin) {
2454 if (c)
2455 option = skipspace(++option);
2456 char *cmd = option;
2457 while (*option && !isspace(*option))
2458 option++;
2459 if (*option) {
2460 *option++ = 0;
2461 option = skipspace(option);
2462 }
2463 if (!*cmd || strcasecmp(cmd, "HELP") == 0) {
2464 if (*cmd && *option) {
2465 const char *hp = GetHelpPage(option, plugin->SVDRPHelpPages());
2466 if (hp) {
2467 Reply(-214, "%s", hp);
2468 Reply(214, "End of HELP info");
2469 }
2470 else
2471 Reply(504, "HELP topic \"%s\" for plugin \"%s\" unknown", option, plugin->Name());
2472 }
2473 else {
2474 Reply(-214, "Plugin %s v%s - %s", plugin->Name(), plugin->Version(), plugin->Description());
2475 const char **hp = plugin->SVDRPHelpPages();
2476 if (hp) {
2477 Reply(-214, "SVDRP commands:");
2478 PrintHelpTopics(hp);
2479 Reply(214, "End of HELP info");
2480 }
2481 else
2482 Reply(214, "This plugin has no SVDRP commands");
2483 }
2484 }
2485 else if (strcasecmp(cmd, "MAIN") == 0) {
2486 if (cRemote::CallPlugin(plugin->Name()))
2487 Reply(250, "Initiated call to main menu function of plugin \"%s\"", plugin->Name());
2488 else
2489 Reply(550, "A plugin call is already pending - please try again later");
2490 }
2491 else {
2492 int ReplyCode = 900;
2493 cString s = plugin->SVDRPCommand(cmd, option, ReplyCode);
2494 if (*s)
2495 Reply(abs(ReplyCode), "%s", *s);
2496 else
2497 Reply(500, "Command unrecognized: \"%s\"", cmd);
2498 }
2499 }
2500 else
2501 Reply(550, "Plugin \"%s\" not found (use PLUG for a list of plugins)", name);
2502 free(opt);
2503 }
2504 else {
2505 Reply(-214, "Available plugins:");
2506 cPlugin *plugin;
2507 for (int i = 0; (plugin = cPluginManager::GetPlugin(i)) != NULL; i++)
2508 Reply(-214, "%s v%s - %s", plugin->Name(), plugin->Version(), plugin->Description());
2509 Reply(214, "End of plugin list");
2510 }
2511}
2512
2513void cSVDRPServer::CmdPOLL(const char *Option)
2514{
2515 if (*Option) {
2516 char buf[strlen(Option) + 1];
2517 char *p = strcpy(buf, Option);
2518 const char *delim = " \t";
2519 char *strtok_next;
2520 char *RemoteName = strtok_r(p, delim, &strtok_next);
2521 char *ListName = strtok_r(NULL, delim, &strtok_next);
2522 if (SVDRPClientHandler) {
2523 if (ListName) {
2524 if (strcasecmp(ListName, "timers") == 0) {
2525 Reply(250, "OK"); // must send reply before calling TriggerFetchingTimers() to avoid a deadlock if two clients send each other POLL commands at the same time
2526 SVDRPClientHandler->TriggerFetchingTimers(RemoteName);
2527 }
2528 else
2529 Reply(501, "Unknown list name: \"%s\"", ListName);
2530 }
2531 else
2532 Reply(501, "Missing list name");
2533 }
2534 else
2535 Reply(501, "No SVDRP client connections");
2536 }
2537 else
2538 Reply(501, "Missing parameters");
2539}
2540
2541void cSVDRPServer::CmdPRIM(const char *Option)
2542{
2543 int n = -1;
2544 if (*Option) {
2545 if (isnumber(Option)) {
2546 int o = strtol(Option, NULL, 10);
2547 if (o > 0 && o <= cDevice::NumDevices())
2548 n = o;
2549 else
2550 Reply(501, "Invalid device number \"%s\"", Option);
2551 }
2552 else
2553 Reply(501, "Invalid parameter \"%s\"", Option);
2554 if (n >= 0) {
2555 Setup.PrimaryDVB = n;
2556 Reply(250, "Primary device set to %d", n);
2557 }
2558 }
2559 else {
2560 if (const cDevice *d = cDevice::PrimaryDevice())
2561 Reply(250, "%d [%s%s] %s", d->DeviceNumber() + 1, d->HasDecoder() ? "D" : "-", d->DeviceNumber() + 1 == Setup.PrimaryDVB ? "P" : "-", *d->DeviceName());
2562 else
2563 Reply(501, "Failed to get primary device");
2564 }
2565}
2566
2567void cSVDRPServer::CmdPUTE(const char *Option)
2568{
2569 if (*Option) {
2570 FILE *f = fopen(Option, "r");
2571 if (f) {
2572 if (cSchedules::Read(f)) {
2573 cSchedules::Cleanup(true);
2574 Reply(250, "EPG data processed from \"%s\"", Option);
2575 }
2576 else
2577 Reply(451, "Error while processing EPG from \"%s\"", Option);
2578 fclose(f);
2579 }
2580 else
2581 Reply(501, "Cannot open file \"%s\"", Option);
2582 }
2583 else {
2584 delete PUTEhandler;
2586 Reply(PUTEhandler->Status(), "%s", PUTEhandler->Message());
2587 if (PUTEhandler->Status() != 354)
2589 }
2590}
2591
2592void cSVDRPServer::CmdREMO(const char *Option)
2593{
2594 if (*Option) {
2595 if (!strcasecmp(Option, "ON")) {
2596 cRemote::SetEnabled(true);
2597 Reply(250, "Remote control enabled");
2598 }
2599 else if (!strcasecmp(Option, "OFF")) {
2600 cRemote::SetEnabled(false);
2601 Reply(250, "Remote control disabled");
2602 }
2603 else
2604 Reply(501, "Invalid Option \"%s\"", Option);
2605 }
2606 else
2607 Reply(250, "Remote control is %s", cRemote::Enabled() ? "enabled" : "disabled");
2608}
2609
2610void cSVDRPServer::CmdSCAN(const char *Option)
2611{
2612 EITScanner.ForceScan();
2613 Reply(250, "EPG scan triggered");
2614}
2615
2616void cSVDRPServer::CmdSTAT(const char *Option)
2617{
2618 if (*Option) {
2619 if (strcasecmp(Option, "DISK") == 0) {
2620 int FreeMB, UsedMB;
2621 int Percent = cVideoDirectory::VideoDiskSpace(&FreeMB, &UsedMB);
2622 Reply(250, "%dMB %dMB %d%%", FreeMB + UsedMB, FreeMB, Percent);
2623 }
2624 else
2625 Reply(501, "Invalid Option \"%s\"", Option);
2626 }
2627 else
2628 Reply(501, "No option given");
2629}
2630
2631void cSVDRPServer::CmdUPDT(const char *Option)
2632{
2633 if (*Option) {
2634 cTimer *Timer = new cTimer;
2635 if (Timer->Parse(Option)) {
2637 if (cTimer *t = Timers->GetTimer(Timer)) {
2638 bool IsRecording = t->HasFlags(tfRecording);
2639 t->Parse(Option);
2640 delete Timer;
2641 Timer = t;
2642 if (IsRecording)
2643 Timer->SetFlags(tfRecording);
2644 else
2645 Timer->ClrFlags(tfRecording);
2646 isyslog("SVDRP %s < %s updated timer %s", Setup.SVDRPHostName, *clientName, *Timer->ToDescr());
2647 }
2648 else {
2649 Timer->ClrFlags(tfRecording);
2650 Timers->Add(Timer);
2651 isyslog("SVDRP %s < %s added timer %s", Setup.SVDRPHostName, *clientName, *Timer->ToDescr());
2652 }
2653 Reply(250, "%d %s", Timer->Id(), *Timer->ToText(true));
2654 return;
2655 }
2656 else
2657 Reply(501, "Error in timer settings");
2658 delete Timer;
2659 }
2660 else
2661 Reply(501, "Missing timer settings");
2662}
2663
2664void cSVDRPServer::CmdUPDR(const char *Option)
2665{
2667 Recordings->Update(false);
2668 Reply(250, "Re-read of recordings directory triggered");
2669}
2670
2671void cSVDRPServer::CmdVOLU(const char *Option)
2672{
2673 if (*Option) {
2674 if (isnumber(Option))
2675 cDevice::PrimaryDevice()->SetVolume(strtol(Option, NULL, 10), true);
2676 else if (strcmp(Option, "+") == 0)
2678 else if (strcmp(Option, "-") == 0)
2680 else if (strcasecmp(Option, "MUTE") == 0)
2682 else {
2683 Reply(501, "Unknown option: \"%s\"", Option);
2684 return;
2685 }
2686 }
2687 if (cDevice::PrimaryDevice()->IsMute())
2688 Reply(250, "Audio is mute");
2689 else
2690 Reply(250, "Audio volume is %d", cDevice::CurrentVolume());
2691}
2692
2693#define CMD(c) (strcasecmp(Cmd, c) == 0)
2694
2696{
2697 // handle PUTE data:
2698 if (PUTEhandler) {
2699 if (!PUTEhandler->Process(Cmd)) {
2700 Reply(PUTEhandler->Status(), "%s", PUTEhandler->Message());
2702 }
2703 cEitFilter::SetDisableUntil(time(NULL) + EITDISABLETIME); // re-trigger the timeout, in case there is very much EPG data
2704 return;
2705 }
2706 // skip leading whitespace:
2707 Cmd = skipspace(Cmd);
2708 // find the end of the command word:
2709 char *s = Cmd;
2710 while (*s && !isspace(*s))
2711 s++;
2712 if (*s)
2713 *s++ = 0;
2714 s = skipspace(s);
2715 if (CMD("AUDI")) CmdAUDI(s);
2716 else if (CMD("CHAN")) CmdCHAN(s);
2717 else if (CMD("CLRE")) CmdCLRE(s);
2718 else if (CMD("CONN")) CmdCONN(s);
2719 else if (CMD("DELC")) CmdDELC(s);
2720 else if (CMD("DELR")) CmdDELR(s);
2721 else if (CMD("DELT")) CmdDELT(s);
2722 else if (CMD("EDIT")) CmdEDIT(s);
2723 else if (CMD("GRAB")) CmdGRAB(s);
2724 else if (CMD("HELP")) CmdHELP(s);
2725 else if (CMD("HITK")) CmdHITK(s);
2726 else if (CMD("LSTC")) CmdLSTC(s);
2727 else if (CMD("LSTD")) CmdLSTD(s);
2728 else if (CMD("LSTE")) CmdLSTE(s);
2729 else if (CMD("LSTR")) CmdLSTR(s);
2730 else if (CMD("LSTT")) CmdLSTT(s);
2731 else if (CMD("MESG")) CmdMESG(s);
2732 else if (CMD("MODC")) CmdMODC(s);
2733 else if (CMD("MODT")) CmdMODT(s);
2734 else if (CMD("MOVC")) CmdMOVC(s);
2735 else if (CMD("MOVR")) CmdMOVR(s);
2736 else if (CMD("NEWC")) CmdNEWC(s);
2737 else if (CMD("NEWT")) CmdNEWT(s);
2738 else if (CMD("NEXT")) CmdNEXT(s);
2739 else if (CMD("PING")) CmdPING(s);
2740 else if (CMD("PLAY")) CmdPLAY(s);
2741 else if (CMD("PLUG")) CmdPLUG(s);
2742 else if (CMD("POLL")) CmdPOLL(s);
2743 else if (CMD("PRIM")) CmdPRIM(s);
2744 else if (CMD("PUTE")) CmdPUTE(s);
2745 else if (CMD("REMO")) CmdREMO(s);
2746 else if (CMD("SCAN")) CmdSCAN(s);
2747 else if (CMD("STAT")) CmdSTAT(s);
2748 else if (CMD("UPDR")) CmdUPDR(s);
2749 else if (CMD("UPDT")) CmdUPDT(s);
2750 else if (CMD("VOLU")) CmdVOLU(s);
2751 else if (CMD("QUIT")) Close(true);
2752 else Reply(500, "Command unrecognized: \"%s\"", Cmd);
2753}
2754
2756{
2757 if (file.IsOpen()) {
2758 while (file.Ready(false)) {
2759 unsigned char c;
2760 int r = safe_read(file, &c, 1);
2761 if (r > 0) {
2762 if (c == '\n' || c == 0x00) {
2763 // strip trailing whitespace:
2764 while (numChars > 0 && strchr(" \t\r\n", cmdLine[numChars - 1]))
2765 cmdLine[--numChars] = 0;
2766 // make sure the string is terminated:
2767 cmdLine[numChars] = 0;
2768 // showtime!
2769 dbgsvdrp("< S %s: %s\n", *clientName, cmdLine);
2771 numChars = 0;
2772 if (length > BUFSIZ) {
2773 free(cmdLine); // let's not tie up too much memory
2774 length = BUFSIZ;
2775 cmdLine = MALLOC(char, length);
2776 }
2777 }
2778 else if (c == 0x04 && numChars == 0) {
2779 // end of file (only at beginning of line)
2780 Close(true);
2781 }
2782 else if (c == 0x08 || c == 0x7F) {
2783 // backspace or delete (last character)
2784 if (numChars > 0)
2785 numChars--;
2786 }
2787 else if (c <= 0x03 || c == 0x0D) {
2788 // ignore control characters
2789 }
2790 else {
2791 if (numChars >= length - 1) {
2792 int NewLength = length + BUFSIZ;
2793 if (char *NewBuffer = (char *)realloc(cmdLine, NewLength)) {
2794 length = NewLength;
2795 cmdLine = NewBuffer;
2796 }
2797 else {
2798 esyslog("SVDRP %s < %s ERROR: out of memory", Setup.SVDRPHostName, *clientName);
2799 Close();
2800 break;
2801 }
2802 }
2803 cmdLine[numChars++] = c;
2804 cmdLine[numChars] = 0;
2805 }
2806 lastActivity = time(NULL);
2807 }
2808 else if (r <= 0) {
2809 isyslog("SVDRP %s < %s lost connection to client", Setup.SVDRPHostName, *clientName);
2810 Close();
2811 }
2812 }
2813 if (Setup.SVDRPTimeout && time(NULL) - lastActivity > Setup.SVDRPTimeout) {
2814 isyslog("SVDRP %s < %s timeout on connection", Setup.SVDRPHostName, *clientName);
2815 Close(true, true);
2816 }
2817 }
2818 return file.IsOpen();
2819}
2820
2821void SetSVDRPPorts(int TcpPort, int UdpPort)
2822{
2823 SVDRPTcpPort = TcpPort;
2824 SVDRPUdpPort = UdpPort;
2825}
2826
2827void SetSVDRPGrabImageDir(const char *GrabImageDir)
2828{
2829 grabImageDir = GrabImageDir;
2830}
2831
2832// --- cSVDRPServerHandler ---------------------------------------------------
2833
2835private:
2836 bool ready;
2839 void HandleServerConnection(void);
2840 void ProcessConnections(void);
2841protected:
2842 virtual void Action(void) override;
2843public:
2844 cSVDRPServerHandler(int TcpPort);
2845 virtual ~cSVDRPServerHandler() override;
2846 void WaitUntilReady(void);
2847 };
2848
2850
2852:cThread("SVDRP server handler", true)
2853,tcpSocket(TcpPort, true)
2854{
2855 ready = false;
2856}
2857
2859{
2860 Cancel(3);
2861 for (int i = 0; i < serverConnections.Size(); i++)
2862 delete serverConnections[i];
2863}
2864
2866{
2867 cTimeMs Timeout(3000);
2868 while (!ready && !Timeout.TimedOut())
2870}
2871
2873{
2874 for (int i = 0; i < serverConnections.Size(); i++) {
2875 if (!serverConnections[i]->Process()) {
2877 SVDRPClientHandler->CloseClient(serverConnections[i]->ClientName());
2878 delete serverConnections[i];
2879 serverConnections.Remove(i);
2880 i--;
2881 }
2882 }
2883}
2884
2886{
2887 int NewSocket = tcpSocket.Accept();
2888 if (NewSocket >= 0)
2889 serverConnections.Append(new cSVDRPServer(NewSocket, tcpSocket.LastIpAddress()));
2890}
2891
2893{
2894 if (tcpSocket.Listen()) {
2895 SVDRPServerPoller.Add(tcpSocket.Socket(), false);
2896 ready = true;
2897 while (Running()) {
2898 SVDRPServerPoller.Poll(1000);
2901 }
2902 SVDRPServerPoller.Del(tcpSocket.Socket(), false);
2903 tcpSocket.Close();
2904 }
2905}
2906
2907// --- SVDRP Handler ---------------------------------------------------------
2908
2910
2912{
2913 cMutexLock MutexLock(&SVDRPHandlerMutex);
2914 if (SVDRPTcpPort) {
2915 if (!SVDRPServerHandler) {
2917 SVDRPServerHandler->Start();
2918 SVDRPServerHandler->WaitUntilReady();
2919 }
2920 if (Setup.SVDRPPeering && SVDRPUdpPort && !SVDRPClientHandler) {
2922 SVDRPClientHandler->Start();
2923 }
2924 }
2925}
2926
2928{
2929 cMutexLock MutexLock(&SVDRPHandlerMutex);
2930 delete SVDRPClientHandler;
2931 SVDRPClientHandler = NULL;
2932 delete SVDRPServerHandler;
2933 SVDRPServerHandler = NULL;
2934}
2935
2937{
2938 bool Result = false;
2939 cMutexLock MutexLock(&SVDRPHandlerMutex);
2941 Result = SVDRPClientHandler->GetServerNames(ServerNames);
2942 return Result;
2943}
2944
2945bool ExecSVDRPCommand(const char *ServerName, const char *Command, cStringList *Response)
2946{
2947 bool Result = false;
2948 cMutexLock MutexLock(&SVDRPHandlerMutex);
2950 Result = SVDRPClientHandler->Execute(ServerName, Command, Response);
2951 return Result;
2952}
2953
2954void BroadcastSVDRPCommand(const char *Command)
2955{
2956 cMutexLock MutexLock(&SVDRPHandlerMutex);
2957 cStringList ServerNames;
2958 if (SVDRPClientHandler) {
2959 if (SVDRPClientHandler->GetServerNames(&ServerNames)) {
2960 for (int i = 0; i < ServerNames.Size(); i++)
2961 ExecSVDRPCommand(ServerNames[i], Command);
2962 }
2963 }
2964}
#define LOCK_CHANNELS_READ
Definition channels.h:270
#define LOCK_CHANNELS_WRITE
Definition channels.h:271
const char * NextLine(void)
Returns the next line of encoded data (terminated by '\0'), or NULL if there is no more encoded data.
Definition tools.c:1456
bool Parse(const char *s)
Definition channels.c:616
static cString ToText(const cChannel *Channel)
Definition channels.c:554
int Number(void) const
Definition channels.h:179
tChannelID GetChannelID(void) const
Definition channels.h:191
static int MaxNumber(void)
Definition channels.h:249
static const char * SystemCharacterTable(void)
Definition tools.h:174
static void SleepMs(int TimeoutMs)
Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the...
Definition thread.c:73
static void Shutdown(void)
Definition player.c:99
static void Attach(void)
Definition player.c:86
static void Launch(cControl *Control)
Definition player.c:79
virtual uchar * GrabImage(int &Size, bool Jpeg=true, int Quality=-1, int SizeX=-1, int SizeY=-1)
Grabs the currently visible screen image.
Definition device.c:474
static cDevice * PrimaryDevice(void)
Returns the primary device.
Definition device.h:148
static cDevice * GetDevice(int Index)
Gets the device with the given Index.
Definition device.c:230
eTrackType GetCurrentAudioTrack(void) const
Definition device.h:593
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
Definition device.c:825
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
Definition device.h:371
const tTrackId * GetTrack(eTrackType Type)
Returns a pointer to the given track id, or NULL if Type is not less than ttMaxTrackTypes.
Definition device.c:1143
static void SetCurrentChannel(int ChannelNumber)
Sets the number of the current channel on the primary device, without actually switching to it.
Definition device.h:373
void SetVolume(int Volume, bool Absolute=false)
Sets the volume to the given value, either absolutely or relative to the current volume.
Definition device.c:1076
static int NumDevices(void)
Returns the total number of devices.
Definition device.h:129
static int CurrentVolume(void)
Definition device.h:648
bool ToggleMute(void)
Turns the volume off or on and returns the new mute state.
Definition device.c:1047
bool SetCurrentAudioTrack(eTrackType Type)
Sets the current audio track to the given Type.
Definition device.c:1168
static void SetDisableUntil(time_t Time)
Definition eit.c:508
Definition tools.h:476
const char * Connection(void) const
Definition svdrp.c:71
cString address
Definition svdrp.c:61
const char * Address(void) const
Definition svdrp.c:67
int Port(void) const
Definition svdrp.c:68
void Set(const char *Address, int Port)
Definition svdrp.c:84
cString connection
Definition svdrp.c:63
int port
Definition svdrp.c:62
cIpAddress(void)
Definition svdrp.c:74
static const char * ToString(eKeys Key, bool Translate=false)
Definition keys.c:138
static eKeys FromString(const char *Name)
Definition keys.c:123
int Count(void) const
Definition tools.h:640
cListObject * Prev(void) const
Definition tools.h:559
int Index(void) const
Definition tools.c:2114
cListObject * Next(void) const
Definition tools.h:560
bool Load(const char *RecordingFileName, double FramesPerSecond=DEFAULTFRAMESPERSECOND, bool IsPesRecording=false)
Definition recording.c:2349
bool Process(const char *s)
Definition svdrp.c:810
cPUTEhandler(void)
Definition svdrp.c:791
int status
Definition svdrp.c:781
int Status(void)
Definition svdrp.c:787
const char * Message(void)
Definition svdrp.c:788
FILE * f
Definition svdrp.c:780
const char * message
Definition svdrp.c:782
~cPUTEhandler()
Definition svdrp.c:804
static cPlugin * GetPlugin(int Index)
Definition plugin.c:470
virtual const char * Version(void)=0
const char * Name(void)
Definition plugin.h:36
virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
Definition plugin.c:131
virtual const char * Description(void)=0
virtual const char ** SVDRPHelpPages(void)
Definition plugin.c:126
cTimer * Timer(void)
Definition menu.h:261
static bool Process(cTimers *Timers, time_t t)
Definition menu.c:5888
static cRecordControl * GetRecordControl(const char *FileName)
Definition menu.c:5868
int Id(void) const
Definition recording.h:150
const char * FileName(void) const
Returns the full path name to the recording directory, including the video directory and the actual '...
Definition recording.c:1181
const char * Title(char Delimiter=' ', bool NewIndicator=false, int Level=-1) const
Definition recording.c:1199
static const cRecordings * GetRecordingsRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of recordings for read access.
Definition recording.h:265
bool Put(uint64_t Code, bool Repeat=false, bool Release=false)
Definition remote.c:124
static bool Enabled(void)
Definition remote.h:49
static bool CallPlugin(const char *Plugin)
Initiates calling the given plugin's main menu function.
Definition remote.c:151
static void SetEnabled(bool Enabled)
Definition remote.h:50
static void SetRecording(const char *FileName)
Definition menu.c:6079
static const char * NowReplaying(void)
Definition menu.c:6084
bool Save(int Index)
Definition recording.c:305
void Delete(void)
Definition recording.c:343
bool Execute(const char *ServerName, const char *Command, cStringList *Response=NULL)
Definition svdrp.c:746
void AddClient(cSVDRPServerParams &ServerParams, const char *IpAddress)
Definition svdrp.c:687
virtual ~cSVDRPClientHandler() override
Definition svdrp.c:622
void SendDiscover(void)
Definition svdrp.c:638
void ProcessConnections(void)
Definition svdrp.c:644
bool GetServerNames(cStringList *ServerNames)
Definition svdrp.c:754
void CloseClient(const char *ServerName)
Definition svdrp.c:701
cSVDRPClientHandler(int TcpPort, int UdpPort)
Definition svdrp.c:615
void HandleClientConnection(void)
Definition svdrp.c:712
cSVDRPClient * GetClientForServer(const char *ServerName)
Definition svdrp.c:629
cVector< cSVDRPClient * > clientConnections
Definition svdrp.c:596
bool TriggerFetchingTimers(const char *ServerName)
Definition svdrp.c:766
cSocket udpSocket
Definition svdrp.c:595
virtual void Action(void) override
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
Definition svdrp.c:724
int length
Definition svdrp.c:319
bool connected
Definition svdrp.c:325
int timeout
Definition svdrp.c:321
cString serverName
Definition svdrp.c:318
cIpAddress serverIpAddress
Definition svdrp.c:316
bool Connected(void) const
Definition svdrp.c:336
bool Execute(const char *Command, cStringList *Response=NULL)
Definition svdrp.c:480
cTimeMs pingTime
Definition svdrp.c:322
void Close(void)
Definition svdrp.c:372
bool HasAddress(const char *Address, int Port) const
Definition svdrp.c:381
cSocket socket
Definition svdrp.c:317
cFile file
Definition svdrp.c:323
const char * ServerName(void) const
Definition svdrp.c:331
bool Send(const char *Command)
Definition svdrp.c:386
cSVDRPClient(const char *Address, int Port, const char *ServerName, int Timeout)
Definition svdrp.c:344
int fetchFlags
Definition svdrp.c:324
bool GetRemoteTimers(cStringList &Response)
Definition svdrp.c:502
bool Process(cStringList *Response=NULL)
Definition svdrp.c:397
void SetFetchFlag(int Flag)
Definition svdrp.c:490
~cSVDRPClient()
Definition svdrp.c:365
char * input
Definition svdrp.c:320
const char * Connection(void) const
Definition svdrp.c:332
bool HasFetchFlag(int Flag)
Definition svdrp.c:495
virtual ~cSVDRPServerHandler() override
Definition svdrp.c:2858
void HandleServerConnection(void)
Definition svdrp.c:2885
virtual void Action(void) override
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
Definition svdrp.c:2892
void ProcessConnections(void)
Definition svdrp.c:2872
cSVDRPServerHandler(int TcpPort)
Definition svdrp.c:2851
void WaitUntilReady(void)
Definition svdrp.c:2865
cSocket tcpSocket
Definition svdrp.c:2837
cVector< cSVDRPServer * > serverConnections
Definition svdrp.c:2838
const char * Host(void) const
Definition svdrp.c:541
cString error
Definition svdrp.c:533
const int Timeout(void) const
Definition svdrp.c:540
const char * ApiVersion(void) const
Definition svdrp.c:539
cString apiversion
Definition svdrp.c:530
cSVDRPServerParams(const char *Params)
Definition svdrp.c:546
const char * VdrVersion(void) const
Definition svdrp.c:538
const char * Name(void) const
Definition svdrp.c:536
cString vdrversion
Definition svdrp.c:529
const char * Error(void) const
Definition svdrp.c:543
const int Port(void) const
Definition svdrp.c:537
bool Ok(void) const
Definition svdrp.c:542
void CmdMESG(const char *Option)
Definition svdrp.c:2111
const char * ClientName(void) const
Definition svdrp.c:1148
void CmdPOLL(const char *Option)
Definition svdrp.c:2513
bool Send(const char *s)
Definition svdrp.c:1194
void CmdLSTT(const char *Option)
Definition svdrp.c:2055
time_t lastActivity
Definition svdrp.c:1102
void CmdCLRE(const char *Option)
Definition svdrp.c:1367
void Reply(int Code, const char *fmt,...) __attribute__((format(printf
Definition svdrp.c:1205
void CmdGRAB(const char *Option)
Definition svdrp.c:1653
void CmdMODC(const char *Option)
Definition svdrp.c:2122
cFile file
Definition svdrp.c:1097
cPUTEhandler * PUTEhandler
Definition svdrp.c:1098
void CmdDELC(const char *Option)
Definition svdrp.c:1452
void CmdPLUG(const char *Option)
Definition svdrp.c:2442
void CmdMODT(const char *Option)
Definition svdrp.c:2158
cIpAddress clientIpAddress
Definition svdrp.c:1095
void CmdCPYR(const char *Option)
Definition svdrp.c:1517
cString clientName
Definition svdrp.c:1096
void CmdLSTC(const char *Option)
Definition svdrp.c:1857
void CmdSCAN(const char *Option)
Definition svdrp.c:2610
void Close(bool SendReply=false, bool Timeout=false)
Definition svdrp.c:1180
~cSVDRPServer()
Definition svdrp.c:1173
void CmdPUTE(const char *Option)
Definition svdrp.c:2567
void CmdLSTR(const char *Option)
Definition svdrp.c:1996
void CmdSTAT(const char *Option)
Definition svdrp.c:2616
void CmdCHAN(const char *Option)
Definition svdrp.c:1305
void CmdHELP(const char *Option)
Definition svdrp.c:1790
bool Process(void)
Definition svdrp.c:2755
void CmdUPDT(const char *Option)
Definition svdrp.c:2631
void CmdREMO(const char *Option)
Definition svdrp.c:2592
void CmdAUDI(const char *Option)
Definition svdrp.c:1266
void CmdLSTE(const char *Option)
Definition svdrp.c:1917
void CmdCONN(const char *Option)
Definition svdrp.c:1432
void CmdDELR(const char *Option)
Definition svdrp.c:1568
void Execute(char *Cmd)
Definition svdrp.c:2695
bool HasConnection(void)
Definition svdrp.c:1149
void CmdUPDR(const char *Option)
Definition svdrp.c:2664
void CmdVOLU(const char *Option)
Definition svdrp.c:2671
void CmdNEWT(const char *Option)
Definition svdrp.c:2330
void CmdEDIT(const char *Option)
Definition svdrp.c:1625
void CmdPLAY(const char *Option)
Definition svdrp.c:2383
void CmdDELT(const char *Option)
Definition svdrp.c:1598
void CmdLSTD(const char *Option)
Definition svdrp.c:1905
cSVDRPServer(int Socket, const cIpAddress *ClientIpAddress)
Definition svdrp.c:1155
void CmdNEXT(const char *Option)
Definition svdrp.c:2359
void CmdHITK(const char *Option)
Definition svdrp.c:1818
int numChars
Definition svdrp.c:1099
void CmdNEWC(const char *Option)
Definition svdrp.c:2303
void CmdPRIM(const char *Option)
Definition svdrp.c:2541
void CmdMOVR(const char *Option)
Definition svdrp.c:2259
void CmdPING(const char *Option)
Definition svdrp.c:2378
char * cmdLine
Definition svdrp.c:1101
void CmdMOVC(const char *Option)
Definition svdrp.c:2204
void void PrintHelpTopics(const char **hp)
Definition svdrp.c:1240
void Cleanup(time_t Time)
Definition epg.c:1141
void Dump(const cChannels *Channels, FILE *f, const char *Prefix="", eDumpMode DumpMode=dmAll, time_t AtTime=0) const
Definition epg.c:1152
static void Cleanup(bool Force=false)
Definition epg.c:1293
static bool Read(FILE *f=NULL)
Definition epg.c:1338
int port
Definition svdrp.c:103
void Close(void)
Definition svdrp.c:133
bool tcp
Definition svdrp.c:104
const cIpAddress * LastIpAddress(void) const
Definition svdrp.c:118
static bool SendDgram(const char *Dgram, int Port)
Definition svdrp.c:226
int Port(void) const
Definition svdrp.c:113
int Socket(void) const
Definition svdrp.c:114
cIpAddress lastIpAddress
Definition svdrp.c:106
int sock
Definition svdrp.c:105
bool Listen(void)
Definition svdrp.c:141
int Accept(void)
Definition svdrp.c:257
cString Discover(void)
Definition svdrp.c:283
cSocket(int Port, bool Tcp)
Definition svdrp.c:121
~cSocket()
Definition svdrp.c:128
bool Connect(const char *Address)
Definition svdrp.c:188
void Remove(bool IncState=true)
Removes this key from the lock it was previously used with.
Definition thread.c:870
virtual void Clear(void) override
Definition tools.c:1658
void SortNumerically(void)
Definition tools.h:866
cString & CompactChars(char c)
Compact any sequence of characters 'c' to a single character, and strip all of them from the beginnin...
Definition tools.c:1206
static cString sprintf(const char *fmt,...) __attribute__((format(printf
Definition tools.c:1212
cString & Truncate(int Index)
Truncate the string at the given Index (if Index is < 0 it is counted from the end of the string).
Definition tools.c:1196
bool Running(void)
Returns false if a derived cThread object shall leave its Action() function.
Definition thread.h:101
cThread(const char *Description=NULL, bool LowPriority=false)
Creates a new thread.
Definition thread.c:239
void Cancel(int WaitSeconds=0)
Cancels the thread by first setting 'running' to false, so that the Action() loop can finish in an or...
Definition thread.c:355
void Set(int Ms=0)
Sets the timer.
Definition tools.c:812
bool TimedOut(void) const
Returns true if the number of milliseconds given in the last call to Set() have passed.
Definition tools.c:820
void ClrFlags(uint Flags)
Definition timers.c:1125
void SetFlags(uint Flags)
Definition timers.c:1120
bool IsPatternTimer(void) const
Definition timers.h:98
cString ToDescr(void) const
Definition timers.c:333
const char * Remote(void) const
Definition timers.h:81
int Id(void) const
Definition timers.h:65
bool Parse(const char *s)
Definition timers.c:446
cString ToText(bool UseChannelID=false) const
Definition timers.c:323
bool StoreRemoteTimers(const char *ServerName=NULL, const cStringList *RemoteTimers=NULL)
Stores the given list of RemoteTimers, which come from the VDR ServerName, in this list.
Definition timers.c:1391
static cTimers * GetTimersWrite(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for write access.
Definition timers.c:1300
static const cTimers * GetTimersRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for read access.
Definition timers.c:1295
int Size(void) const
Definition tools.h:767
virtual void Append(T Data)
Definition tools.h:787
static int VideoDiskSpace(int *FreeMB=NULL, int *UsedMB=NULL)
Definition videodir.c:152
cSetup Setup
Definition config.c:372
cSVDRPhosts SVDRPhosts
Definition config.c:280
#define APIVERSNUM
Definition config.h:31
#define VDRVERSION
Definition config.h:25
#define VDRVERSNUM
Definition config.h:26
eTrackType
Definition device.h:63
@ ttDolbyLast
Definition device.h:69
@ ttAudioFirst
Definition device.h:65
#define VOLUMEDELTA
Definition device.h:33
cEITScanner EITScanner
Definition eitscan.c:104
#define LOCK_SCHEDULES_READ
Definition epg.h:228
eDumpMode
Definition epg.h:42
@ dmAtTime
Definition epg.h:42
@ dmPresent
Definition epg.h:42
@ dmFollowing
Definition epg.h:42
@ dmAll
Definition epg.h:42
#define LOCK_SCHEDULES_WRITE
Definition epg.h:229
eKeys
Definition keys.h:16
@ kNone
Definition keys.h:55
void SetTrackDescriptions(int LiveChannel)
Definition menu.c:4960
bool EnoughFreeDiskSpaceForEdit(const char *FileName)
Definition recording.c:3558
char * ExchangeChars(char *s, bool ToFileSystem)
Definition recording.c:706
int HMSFToIndex(const char *HMSF, double FramesPerSecond)
Definition recording.c:3437
cRecordingsHandler RecordingsHandler
Definition recording.c:2156
struct __attribute__((packed))
Definition recording.c:2758
@ ruCut
Definition recording.h:34
@ ruReplay
Definition recording.h:32
@ ruCopy
Definition recording.h:36
@ ruTimer
Definition recording.h:31
@ ruMove
Definition recording.h:35
#define LOCK_RECORDINGS_READ
Definition recording.h:332
#define FOLDERDELIMCHAR
Definition recording.h:22
#define LOCK_RECORDINGS_WRITE
Definition recording.h:333
cSkins Skins
Definition skins.c:253
@ mtInfo
Definition skins.h:37
tChannelID & ClrRid(void)
Definition channels.h:59
static const tChannelID InvalidID
Definition channels.h:68
static tChannelID FromString(const char *s)
Definition channels.c:23
cString ToString(void) const
Definition channels.c:40
char language[MAXLANGCODE2]
Definition device.h:82
char description[32]
Definition device.h:83
uint16_t id
Definition device.h:81
#define dbgsvdrp(a...)
Definition svdrp.c:45
static int SVDRPUdpPort
Definition svdrp.c:48
void StopSVDRPHandler(void)
Definition svdrp.c:2927
static cPoller SVDRPClientPoller
Definition svdrp.c:342
void SetSVDRPGrabImageDir(const char *GrabImageDir)
Definition svdrp.c:2827
static cString grabImageDir
Definition svdrp.c:1090
eSvdrpFetchFlags
Definition svdrp.c:50
@ sffTimers
Definition svdrp.c:54
@ sffNone
Definition svdrp.c:51
@ sffPing
Definition svdrp.c:53
@ sffConn
Definition svdrp.c:52
#define EITDISABLETIME
Definition svdrp.c:839
#define MAXHELPTOPIC
Definition svdrp.c:838
bool GetSVDRPServerNames(cStringList *ServerNames)
Gets a list of all available VDRs this VDR is connected to via SVDRP, and stores it in the given Serv...
Definition svdrp.c:2936
static int SVDRPTcpPort
Definition svdrp.c:47
static cString RecordingInUseMessage(int Reason, const char *RecordingId, cRecording *Recording)
Definition svdrp.c:1501
const char * HelpPages[]
Definition svdrp.c:842
static cMutex SVDRPHandlerMutex
Definition svdrp.c:2909
bool ExecSVDRPCommand(const char *ServerName, const char *Command, cStringList *Response)
Sends the given SVDRP Command string to the remote VDR identified by ServerName and collects all of t...
Definition svdrp.c:2945
static cPoller SVDRPServerPoller
Definition svdrp.c:1153
static cSVDRPServerHandler * SVDRPServerHandler
Definition svdrp.c:2849
void StartSVDRPHandler(void)
Definition svdrp.c:2911
cStateKey StateKeySVDRPRemoteTimersPoll(true)
#define MAXUDPBUF
Definition svdrp.c:99
void BroadcastSVDRPCommand(const char *Command)
Sends the given SVDRP Command string to all remote VDRs.
Definition svdrp.c:2954
#define SVDRPResonseTimeout
const char * GetHelpPage(const char *Cmd, const char **p)
Definition svdrp.c:1077
static cSVDRPClientHandler * SVDRPClientHandler
Definition svdrp.c:613
static bool DumpSVDRPDataTransfer
Definition svdrp.c:43
const char * GetHelpTopic(const char *HelpPage)
Definition svdrp.c:1059
#define CMD(c)
Definition svdrp.c:2693
#define SVDRPDiscoverDelta
void SetSVDRPPorts(int TcpPort, int UdpPort)
Definition svdrp.c:2821
@ spmOnly
Definition svdrp.h:19
int SVDRPCode(const char *s)
Returns the value of the three digit reply code of the given SVDRP response string.
Definition svdrp.h:47
cStateKey StateKeySVDRPRemoteTimersPoll
Controls whether a change to the local list of timers needs to result in sending a POLL to the remote...
#define LOCK_TIMERS_READ
Definition timers.h:275
#define LOCK_TIMERS_WRITE
Definition timers.h:276
@ tfActive
Definition timers.h:19
@ tfRecording
Definition timers.h:22
char * strreplace(char *s, char c1, char c2)
Definition tools.c:142
cString TimeToString(time_t t)
Converts the given time to a string of the form "www mmm dd hh:mm:ss yyyy".
Definition tools.c:1288
bool MakeDirs(const char *FileName, bool IsDirectory)
Definition tools.c:512
bool startswith(const char *s, const char *p)
Definition tools.c:337
char * strshift(char *s, int n)
Shifts the given string to the left by the given number of bytes, thus removing the first n bytes fro...
Definition tools.c:325
ssize_t safe_read(int filedes, void *buffer, size_t size)
Definition tools.c:53
cString strgetval(const char *s, const char *name, char d)
Returns the value part of a 'name=value' pair in s.
Definition tools.c:303
ssize_t safe_write(int filedes, const void *buffer, size_t size)
Definition tools.c:65
bool isnumber(const char *s)
Definition tools.c:372
cString AddDirectory(const char *DirName, const char *FileName)
Definition tools.c:415
#define FATALERRNO
Definition tools.h:52
#define LOG_ERROR_STR(s)
Definition tools.h:40
unsigned char uchar
Definition tools.h:31
#define dsyslog(a...)
Definition tools.h:37
#define MALLOC(type, size)
Definition tools.h:47
char * skipspace(const char *s)
Definition tools.h:244
void DELETENULL(T *&p)
Definition tools.h:49
#define esyslog(a...)
Definition tools.h:35
#define LOG_ERROR
Definition tools.h:39
#define isyslog(a...)
Definition tools.h:36