2000-07-23 15:01:31 +02:00
|
|
|
/*
|
|
|
|
* svdrp.c: Simple Video Disk Recorder Protocol
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
|
|
|
* The "Simple Video Disk Recorder Protocol" (SVDRP) was inspired
|
|
|
|
* by the "Simple Mail Transfer Protocol" (SMTP) and is fully ASCII
|
|
|
|
* text based. Therefore you can simply 'telnet' to your VDR port
|
|
|
|
* and interact with the Video Disk Recorder - or write a full featured
|
|
|
|
* graphical interface that sits on top of an SVDRP connection.
|
|
|
|
*
|
2011-02-25 15:25:42 +01:00
|
|
|
* $Id: svdrp.c 2.9 2011/02/25 14:38:45 kls Exp $
|
2000-07-23 15:01:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "svdrp.h"
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <ctype.h>
|
2000-12-08 16:23:32 +01:00
|
|
|
#include <errno.h>
|
2000-07-23 15:01:31 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
2002-10-06 10:25:42 +02:00
|
|
|
#include "channels.h"
|
2000-07-23 15:01:31 +02:00
|
|
|
#include "config.h"
|
2005-08-28 14:18:24 +02:00
|
|
|
#include "cutter.h"
|
2002-06-16 12:57:31 +02:00
|
|
|
#include "device.h"
|
2004-01-17 15:41:52 +01:00
|
|
|
#include "eitscan.h"
|
2002-09-29 13:40:45 +02:00
|
|
|
#include "keys.h"
|
2005-05-26 10:00:59 +02:00
|
|
|
#include "menu.h"
|
2005-08-27 16:42:28 +02:00
|
|
|
#include "plugin.h"
|
2002-09-29 13:40:45 +02:00
|
|
|
#include "remote.h"
|
2005-11-27 15:57:03 +01:00
|
|
|
#include "skins.h"
|
2002-10-20 12:28:55 +02:00
|
|
|
#include "timers.h"
|
2000-07-23 15:01:31 +02:00
|
|
|
#include "tools.h"
|
2003-04-27 14:23:30 +02:00
|
|
|
#include "videodir.h"
|
2000-07-23 15:01:31 +02:00
|
|
|
|
|
|
|
// --- cSocket ---------------------------------------------------------------
|
|
|
|
|
|
|
|
cSocket::cSocket(int Port, int Queue)
|
|
|
|
{
|
|
|
|
port = Port;
|
|
|
|
sock = -1;
|
2002-08-11 13:32:23 +02:00
|
|
|
queue = Queue;
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cSocket::~cSocket()
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSocket::Close(void)
|
|
|
|
{
|
|
|
|
if (sock >= 0) {
|
|
|
|
close(sock);
|
|
|
|
sock = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cSocket::Open(void)
|
|
|
|
{
|
|
|
|
if (sock < 0) {
|
|
|
|
// create socket:
|
|
|
|
sock = socket(PF_INET, SOCK_STREAM, 0);
|
|
|
|
if (sock < 0) {
|
|
|
|
LOG_ERROR;
|
|
|
|
port = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2001-02-18 14:18:13 +01:00
|
|
|
// allow it to always reuse the same port:
|
|
|
|
int ReUseAddr = 1;
|
|
|
|
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &ReUseAddr, sizeof(ReUseAddr));
|
|
|
|
//
|
2000-07-23 15:01:31 +02:00
|
|
|
struct sockaddr_in name;
|
|
|
|
name.sin_family = AF_INET;
|
|
|
|
name.sin_port = htons(port);
|
2010-01-17 12:27:01 +01:00
|
|
|
name.sin_addr.s_addr = SVDRPhosts.LocalhostOnly() ? htonl(INADDR_LOOPBACK) : htonl(INADDR_ANY);
|
2000-07-23 15:01:31 +02:00
|
|
|
if (bind(sock, (struct sockaddr *)&name, sizeof(name)) < 0) {
|
|
|
|
LOG_ERROR;
|
|
|
|
Close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// make it non-blocking:
|
|
|
|
int oldflags = fcntl(sock, F_GETFL, 0);
|
|
|
|
if (oldflags < 0) {
|
|
|
|
LOG_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
oldflags |= O_NONBLOCK;
|
|
|
|
if (fcntl(sock, F_SETFL, oldflags) < 0) {
|
|
|
|
LOG_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// listen to the socket:
|
|
|
|
if (listen(sock, queue) < 0) {
|
|
|
|
LOG_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cSocket::Accept(void)
|
|
|
|
{
|
|
|
|
if (Open()) {
|
|
|
|
struct sockaddr_in clientname;
|
|
|
|
uint size = sizeof(clientname);
|
|
|
|
int newsock = accept(sock, (struct sockaddr *)&clientname, &size);
|
2002-02-02 17:20:54 +01:00
|
|
|
if (newsock > 0) {
|
|
|
|
bool accepted = SVDRPhosts.Acceptable(clientname.sin_addr.s_addr);
|
|
|
|
if (!accepted) {
|
|
|
|
const char *s = "Access denied!\n";
|
2005-03-20 10:10:38 +01:00
|
|
|
if (write(newsock, s, strlen(s)) < 0)
|
|
|
|
LOG_ERROR;
|
2002-02-02 17:20:54 +01:00
|
|
|
close(newsock);
|
|
|
|
newsock = -1;
|
|
|
|
}
|
2006-08-12 09:12:34 +02:00
|
|
|
isyslog("connect from %s, port %hu - %s", inet_ntoa(clientname.sin_addr), ntohs(clientname.sin_port), accepted ? "accepted" : "DENIED");
|
2002-02-02 17:20:54 +01:00
|
|
|
}
|
2002-02-02 13:44:24 +01:00
|
|
|
else if (errno != EINTR && errno != EAGAIN)
|
2000-07-23 15:01:31 +02:00
|
|
|
LOG_ERROR;
|
|
|
|
return newsock;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-02-24 11:13:21 +01:00
|
|
|
// --- cPUTEhandler ----------------------------------------------------------
|
|
|
|
|
|
|
|
cPUTEhandler::cPUTEhandler(void)
|
|
|
|
{
|
|
|
|
if ((f = tmpfile()) != NULL) {
|
|
|
|
status = 354;
|
|
|
|
message = "Enter EPG data, end with \".\" on a line by itself";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG_ERROR;
|
|
|
|
status = 554;
|
|
|
|
message = "Error while opening temporary file";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cPUTEhandler::~cPUTEhandler()
|
|
|
|
{
|
|
|
|
if (f)
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cPUTEhandler::Process(const char *s)
|
|
|
|
{
|
|
|
|
if (f) {
|
|
|
|
if (strcmp(s, ".") != 0) {
|
|
|
|
fputs(s, f);
|
|
|
|
fputc('\n', f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rewind(f);
|
|
|
|
if (cSchedules::Read(f)) {
|
2003-12-22 13:29:24 +01:00
|
|
|
cSchedules::Cleanup(true);
|
2002-02-24 11:13:21 +01:00
|
|
|
status = 250;
|
|
|
|
message = "EPG data processed";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
status = 451;
|
|
|
|
message = "Error while processing EPG data";
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
f = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
// --- cSVDRP ----------------------------------------------------------------
|
|
|
|
|
|
|
|
#define MAXHELPTOPIC 10
|
2010-01-03 15:45:23 +01:00
|
|
|
#define EITDISABLETIME 10 // seconds until EIT processing is enabled again after a CLRE command
|
|
|
|
// adjust the help for CLRE accordingly if changing this!
|
2000-07-23 15:01:31 +02:00
|
|
|
|
|
|
|
const char *HelpPages[] = {
|
2002-12-22 14:07:51 +01:00
|
|
|
"CHAN [ + | - | <number> | <name> | <id> ]\n"
|
|
|
|
" Switch channel up, down or to the given channel number, name or id.\n"
|
2000-07-23 15:01:31 +02:00
|
|
|
" Without option (or after successfully switching to the channel)\n"
|
|
|
|
" it returns the current channel number and name.",
|
2008-01-13 15:06:25 +01:00
|
|
|
"CLRE [ <number> | <name> | <id> ]\n"
|
|
|
|
" Clear the EPG list of the given channel number, name or id.\n"
|
2010-01-03 15:45:23 +01:00
|
|
|
" Without option it clears the entire EPG list.\n"
|
|
|
|
" After a CLRE command, no further EPG processing is done for 10\n"
|
|
|
|
" seconds, so that data sent with subsequent PUTE commands doesn't\n"
|
|
|
|
" interfere with data from the broadcasters.",
|
2000-07-23 15:01:31 +02:00
|
|
|
"DELC <number>\n"
|
|
|
|
" Delete channel.",
|
2001-10-27 11:47:46 +02:00
|
|
|
"DELR <number>\n"
|
|
|
|
" Delete the recording with the given number. Before a recording can be\n"
|
|
|
|
" deleted, an LSTR command must have been executed in order to retrieve\n"
|
|
|
|
" the recording numbers. The numbers don't change during subsequent DELR\n"
|
|
|
|
" commands. CAUTION: THERE IS NO CONFIRMATION PROMPT WHEN DELETING A\n"
|
|
|
|
" RECORDING - BE SURE YOU KNOW WHAT YOU ARE DOING!",
|
2000-07-23 15:01:31 +02:00
|
|
|
"DELT <number>\n"
|
|
|
|
" Delete timer.",
|
2005-08-28 14:18:24 +02:00
|
|
|
"EDIT <number>\n"
|
|
|
|
" Edit the recording with the given number. Before a recording can be\n"
|
|
|
|
" edited, an LSTR command must have been executed in order to retrieve\n"
|
|
|
|
" the recording numbers.",
|
2005-12-29 12:18:27 +01:00
|
|
|
"GRAB <filename> [ <quality> [ <sizex> <sizey> ] ]\n"
|
2000-09-17 11:53:35 +02:00
|
|
|
" Grab the current frame and save it to the given file. Images can\n"
|
2005-12-29 12:18:27 +01:00
|
|
|
" be stored as JPEG or PNM, depending on the given file name extension.\n"
|
2005-12-30 10:27:23 +01:00
|
|
|
" The quality of the grabbed image can be in the range 0..100, where 100\n"
|
|
|
|
" (the default) means \"best\" (only applies to JPEG). The size parameters\n"
|
|
|
|
" define the size of the resulting image (default is full screen).\n"
|
|
|
|
" If the file name is just an extension (.jpg, .jpeg or .pnm) the image\n"
|
|
|
|
" data will be sent to the SVDRP connection encoded in base64. The same\n"
|
|
|
|
" happens if '-' (a minus sign) is given as file name, in which case the\n"
|
|
|
|
" image format defaults to JPEG.",
|
2000-07-23 15:01:31 +02:00
|
|
|
"HELP [ <topic> ]\n"
|
|
|
|
" The HELP command gives help info.",
|
2000-09-17 09:36:50 +02:00
|
|
|
"HITK [ <key> ]\n"
|
|
|
|
" Hit the given remote control key. Without option a list of all\n"
|
|
|
|
" valid key names is given.",
|
2007-08-25 09:31:13 +02:00
|
|
|
"LSTC [ :groups | <number> | <name> ]\n"
|
2000-07-23 15:01:31 +02:00
|
|
|
" List channels. Without option, all channels are listed. Otherwise\n"
|
|
|
|
" only the given channel is listed. If a name is given, all channels\n"
|
2007-08-25 09:31:13 +02:00
|
|
|
" containing the given string as part of their name are listed.\n"
|
|
|
|
" If ':groups' is given, all channels are listed including group\n"
|
|
|
|
" separators. The channel number of a group separator is always 0.",
|
2004-02-22 15:36:36 +01:00
|
|
|
"LSTE [ <channel> ] [ now | next | at <time> ]\n"
|
|
|
|
" List EPG data. Without any parameters all data of all channels is\n"
|
2005-08-07 14:25:31 +02:00
|
|
|
" listed. If a channel is given (either by number or by channel ID),\n"
|
2004-02-22 15:36:36 +01:00
|
|
|
" only data for that channel is listed. 'now', 'next', or 'at <time>'\n"
|
|
|
|
" restricts the returned data to present events, following events, or\n"
|
2004-03-25 17:01:03 +01:00
|
|
|
" events at the given time (which must be in time_t form).",
|
2001-10-27 11:47:46 +02:00
|
|
|
"LSTR [ <number> ]\n"
|
|
|
|
" List recordings. Without option, all recordings are listed. Otherwise\n"
|
2005-05-16 14:45:11 +02:00
|
|
|
" the information for the given recording is listed.",
|
2006-01-08 13:33:57 +01:00
|
|
|
"LSTT [ <number> ] [ id ]\n"
|
2000-07-23 15:01:31 +02:00
|
|
|
" List timers. Without option, all timers are listed. Otherwise\n"
|
2006-01-08 13:33:57 +01:00
|
|
|
" only the given timer is listed. If the keyword 'id' is given, the\n"
|
|
|
|
" channels will be listed with their unique channel ids instead of\n"
|
|
|
|
" their numbers.",
|
2005-11-27 15:57:03 +01:00
|
|
|
"MESG <message>\n"
|
|
|
|
" Displays the given message on the OSD. The message will be queued\n"
|
|
|
|
" and displayed whenever this is suitable.\n",
|
2000-07-23 15:01:31 +02:00
|
|
|
"MODC <number> <settings>\n"
|
|
|
|
" Modify a channel. Settings must be in the same format as returned\n"
|
|
|
|
" by the LSTC command.",
|
|
|
|
"MODT <number> on | off | <settings>\n"
|
|
|
|
" Modify a timer. Settings must be in the same format as returned\n"
|
|
|
|
" by the LSTT command. The special keywords 'on' and 'off' can be\n"
|
|
|
|
" used to easily activate or deactivate a timer.",
|
|
|
|
"MOVC <number> <to>\n"
|
|
|
|
" Move a channel to a new position.",
|
|
|
|
"MOVT <number> <to>\n"
|
|
|
|
" Move a timer to a new position.",
|
|
|
|
"NEWC <settings>\n"
|
|
|
|
" Create a new channel. Settings must be in the same format as returned\n"
|
|
|
|
" by the LSTC command.",
|
|
|
|
"NEWT <settings>\n"
|
|
|
|
" Create a new timer. Settings must be in the same format as returned\n"
|
2000-08-06 12:56:49 +02:00
|
|
|
" by the LSTT command. It is an error if a timer with the same channel,\n"
|
|
|
|
" day, start and stop time already exists.",
|
2001-09-01 09:53:01 +02:00
|
|
|
"NEXT [ abs | rel ]\n"
|
|
|
|
" Show the next timer event. If no option is given, the output will be\n"
|
|
|
|
" in human readable form. With option 'abs' the absolute time of the next\n"
|
|
|
|
" event will be given as the number of seconds since the epoch (time_t\n"
|
|
|
|
" format), while with option 'rel' the relative time will be given as the\n"
|
|
|
|
" number of seconds from now until the event. If the absolute time given\n"
|
|
|
|
" is smaller than the current time, or if the relative time is less than\n"
|
|
|
|
" zero, this means that the timer is currently recording and has started\n"
|
|
|
|
" at the given time. The first value in the resulting line is the number\n"
|
|
|
|
" of the timer.",
|
2005-08-28 10:45:19 +02:00
|
|
|
"PLAY <number> [ begin | <position> ]\n"
|
|
|
|
" Play the recording with the given number. Before a recording can be\n"
|
|
|
|
" played, an LSTR command must have been executed in order to retrieve\n"
|
|
|
|
" the recording numbers.\n"
|
|
|
|
" The keyword 'begin' plays the recording from its very beginning, while\n"
|
|
|
|
" a <position> (given as hh:mm:ss[.ff] or framenumber) starts at that\n"
|
|
|
|
" position. If neither 'begin' nor a <position> are given, replay is resumed\n"
|
|
|
|
" at the position where any previous replay was stopped, or from the beginning\n"
|
|
|
|
" by default. To control or stop the replay session, use the usual remote\n"
|
|
|
|
" control keypresses via the HITK command.",
|
2005-09-03 12:49:36 +02:00
|
|
|
"PLUG <name> [ help | main ] [ <command> [ <options> ]]\n"
|
2005-08-27 16:42:28 +02:00
|
|
|
" Send a command to a plugin.\n"
|
|
|
|
" The PLUG command without any parameters lists all plugins.\n"
|
|
|
|
" If only a name is given, all commands known to that plugin are listed.\n"
|
|
|
|
" If a command is given (optionally followed by parameters), that command\n"
|
2005-09-03 12:20:24 +02:00
|
|
|
" is sent to the plugin, and the result will be displayed.\n"
|
|
|
|
" The keyword 'help' lists all the SVDRP commands known to the named plugin.\n"
|
|
|
|
" If 'help' is followed by a command, the detailed help for that command is\n"
|
2005-09-03 12:49:36 +02:00
|
|
|
" given. The keyword 'main' initiates a call to the main menu function of the\n"
|
|
|
|
" given plugin.\n",
|
2009-04-13 13:35:29 +02:00
|
|
|
"PUTE [ file ]\n"
|
2002-02-24 11:13:21 +01:00
|
|
|
" Put data into the EPG list. The data entered has to strictly follow the\n"
|
2002-05-10 15:08:51 +02:00
|
|
|
" format defined in vdr(5) for the 'epg.data' file. A '.' on a line\n"
|
2002-02-24 11:13:21 +01:00
|
|
|
" by itself terminates the input and starts processing of the data (all\n"
|
2009-04-13 13:35:29 +02:00
|
|
|
" entered data is buffered until the terminating '.' is seen).\n"
|
|
|
|
" If a file name is given, epg data will be read from this file (which\n"
|
|
|
|
" must be accessible under the given name from the machine VDR is running\n"
|
|
|
|
" on). In case of file input, no terminating '.' shall be given.\n",
|
2007-04-30 12:53:35 +02:00
|
|
|
"REMO [ on | off ]\n"
|
|
|
|
" Turns the remote control on or off. Without a parameter, the current\n"
|
|
|
|
" status of the remote control is reported.",
|
2004-01-17 15:41:52 +01:00
|
|
|
"SCAN\n"
|
|
|
|
" Forces an EPG scan. If this is a single DVB device system, the scan\n"
|
|
|
|
" will be done on the primary device unless it is currently recording.",
|
2003-04-27 14:23:30 +02:00
|
|
|
"STAT disk\n"
|
|
|
|
" Return information about disk usage (total, free, percent).",
|
2000-08-06 12:56:49 +02:00
|
|
|
"UPDT <settings>\n"
|
|
|
|
" Updates a timer. Settings must be in the same format as returned\n"
|
|
|
|
" by the LSTT command. If a timer with the same channel, day, start\n"
|
|
|
|
" and stop time does not yet exists, it will be created.",
|
2002-03-09 10:07:40 +01:00
|
|
|
"VOLU [ <number> | + | - | mute ]\n"
|
|
|
|
" Set the audio volume to the given number (which is limited to the range\n"
|
|
|
|
" 0...255). If the special options '+' or '-' are given, the volume will\n"
|
|
|
|
" be turned up or down, respectively. The option 'mute' will toggle the\n"
|
|
|
|
" audio muting. If no option is given, the current audio volume level will\n"
|
|
|
|
" be returned.",
|
2000-07-23 15:01:31 +02:00
|
|
|
"QUIT\n"
|
|
|
|
" Exit vdr (SVDRP).\n"
|
|
|
|
" You can also hit Ctrl-D to exit.",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* SVDRP Reply Codes:
|
|
|
|
|
|
|
|
214 Help message
|
2005-05-16 14:45:11 +02:00
|
|
|
215 EPG or recording data record
|
2005-12-30 10:27:23 +01:00
|
|
|
216 Image grab data (base 64)
|
2000-07-23 15:01:31 +02:00
|
|
|
220 VDR service ready
|
|
|
|
221 VDR service closing transmission channel
|
|
|
|
250 Requested VDR action okay, completed
|
2002-02-24 11:13:21 +01:00
|
|
|
354 Start sending EPG data
|
2000-07-23 15:01:31 +02:00
|
|
|
451 Requested action aborted: local error in processing
|
|
|
|
500 Syntax error, command unrecognized
|
|
|
|
501 Syntax error in parameters or arguments
|
|
|
|
502 Command not implemented
|
|
|
|
504 Command parameter not implemented
|
|
|
|
550 Requested action not taken
|
|
|
|
554 Transaction failed
|
2005-08-27 16:42:28 +02:00
|
|
|
900 Default plugin reply code
|
|
|
|
901..999 Plugin specific reply codes
|
2000-07-23 15:01:31 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *GetHelpTopic(const char *HelpPage)
|
|
|
|
{
|
|
|
|
static char topic[MAXHELPTOPIC];
|
|
|
|
const char *q = HelpPage;
|
|
|
|
while (*q) {
|
|
|
|
if (isspace(*q)) {
|
|
|
|
uint n = q - HelpPage;
|
|
|
|
if (n >= sizeof(topic))
|
|
|
|
n = sizeof(topic) - 1;
|
|
|
|
strncpy(topic, HelpPage, n);
|
|
|
|
topic[n] = 0;
|
|
|
|
return topic;
|
|
|
|
}
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-27 16:42:28 +02:00
|
|
|
const char *GetHelpPage(const char *Cmd, const char **p)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
2005-08-27 16:42:28 +02:00
|
|
|
if (p) {
|
|
|
|
while (*p) {
|
|
|
|
const char *t = GetHelpTopic(*p);
|
|
|
|
if (strcasecmp(Cmd, t) == 0)
|
|
|
|
return *p;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2000-07-23 15:01:31 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-12-30 15:11:16 +01:00
|
|
|
char *cSVDRP::grabImageDir = NULL;
|
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
cSVDRP::cSVDRP(int Port)
|
|
|
|
:socket(Port)
|
|
|
|
{
|
2002-02-24 11:13:21 +01:00
|
|
|
PUTEhandler = NULL;
|
2001-04-01 14:13:42 +02:00
|
|
|
numChars = 0;
|
2005-11-05 11:21:38 +01:00
|
|
|
length = BUFSIZ;
|
|
|
|
cmdLine = MALLOC(char, length);
|
2001-02-18 14:18:13 +01:00
|
|
|
lastActivity = 0;
|
2002-05-13 16:35:49 +02:00
|
|
|
isyslog("SVDRP listening on port %d", Port);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cSVDRP::~cSVDRP()
|
|
|
|
{
|
2006-08-06 09:20:04 +02:00
|
|
|
Close(true);
|
2005-11-05 11:21:38 +01:00
|
|
|
free(cmdLine);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
2006-08-06 09:20:04 +02:00
|
|
|
void cSVDRP::Close(bool SendReply, bool Timeout)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
2000-09-17 08:23:46 +02:00
|
|
|
if (file.IsOpen()) {
|
2006-08-06 09:20:04 +02:00
|
|
|
if (SendReply) {
|
|
|
|
//TODO how can we get the *full* hostname?
|
|
|
|
char buffer[BUFSIZ];
|
|
|
|
gethostname(buffer, sizeof(buffer));
|
|
|
|
Reply(221, "%s closing connection%s", buffer, Timeout ? " (timeout)" : "");
|
|
|
|
}
|
2002-05-13 16:35:49 +02:00
|
|
|
isyslog("closing SVDRP connection"); //TODO store IP#???
|
2000-09-17 08:23:46 +02:00
|
|
|
file.Close();
|
2002-02-24 11:13:21 +01:00
|
|
|
DELETENULL(PUTEhandler);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cSVDRP::Send(const char *s, int length)
|
|
|
|
{
|
|
|
|
if (length < 0)
|
|
|
|
length = strlen(s);
|
2002-03-23 16:17:39 +01:00
|
|
|
if (safe_write(file, s, length) < 0) {
|
2000-07-23 15:01:31 +02:00
|
|
|
LOG_ERROR;
|
2006-08-06 09:20:04 +02:00
|
|
|
Close();
|
2002-03-23 16:17:39 +01:00
|
|
|
return false;
|
2000-09-17 13:47:06 +02:00
|
|
|
}
|
2002-03-23 16:17:39 +01:00
|
|
|
return true;
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cSVDRP::Reply(int Code, const char *fmt, ...)
|
|
|
|
{
|
2000-09-17 08:23:46 +02:00
|
|
|
if (file.IsOpen()) {
|
2000-07-23 15:01:31 +02:00
|
|
|
if (Code != 0) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2008-02-15 14:57:48 +01:00
|
|
|
cString buffer = cString::sprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
2000-07-23 15:01:31 +02:00
|
|
|
const char *s = buffer;
|
|
|
|
while (s && *s) {
|
|
|
|
const char *n = strchr(s, '\n');
|
2005-08-27 16:42:28 +02:00
|
|
|
char cont = ' ';
|
|
|
|
if (Code < 0 || n && *(n + 1)) // trailing newlines don't count!
|
|
|
|
cont = '-';
|
|
|
|
char number[16];
|
|
|
|
sprintf(number, "%03d%c", abs(Code), cont);
|
2006-08-06 09:20:04 +02:00
|
|
|
if (!(Send(number) && Send(s, n ? n - s : -1) && Send("\r\n")))
|
2000-07-23 15:01:31 +02:00
|
|
|
break;
|
|
|
|
s = n ? n + 1 : NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(451, "Zero return code - looks like a programming error!");
|
2002-05-13 16:35:49 +02:00
|
|
|
esyslog("SVDRP: zero return code!");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-27 16:42:28 +02:00
|
|
|
void cSVDRP::PrintHelpTopics(const char **hp)
|
|
|
|
{
|
|
|
|
int NumPages = 0;
|
|
|
|
if (hp) {
|
|
|
|
while (*hp) {
|
|
|
|
NumPages++;
|
|
|
|
hp++;
|
|
|
|
}
|
|
|
|
hp -= NumPages;
|
|
|
|
}
|
|
|
|
const int TopicsPerLine = 5;
|
|
|
|
int x = 0;
|
|
|
|
for (int y = 0; (y * TopicsPerLine + x) < NumPages; y++) {
|
|
|
|
char buffer[TopicsPerLine * MAXHELPTOPIC + 5];
|
|
|
|
char *q = buffer;
|
|
|
|
q += sprintf(q, " ");
|
|
|
|
for (x = 0; x < TopicsPerLine && (y * TopicsPerLine + x) < NumPages; x++) {
|
|
|
|
const char *topic = GetHelpTopic(hp[(y * TopicsPerLine + x)]);
|
|
|
|
if (topic)
|
|
|
|
q += sprintf(q, "%*s", -MAXHELPTOPIC, topic);
|
|
|
|
}
|
|
|
|
x = 0;
|
2006-03-26 09:27:30 +02:00
|
|
|
Reply(-214, "%s", buffer);
|
2005-08-27 16:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdCHAN(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
int n = -1;
|
2002-09-08 11:46:53 +02:00
|
|
|
int d = 0;
|
2000-07-23 15:01:31 +02:00
|
|
|
if (isnumber(Option)) {
|
2000-09-09 14:57:43 +02:00
|
|
|
int o = strtol(Option, NULL, 10);
|
|
|
|
if (o >= 1 && o <= Channels.MaxNumber())
|
2000-07-23 15:01:31 +02:00
|
|
|
n = o;
|
|
|
|
}
|
|
|
|
else if (strcmp(Option, "-") == 0) {
|
2002-06-16 12:57:31 +02:00
|
|
|
n = cDevice::CurrentChannel();
|
2002-09-08 11:46:53 +02:00
|
|
|
if (n > 1) {
|
2000-07-23 15:01:31 +02:00
|
|
|
n--;
|
2002-09-08 11:46:53 +02:00
|
|
|
d = -1;
|
|
|
|
}
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else if (strcmp(Option, "+") == 0) {
|
2002-06-16 12:57:31 +02:00
|
|
|
n = cDevice::CurrentChannel();
|
2002-09-08 11:46:53 +02:00
|
|
|
if (n < Channels.MaxNumber()) {
|
2000-07-23 15:01:31 +02:00
|
|
|
n++;
|
2002-09-08 11:46:53 +02:00
|
|
|
d = 1;
|
|
|
|
}
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else {
|
2002-12-22 14:07:51 +01:00
|
|
|
cChannel *channel = Channels.GetByChannelID(tChannelID::FromString(Option));
|
|
|
|
if (channel)
|
|
|
|
n = channel->Number();
|
|
|
|
else {
|
2007-06-23 13:24:00 +02:00
|
|
|
for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) {
|
|
|
|
if (!channel->GroupSep()) {
|
|
|
|
if (strcasecmp(channel->Name(), Option) == 0) {
|
|
|
|
n = channel->Number();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-12-22 14:07:51 +01:00
|
|
|
}
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
if (n < 0) {
|
|
|
|
Reply(501, "Undefined channel \"%s\"", Option);
|
|
|
|
return;
|
|
|
|
}
|
2002-09-08 11:46:53 +02:00
|
|
|
if (!d) {
|
|
|
|
cChannel *channel = Channels.GetByNumber(n);
|
|
|
|
if (channel) {
|
|
|
|
if (!cDevice::PrimaryDevice()->SwitchChannel(channel, true)) {
|
2002-10-06 10:25:42 +02:00
|
|
|
Reply(554, "Error switching to channel \"%d\"", channel->Number());
|
2002-09-08 11:46:53 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(550, "Unable to find channel \"%s\"", Option);
|
2000-07-23 15:01:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-09-08 11:46:53 +02:00
|
|
|
else
|
|
|
|
cDevice::SwitchChannel(d);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
cChannel *channel = Channels.GetByNumber(cDevice::CurrentChannel());
|
2000-07-23 15:01:31 +02:00
|
|
|
if (channel)
|
2002-10-06 10:25:42 +02:00
|
|
|
Reply(250, "%d %s", channel->Number(), channel->Name());
|
2000-07-23 15:01:31 +02:00
|
|
|
else
|
2002-06-16 12:57:31 +02:00
|
|
|
Reply(550, "Unable to find channel \"%d\"", cDevice::CurrentChannel());
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
2002-08-25 10:49:02 +02:00
|
|
|
void cSVDRP::CmdCLRE(const char *Option)
|
|
|
|
{
|
2008-01-13 15:06:25 +01:00
|
|
|
if (*Option) {
|
|
|
|
tChannelID ChannelID = tChannelID::InvalidID;
|
|
|
|
if (isnumber(Option)) {
|
|
|
|
int o = strtol(Option, NULL, 10);
|
|
|
|
if (o >= 1 && o <= Channels.MaxNumber())
|
|
|
|
ChannelID = Channels.GetByNumber(o)->GetChannelID();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ChannelID = tChannelID::FromString(Option);
|
|
|
|
if (ChannelID == tChannelID::InvalidID) {
|
|
|
|
for (cChannel *Channel = Channels.First(); Channel; Channel = Channels.Next(Channel)) {
|
|
|
|
if (!Channel->GroupSep()) {
|
|
|
|
if (strcasecmp(Channel->Name(), Option) == 0) {
|
|
|
|
ChannelID = Channel->GetChannelID();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(ChannelID == tChannelID::InvalidID)) {
|
|
|
|
cSchedulesLock SchedulesLock(true, 1000);
|
|
|
|
cSchedules *s = (cSchedules *)cSchedules::Schedules(SchedulesLock);
|
|
|
|
if (s) {
|
|
|
|
cSchedule *Schedule = NULL;
|
|
|
|
ChannelID.ClrRid();
|
|
|
|
for (cSchedule *p = s->First(); p; p = s->Next(p)) {
|
|
|
|
if (p->ChannelID() == ChannelID) {
|
|
|
|
Schedule = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Schedule) {
|
|
|
|
Schedule->Cleanup(INT_MAX);
|
2010-01-03 15:45:23 +01:00
|
|
|
cEitFilter::SetDisableUntil(time(NULL) + EITDISABLETIME);
|
2008-01-13 15:06:25 +01:00
|
|
|
Reply(250, "EPG data of channel \"%s\" cleared", Option);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(550, "No EPG data found for channel \"%s\"", Option);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(451, "Can't get EPG data");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Undefined channel \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cSchedules::ClearAll();
|
2010-01-03 15:45:23 +01:00
|
|
|
cEitFilter::SetDisableUntil(time(NULL) + EITDISABLETIME);
|
2008-01-13 15:06:25 +01:00
|
|
|
Reply(250, "EPG data cleared");
|
|
|
|
}
|
2002-08-25 10:49:02 +02:00
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdDELC(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
2003-08-31 11:26:46 +02:00
|
|
|
if (*Option) {
|
|
|
|
if (isnumber(Option)) {
|
2005-07-31 14:34:38 +02:00
|
|
|
if (!Channels.BeingEdited()) {
|
|
|
|
cChannel *channel = Channels.GetByNumber(strtol(Option, NULL, 10));
|
|
|
|
if (channel) {
|
|
|
|
for (cTimer *timer = Timers.First(); timer; timer = Timers.Next(timer)) {
|
|
|
|
if (timer->Channel() == channel) {
|
|
|
|
Reply(550, "Channel \"%s\" is in use by timer %d", Option, timer->Index() + 1);
|
|
|
|
return;
|
|
|
|
}
|
2003-08-31 11:26:46 +02:00
|
|
|
}
|
2006-06-03 09:25:13 +02:00
|
|
|
int CurrentChannelNr = cDevice::CurrentChannel();
|
|
|
|
cChannel *CurrentChannel = Channels.GetByNumber(CurrentChannelNr);
|
|
|
|
if (CurrentChannel && channel == CurrentChannel) {
|
|
|
|
int n = Channels.GetNextNormal(CurrentChannel->Index());
|
|
|
|
if (n < 0)
|
|
|
|
n = Channels.GetPrevNormal(CurrentChannel->Index());
|
|
|
|
CurrentChannel = Channels.Get(n);
|
|
|
|
CurrentChannelNr = 0; // triggers channel switch below
|
|
|
|
}
|
2005-07-31 14:34:38 +02:00
|
|
|
Channels.Del(channel);
|
|
|
|
Channels.ReNumber();
|
|
|
|
Channels.SetModified(true);
|
|
|
|
isyslog("channel %s deleted", Option);
|
2006-06-03 09:25:13 +02:00
|
|
|
if (CurrentChannel && CurrentChannel->Number() != CurrentChannelNr) {
|
|
|
|
if (!cDevice::PrimaryDevice()->Replaying() || cDevice::PrimaryDevice()->Transferring())
|
|
|
|
Channels.SwitchTo(CurrentChannel->Number());
|
|
|
|
else
|
|
|
|
cDevice::SetCurrentChannel(CurrentChannel);
|
|
|
|
}
|
2005-07-31 14:34:38 +02:00
|
|
|
Reply(250, "Channel \"%s\" deleted", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Channel \"%s\" not defined", Option);
|
2003-08-31 11:26:46 +02:00
|
|
|
}
|
|
|
|
else
|
2005-07-31 14:34:38 +02:00
|
|
|
Reply(550, "Channels are being edited - try again later");
|
2003-08-31 11:26:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in channel number \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing channel number");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
2001-10-27 11:47:46 +02:00
|
|
|
void cSVDRP::CmdDELR(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
if (isnumber(Option)) {
|
|
|
|
cRecording *recording = Recordings.Get(strtol(Option, NULL, 10) - 1);
|
|
|
|
if (recording) {
|
2005-05-26 10:00:59 +02:00
|
|
|
cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
|
|
|
|
if (!rc) {
|
|
|
|
if (recording->Delete()) {
|
|
|
|
Reply(250, "Recording \"%s\" deleted", Option);
|
2005-09-18 10:51:54 +02:00
|
|
|
::Recordings.DelByName(recording->FileName());
|
2005-05-26 10:00:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(554, "Error while deleting recording!");
|
2004-06-13 20:26:51 +02:00
|
|
|
}
|
2001-10-27 11:47:46 +02:00
|
|
|
else
|
2005-05-26 10:00:59 +02:00
|
|
|
Reply(550, "Recording \"%s\" is in use by timer %d", Option, rc->Timer()->Index() + 1);
|
2001-10-27 11:47:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "Recording \"%s\" not found%s", Option, Recordings.Count() ? "" : " (use LSTR before deleting)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in recording number \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing recording number");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdDELT(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
if (isnumber(Option)) {
|
2005-07-31 14:34:38 +02:00
|
|
|
if (!Timers.BeingEdited()) {
|
|
|
|
cTimer *timer = Timers.Get(strtol(Option, NULL, 10) - 1);
|
|
|
|
if (timer) {
|
|
|
|
if (!timer->Recording()) {
|
|
|
|
isyslog("deleting timer %s", *timer->ToDescr());
|
|
|
|
Timers.Del(timer);
|
|
|
|
Timers.SetModified();
|
|
|
|
Reply(250, "Timer \"%s\" deleted", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "Timer \"%s\" is recording", Option);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
2005-07-31 14:34:38 +02:00
|
|
|
Reply(501, "Timer \"%s\" not defined", Option);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
2005-07-31 14:34:38 +02:00
|
|
|
Reply(550, "Timers are being edited - try again later");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in timer number \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing timer number");
|
|
|
|
}
|
|
|
|
|
2005-08-28 14:18:24 +02:00
|
|
|
void cSVDRP::CmdEDIT(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
if (isnumber(Option)) {
|
|
|
|
cRecording *recording = Recordings.Get(strtol(Option, NULL, 10) - 1);
|
|
|
|
if (recording) {
|
|
|
|
cMarks Marks;
|
2009-01-06 14:41:11 +01:00
|
|
|
if (Marks.Load(recording->FileName(), recording->FramesPerSecond(), recording->IsPesRecording()) && Marks.Count()) {
|
2005-08-28 14:18:24 +02:00
|
|
|
if (!cCutter::Active()) {
|
|
|
|
if (cCutter::Start(recording->FileName()))
|
|
|
|
Reply(250, "Editing recording \"%s\" [%s]", Option, recording->Title());
|
|
|
|
else
|
|
|
|
Reply(554, "Can't start editing process");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(554, "Editing process already active");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(554, "No editing marks defined");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "Recording \"%s\" not found%s", Option, Recordings.Count() ? "" : " (use LSTR before editing)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in recording number \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing recording number");
|
|
|
|
}
|
|
|
|
|
2000-09-17 11:53:35 +02:00
|
|
|
void cSVDRP::CmdGRAB(const char *Option)
|
|
|
|
{
|
2008-02-15 14:57:48 +01:00
|
|
|
const char *FileName = NULL;
|
2000-09-17 11:53:35 +02:00
|
|
|
bool Jpeg = true;
|
|
|
|
int Quality = -1, SizeX = -1, SizeY = -1;
|
|
|
|
if (*Option) {
|
|
|
|
char buf[strlen(Option) + 1];
|
|
|
|
char *p = strcpy(buf, Option);
|
|
|
|
const char *delim = " \t";
|
2004-12-19 16:33:34 +01:00
|
|
|
char *strtok_next;
|
|
|
|
FileName = strtok_r(p, delim, &strtok_next);
|
2005-12-30 15:11:16 +01:00
|
|
|
// image type:
|
2009-06-06 13:48:41 +02:00
|
|
|
const char *Extension = strrchr(FileName, '.');
|
2005-12-29 12:18:27 +01:00
|
|
|
if (Extension) {
|
|
|
|
if (strcasecmp(Extension, ".jpg") == 0 || strcasecmp(Extension, ".jpeg") == 0)
|
2000-09-17 11:53:35 +02:00
|
|
|
Jpeg = true;
|
2005-12-29 12:18:27 +01:00
|
|
|
else if (strcasecmp(Extension, ".pnm") == 0)
|
2000-09-17 11:53:35 +02:00
|
|
|
Jpeg = false;
|
|
|
|
else {
|
2005-12-29 12:18:27 +01:00
|
|
|
Reply(501, "Unknown image type \"%s\"", Extension + 1);
|
2000-09-17 11:53:35 +02:00
|
|
|
return;
|
|
|
|
}
|
2005-12-30 10:27:23 +01:00
|
|
|
if (Extension == FileName)
|
|
|
|
FileName = NULL;
|
2000-09-17 11:53:35 +02:00
|
|
|
}
|
2005-12-30 10:27:23 +01:00
|
|
|
else if (strcmp(FileName, "-") == 0)
|
|
|
|
FileName = NULL;
|
2005-12-30 15:11:16 +01:00
|
|
|
// image quality (and obsolete type):
|
2004-12-19 16:33:34 +01:00
|
|
|
if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
|
2005-12-29 12:18:27 +01:00
|
|
|
if (strcasecmp(p, "JPEG") == 0 || strcasecmp(p, "PNM") == 0) {
|
|
|
|
// tolerate for backward compatibility
|
|
|
|
p = strtok_r(NULL, delim, &strtok_next);
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
if (isnumber(p))
|
|
|
|
Quality = atoi(p);
|
|
|
|
else {
|
2005-12-30 15:43:21 +01:00
|
|
|
Reply(501, "Invalid quality \"%s\"", p);
|
2005-12-29 12:18:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2000-09-17 11:53:35 +02:00
|
|
|
}
|
|
|
|
}
|
2005-12-30 15:11:16 +01:00
|
|
|
// image size:
|
2004-12-19 16:33:34 +01:00
|
|
|
if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
|
2000-09-17 11:53:35 +02:00
|
|
|
if (isnumber(p))
|
|
|
|
SizeX = atoi(p);
|
|
|
|
else {
|
2005-12-30 15:43:21 +01:00
|
|
|
Reply(501, "Invalid sizex \"%s\"", p);
|
2000-09-17 11:53:35 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-12-19 16:33:34 +01:00
|
|
|
if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
|
2000-09-17 11:53:35 +02:00
|
|
|
if (isnumber(p))
|
|
|
|
SizeY = atoi(p);
|
|
|
|
else {
|
2005-12-30 15:43:21 +01:00
|
|
|
Reply(501, "Invalid sizey \"%s\"", p);
|
2000-09-17 11:53:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(501, "Missing sizey");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-12-19 16:33:34 +01:00
|
|
|
if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
|
2000-09-17 11:53:35 +02:00
|
|
|
Reply(501, "Unexpected parameter \"%s\"", p);
|
|
|
|
return;
|
|
|
|
}
|
2005-12-30 15:11:16 +01:00
|
|
|
// canonicalize the file name:
|
|
|
|
char RealFileName[PATH_MAX];
|
|
|
|
if (FileName) {
|
|
|
|
if (grabImageDir) {
|
2009-06-06 14:07:02 +02:00
|
|
|
cString s(FileName);
|
|
|
|
FileName = s;
|
|
|
|
const char *slash = strrchr(FileName, '/');
|
2006-01-14 11:45:43 +01:00
|
|
|
if (!slash) {
|
2008-02-15 14:57:48 +01:00
|
|
|
s = AddDirectory(grabImageDir, FileName);
|
2006-01-14 11:45:43 +01:00
|
|
|
FileName = s;
|
|
|
|
}
|
|
|
|
slash = strrchr(FileName, '/'); // there definitely is one
|
2009-06-06 14:07:02 +02:00
|
|
|
cString t(s);
|
|
|
|
t.Truncate(slash - FileName);
|
|
|
|
char *r = realpath(t, RealFileName);
|
2005-12-30 15:11:16 +01:00
|
|
|
if (!r) {
|
|
|
|
LOG_ERROR_STR(FileName);
|
2005-12-30 15:43:21 +01:00
|
|
|
Reply(501, "Invalid file name \"%s\"", FileName);
|
2005-12-30 15:11:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcat(RealFileName, slash);
|
|
|
|
FileName = RealFileName;
|
|
|
|
if (strncmp(FileName, grabImageDir, strlen(grabImageDir)) != 0) {
|
2005-12-30 15:43:21 +01:00
|
|
|
Reply(501, "Invalid file name \"%s\"", FileName);
|
2005-12-30 15:11:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(550, "Grabbing to file not allowed (use \"GRAB -\" instead)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// actual grabbing:
|
2005-12-30 10:27:23 +01:00
|
|
|
int ImageSize;
|
|
|
|
uchar *Image = cDevice::PrimaryDevice()->GrabImage(ImageSize, Jpeg, Quality, SizeX, SizeY);
|
|
|
|
if (Image) {
|
|
|
|
if (FileName) {
|
2005-12-30 15:11:16 +01:00
|
|
|
int fd = open(FileName, O_WRONLY | O_CREAT | O_NOFOLLOW | O_TRUNC, DEFFILEMODE);
|
|
|
|
if (fd >= 0) {
|
|
|
|
if (safe_write(fd, Image, ImageSize) == ImageSize) {
|
2006-06-11 09:14:22 +02:00
|
|
|
dsyslog("grabbed image to %s", FileName);
|
2005-12-30 10:27:23 +01:00
|
|
|
Reply(250, "Grabbed image %s", Option);
|
2005-12-30 15:11:16 +01:00
|
|
|
}
|
2005-12-30 10:27:23 +01:00
|
|
|
else {
|
|
|
|
LOG_ERROR_STR(FileName);
|
|
|
|
Reply(451, "Can't write to '%s'", FileName);
|
|
|
|
}
|
2005-12-30 15:11:16 +01:00
|
|
|
close(fd);
|
2005-12-30 10:27:23 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG_ERROR_STR(FileName);
|
|
|
|
Reply(451, "Can't open '%s'", FileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cBase64Encoder Base64(Image, ImageSize);
|
|
|
|
const char *s;
|
|
|
|
while ((s = Base64.NextLine()) != NULL)
|
2006-03-26 09:27:30 +02:00
|
|
|
Reply(-216, "%s", s);
|
2005-12-30 10:27:23 +01:00
|
|
|
Reply(216, "Grabbed image %s", Option);
|
|
|
|
}
|
|
|
|
free(Image);
|
|
|
|
}
|
2000-09-17 11:53:35 +02:00
|
|
|
else
|
|
|
|
Reply(451, "Grab image failed");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing filename");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdHELP(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
|
|
|
if (*Option) {
|
2005-08-27 16:42:28 +02:00
|
|
|
const char *hp = GetHelpPage(Option, HelpPages);
|
2000-07-23 15:01:31 +02:00
|
|
|
if (hp)
|
2007-10-13 10:23:19 +02:00
|
|
|
Reply(-214, "%s", hp);
|
2000-07-23 15:01:31 +02:00
|
|
|
else {
|
|
|
|
Reply(504, "HELP topic \"%s\" unknown", Option);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2000-07-29 18:19:49 +02:00
|
|
|
Reply(-214, "This is VDR version %s", VDRVERSION);
|
2000-07-23 15:01:31 +02:00
|
|
|
Reply(-214, "Topics:");
|
2005-08-27 16:42:28 +02:00
|
|
|
PrintHelpTopics(HelpPages);
|
|
|
|
cPlugin *plugin;
|
|
|
|
for (int i = 0; (plugin = cPluginManager::GetPlugin(i)) != NULL; i++) {
|
|
|
|
const char **hp = plugin->SVDRPHelpPages();
|
|
|
|
if (hp)
|
|
|
|
Reply(-214, "Plugin %s v%s - %s", plugin->Name(), plugin->Version(), plugin->Description());
|
|
|
|
PrintHelpTopics(hp);
|
2001-04-01 16:07:58 +02:00
|
|
|
}
|
2000-07-23 15:01:31 +02:00
|
|
|
Reply(-214, "To report bugs in the implementation send email to");
|
2009-10-18 14:18:22 +02:00
|
|
|
Reply(-214, " vdr-bugs@tvdr.de");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
Reply(214, "End of HELP info");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdHITK(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
2002-09-29 13:40:45 +02:00
|
|
|
eKeys k = cKey::FromString(Option);
|
2000-09-17 09:36:50 +02:00
|
|
|
if (k != kNone) {
|
2002-09-29 13:40:45 +02:00
|
|
|
cRemote::Put(k);
|
2000-09-17 09:36:50 +02:00
|
|
|
Reply(250, "Key \"%s\" accepted", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(504, "Unknown key: \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(-214, "Valid <key> names for the HITK command:");
|
|
|
|
for (int i = 0; i < kNone; i++) {
|
2002-09-29 13:40:45 +02:00
|
|
|
Reply(-214, " %s", cKey::ToString(eKeys(i)));
|
2000-09-17 09:36:50 +02:00
|
|
|
}
|
|
|
|
Reply(214, "End of key list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cSVDRP::CmdLSTC(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
2007-08-25 09:31:13 +02:00
|
|
|
bool WithGroupSeps = strcasecmp(Option, ":groups") == 0;
|
|
|
|
if (*Option && !WithGroupSeps) {
|
2000-07-23 15:01:31 +02:00
|
|
|
if (isnumber(Option)) {
|
2000-09-09 14:57:43 +02:00
|
|
|
cChannel *channel = Channels.GetByNumber(strtol(Option, NULL, 10));
|
2000-07-23 15:01:31 +02:00
|
|
|
if (channel)
|
2004-12-26 12:45:22 +01:00
|
|
|
Reply(250, "%d %s", channel->Number(), *channel->ToText());
|
2000-07-23 15:01:31 +02:00
|
|
|
else
|
|
|
|
Reply(501, "Channel \"%s\" not defined", Option);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cChannel *next = NULL;
|
2007-06-23 13:24:00 +02:00
|
|
|
for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) {
|
|
|
|
if (!channel->GroupSep()) {
|
|
|
|
if (strcasestr(channel->Name(), Option)) {
|
|
|
|
if (next)
|
|
|
|
Reply(-250, "%d %s", next->Number(), *next->ToText());
|
|
|
|
next = channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-07-23 15:01:31 +02:00
|
|
|
if (next)
|
2004-12-26 12:45:22 +01:00
|
|
|
Reply(250, "%d %s", next->Number(), *next->ToText());
|
2002-02-24 14:16:46 +01:00
|
|
|
else
|
|
|
|
Reply(501, "Channel \"%s\" not defined", Option);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
}
|
2001-03-02 23:00:53 +01:00
|
|
|
else if (Channels.MaxNumber() >= 1) {
|
2007-06-23 13:24:00 +02:00
|
|
|
for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) {
|
2007-08-25 09:31:13 +02:00
|
|
|
if (WithGroupSeps)
|
|
|
|
Reply(channel->Next() ? -250: 250, "%d %s", channel->GroupSep() ? 0 : channel->Number(), *channel->ToText());
|
|
|
|
else if (!channel->GroupSep())
|
2007-06-23 13:24:00 +02:00
|
|
|
Reply(channel->Number() < Channels.MaxNumber() ? -250 : 250, "%d %s", channel->Number(), *channel->ToText());
|
|
|
|
}
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
2001-03-02 23:00:53 +01:00
|
|
|
else
|
|
|
|
Reply(550, "No channels defined");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
2001-04-01 15:40:43 +02:00
|
|
|
void cSVDRP::CmdLSTE(const char *Option)
|
|
|
|
{
|
2003-12-22 13:29:24 +01:00
|
|
|
cSchedulesLock SchedulesLock;
|
|
|
|
const cSchedules *Schedules = cSchedules::Schedules(SchedulesLock);
|
2001-04-01 15:40:43 +02:00
|
|
|
if (Schedules) {
|
2004-02-22 15:36:36 +01:00
|
|
|
const cSchedule* Schedule = NULL;
|
|
|
|
eDumpMode DumpMode = dmAll;
|
|
|
|
time_t AtTime = 0;
|
|
|
|
if (*Option) {
|
|
|
|
char buf[strlen(Option) + 1];
|
|
|
|
strcpy(buf, Option);
|
|
|
|
const char *delim = " \t";
|
2004-12-19 16:33:34 +01:00
|
|
|
char *strtok_next;
|
|
|
|
char *p = strtok_r(buf, delim, &strtok_next);
|
2004-02-22 15:36:36 +01:00
|
|
|
while (p && DumpMode == dmAll) {
|
|
|
|
if (strcasecmp(p, "NOW") == 0)
|
|
|
|
DumpMode = dmPresent;
|
|
|
|
else if (strcasecmp(p, "NEXT") == 0)
|
|
|
|
DumpMode = dmFollowing;
|
|
|
|
else if (strcasecmp(p, "AT") == 0) {
|
|
|
|
DumpMode = dmAtTime;
|
2004-12-19 16:33:34 +01:00
|
|
|
if ((p = strtok_r(NULL, delim, &strtok_next)) != NULL) {
|
2004-02-22 15:36:36 +01:00
|
|
|
if (isnumber(p))
|
|
|
|
AtTime = strtol(p, NULL, 10);
|
|
|
|
else {
|
|
|
|
Reply(501, "Invalid time");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(501, "Missing time");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!Schedule) {
|
|
|
|
cChannel* Channel = NULL;
|
|
|
|
if (isnumber(p))
|
|
|
|
Channel = Channels.GetByNumber(strtol(Option, NULL, 10));
|
|
|
|
else
|
|
|
|
Channel = Channels.GetByChannelID(tChannelID::FromString(Option));
|
|
|
|
if (Channel) {
|
2006-01-14 15:52:40 +01:00
|
|
|
Schedule = Schedules->GetSchedule(Channel);
|
2004-02-22 15:36:36 +01:00
|
|
|
if (!Schedule) {
|
|
|
|
Reply(550, "No schedule found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(550, "Channel \"%s\" not defined", p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(501, "Unknown option: \"%s\"", p);
|
|
|
|
return;
|
|
|
|
}
|
2004-12-19 16:33:34 +01:00
|
|
|
p = strtok_r(NULL, delim, &strtok_next);
|
2004-02-22 15:36:36 +01:00
|
|
|
}
|
|
|
|
}
|
2005-08-07 14:25:31 +02:00
|
|
|
int fd = dup(file);
|
|
|
|
if (fd) {
|
|
|
|
FILE *f = fdopen(fd, "w");
|
|
|
|
if (f) {
|
|
|
|
if (Schedule)
|
|
|
|
Schedule->Dump(f, "215-", DumpMode, AtTime);
|
|
|
|
else
|
|
|
|
Schedules->Dump(f, "215-", DumpMode, AtTime);
|
|
|
|
fflush(f);
|
|
|
|
Reply(215, "End of EPG data");
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(451, "Can't open file connection");
|
|
|
|
close(fd);
|
|
|
|
}
|
2001-04-01 15:40:43 +02:00
|
|
|
}
|
|
|
|
else
|
2005-08-07 14:25:31 +02:00
|
|
|
Reply(451, "Can't dup stream descriptor");
|
2001-04-01 15:40:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(451, "Can't get EPG data");
|
|
|
|
}
|
|
|
|
|
2001-10-27 11:47:46 +02:00
|
|
|
void cSVDRP::CmdLSTR(const char *Option)
|
|
|
|
{
|
2005-09-25 11:00:57 +02:00
|
|
|
bool recordings = Recordings.Update(true);
|
2001-10-27 11:47:46 +02:00
|
|
|
if (*Option) {
|
|
|
|
if (isnumber(Option)) {
|
|
|
|
cRecording *recording = Recordings.Get(strtol(Option, NULL, 10) - 1);
|
|
|
|
if (recording) {
|
2005-05-16 14:45:11 +02:00
|
|
|
FILE *f = fdopen(file, "w");
|
|
|
|
if (f) {
|
|
|
|
recording->Info()->Write(f, "215-");
|
|
|
|
fflush(f);
|
|
|
|
Reply(215, "End of recording information");
|
|
|
|
// don't 'fclose(f)' here!
|
2001-10-27 11:47:46 +02:00
|
|
|
}
|
|
|
|
else
|
2005-05-16 14:45:11 +02:00
|
|
|
Reply(451, "Can't open file connection");
|
2001-10-27 11:47:46 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "Recording \"%s\" not found", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in recording number \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else if (recordings) {
|
|
|
|
cRecording *recording = Recordings.First();
|
|
|
|
while (recording) {
|
|
|
|
Reply(recording == Recordings.Last() ? 250 : -250, "%d %s", recording->Index() + 1, recording->Title(' ', true));
|
|
|
|
recording = Recordings.Next(recording);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "No recordings available");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdLSTT(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
2006-01-08 13:33:57 +01:00
|
|
|
int Number = 0;
|
|
|
|
bool Id = false;
|
2000-07-23 15:01:31 +02:00
|
|
|
if (*Option) {
|
2006-01-08 13:33:57 +01:00
|
|
|
char buf[strlen(Option) + 1];
|
|
|
|
strcpy(buf, Option);
|
|
|
|
const char *delim = " \t";
|
|
|
|
char *strtok_next;
|
|
|
|
char *p = strtok_r(buf, delim, &strtok_next);
|
|
|
|
while (p) {
|
|
|
|
if (isnumber(p))
|
|
|
|
Number = strtol(p, NULL, 10);
|
|
|
|
else if (strcasecmp(p, "ID") == 0)
|
|
|
|
Id = true;
|
|
|
|
else {
|
|
|
|
Reply(501, "Unknown option: \"%s\"", p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p = strtok_r(NULL, delim, &strtok_next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Number) {
|
|
|
|
cTimer *timer = Timers.Get(Number - 1);
|
|
|
|
if (timer)
|
|
|
|
Reply(250, "%d %s", timer->Index() + 1, *timer->ToText(Id));
|
2000-07-23 15:01:31 +02:00
|
|
|
else
|
2006-01-08 13:33:57 +01:00
|
|
|
Reply(501, "Timer \"%s\" not defined", Option);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
2001-03-02 23:00:53 +01:00
|
|
|
else if (Timers.Count()) {
|
2000-07-23 15:01:31 +02:00
|
|
|
for (int i = 0; i < Timers.Count(); i++) {
|
|
|
|
cTimer *timer = Timers.Get(i);
|
|
|
|
if (timer)
|
2006-01-08 13:33:57 +01:00
|
|
|
Reply(i < Timers.Count() - 1 ? -250 : 250, "%d %s", timer->Index() + 1, *timer->ToText(Id));
|
2000-07-23 15:01:31 +02:00
|
|
|
else
|
|
|
|
Reply(501, "Timer \"%d\" not found", i + 1);
|
|
|
|
}
|
|
|
|
}
|
2001-03-02 23:00:53 +01:00
|
|
|
else
|
|
|
|
Reply(550, "No timers defined");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
2001-02-18 14:18:13 +01:00
|
|
|
void cSVDRP::CmdMESG(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
2005-11-27 15:57:03 +01:00
|
|
|
isyslog("SVDRP message: '%s'", Option);
|
|
|
|
Skins.QueueMessage(mtInfo, Option);
|
|
|
|
Reply(250, "Message queued");
|
2001-02-18 14:18:13 +01:00
|
|
|
}
|
|
|
|
else
|
2005-11-27 15:57:03 +01:00
|
|
|
Reply(501, "Missing message");
|
2001-02-18 14:18:13 +01:00
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdMODC(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
char *tail;
|
|
|
|
int n = strtol(Option, &tail, 10);
|
|
|
|
if (tail && tail != Option) {
|
|
|
|
tail = skipspace(tail);
|
2005-07-31 14:34:38 +02:00
|
|
|
if (!Channels.BeingEdited()) {
|
|
|
|
cChannel *channel = Channels.GetByNumber(n);
|
|
|
|
if (channel) {
|
|
|
|
cChannel ch;
|
|
|
|
if (ch.Parse(tail)) {
|
|
|
|
if (Channels.HasUniqueChannelID(&ch, channel)) {
|
|
|
|
*channel = ch;
|
|
|
|
Channels.ReNumber();
|
|
|
|
Channels.SetModified(true);
|
|
|
|
isyslog("modifed channel %d %s", channel->Number(), *channel->ToText());
|
|
|
|
Reply(250, "%d %s", channel->Number(), *channel->ToText());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Channel settings are not unique");
|
2002-11-10 15:50:21 +01:00
|
|
|
}
|
|
|
|
else
|
2005-07-31 14:34:38 +02:00
|
|
|
Reply(501, "Error in channel settings");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
2002-11-10 15:50:21 +01:00
|
|
|
else
|
2005-07-31 14:34:38 +02:00
|
|
|
Reply(501, "Channel \"%d\" not defined", n);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
2005-07-31 14:34:38 +02:00
|
|
|
Reply(550, "Channels are being edited - try again later");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in channel number");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing channel settings");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdMODT(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
char *tail;
|
|
|
|
int n = strtol(Option, &tail, 10);
|
|
|
|
if (tail && tail != Option) {
|
|
|
|
tail = skipspace(tail);
|
2005-07-31 14:34:38 +02:00
|
|
|
if (!Timers.BeingEdited()) {
|
|
|
|
cTimer *timer = Timers.Get(n - 1);
|
|
|
|
if (timer) {
|
|
|
|
cTimer t = *timer;
|
|
|
|
if (strcasecmp(tail, "ON") == 0)
|
|
|
|
t.SetFlags(tfActive);
|
|
|
|
else if (strcasecmp(tail, "OFF") == 0)
|
|
|
|
t.ClrFlags(tfActive);
|
|
|
|
else if (!t.Parse(tail)) {
|
|
|
|
Reply(501, "Error in timer settings");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*timer = t;
|
|
|
|
Timers.SetModified();
|
|
|
|
isyslog("timer %s modified (%s)", *timer->ToDescr(), timer->HasFlags(tfActive) ? "active" : "inactive");
|
|
|
|
Reply(250, "%d %s", timer->Index() + 1, *timer->ToText());
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
2005-07-31 14:34:38 +02:00
|
|
|
else
|
|
|
|
Reply(501, "Timer \"%d\" not defined", n);
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
2005-07-31 14:34:38 +02:00
|
|
|
Reply(550, "Timers are being edited - try again later");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in timer number");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing timer settings");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdMOVC(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
2005-09-03 14:10:01 +02:00
|
|
|
if (*Option) {
|
|
|
|
if (!Channels.BeingEdited() && !Timers.BeingEdited()) {
|
|
|
|
char *tail;
|
|
|
|
int From = strtol(Option, &tail, 10);
|
|
|
|
if (tail && tail != Option) {
|
|
|
|
tail = skipspace(tail);
|
|
|
|
if (tail && tail != Option) {
|
|
|
|
int To = strtol(tail, NULL, 10);
|
|
|
|
int CurrentChannelNr = cDevice::CurrentChannel();
|
|
|
|
cChannel *CurrentChannel = Channels.GetByNumber(CurrentChannelNr);
|
|
|
|
cChannel *FromChannel = Channels.GetByNumber(From);
|
|
|
|
if (FromChannel) {
|
|
|
|
cChannel *ToChannel = Channels.GetByNumber(To);
|
|
|
|
if (ToChannel) {
|
|
|
|
int FromNumber = FromChannel->Number();
|
|
|
|
int ToNumber = ToChannel->Number();
|
|
|
|
if (FromNumber != ToNumber) {
|
|
|
|
Channels.Move(FromChannel, ToChannel);
|
|
|
|
Channels.ReNumber();
|
|
|
|
Channels.SetModified(true);
|
2006-06-03 09:25:13 +02:00
|
|
|
if (CurrentChannel && CurrentChannel->Number() != CurrentChannelNr) {
|
|
|
|
if (!cDevice::PrimaryDevice()->Replaying() || cDevice::PrimaryDevice()->Transferring())
|
|
|
|
Channels.SwitchTo(CurrentChannel->Number());
|
|
|
|
else
|
|
|
|
cDevice::SetCurrentChannel(CurrentChannel);
|
|
|
|
}
|
2005-09-03 14:10:01 +02:00
|
|
|
isyslog("channel %d moved to %d", FromNumber, ToNumber);
|
|
|
|
Reply(250,"Channel \"%d\" moved to \"%d\"", From, To);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Can't move channel to same postion");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Channel \"%d\" not defined", To);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Channel \"%d\" not defined", From);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in channel number");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in channel number");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "Channels or timers are being edited - try again later");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing channel number");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdMOVT(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
|
|
|
//TODO combine this with menu action
|
|
|
|
Reply(502, "MOVT not yet implemented");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdNEWC(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
|
|
|
if (*Option) {
|
2002-11-10 15:50:21 +01:00
|
|
|
cChannel ch;
|
2005-05-06 13:49:01 +02:00
|
|
|
if (ch.Parse(Option)) {
|
2002-11-10 15:50:21 +01:00
|
|
|
if (Channels.HasUniqueChannelID(&ch)) {
|
|
|
|
cChannel *channel = new cChannel;
|
|
|
|
*channel = ch;
|
|
|
|
Channels.Add(channel);
|
|
|
|
Channels.ReNumber();
|
2004-10-17 11:50:21 +02:00
|
|
|
Channels.SetModified(true);
|
2004-12-26 12:45:22 +01:00
|
|
|
isyslog("new channel %d %s", channel->Number(), *channel->ToText());
|
|
|
|
Reply(250, "%d %s", channel->Number(), *channel->ToText());
|
2002-11-10 15:50:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Channel settings are not unique");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in channel settings");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing channel settings");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdNEWT(const char *Option)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
cTimer *timer = new cTimer;
|
|
|
|
if (timer->Parse(Option)) {
|
2000-08-06 12:56:49 +02:00
|
|
|
cTimer *t = Timers.GetTimer(timer);
|
|
|
|
if (!t) {
|
|
|
|
Timers.Add(timer);
|
2004-10-31 10:22:32 +01:00
|
|
|
Timers.SetModified();
|
2005-03-20 15:15:42 +01:00
|
|
|
isyslog("timer %s added", *timer->ToDescr());
|
2004-12-26 12:45:22 +01:00
|
|
|
Reply(250, "%d %s", timer->Index() + 1, *timer->ToText());
|
2000-08-06 12:56:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2004-12-26 12:45:22 +01:00
|
|
|
Reply(550, "Timer already defined: %d %s", t->Index() + 1, *t->ToText());
|
2000-08-06 12:56:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in timer settings");
|
|
|
|
delete timer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing timer settings");
|
|
|
|
}
|
|
|
|
|
2001-09-01 09:53:01 +02:00
|
|
|
void cSVDRP::CmdNEXT(const char *Option)
|
|
|
|
{
|
|
|
|
cTimer *t = Timers.GetNextActiveTimer();
|
|
|
|
if (t) {
|
|
|
|
time_t Start = t->StartTime();
|
|
|
|
int Number = t->Index() + 1;
|
2004-12-19 16:33:34 +01:00
|
|
|
if (!*Option)
|
2004-12-26 12:45:22 +01:00
|
|
|
Reply(250, "%d %s", Number, *TimeToString(Start));
|
2001-09-01 09:53:01 +02:00
|
|
|
else if (strcasecmp(Option, "ABS") == 0)
|
|
|
|
Reply(250, "%d %ld", Number, Start);
|
|
|
|
else if (strcasecmp(Option, "REL") == 0)
|
|
|
|
Reply(250, "%d %ld", Number, Start - time(NULL));
|
|
|
|
else
|
|
|
|
Reply(501, "Unknown option: \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "No active timers");
|
|
|
|
}
|
|
|
|
|
2005-08-28 10:45:19 +02:00
|
|
|
void cSVDRP::CmdPLAY(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
char *opt = strdup(Option);
|
|
|
|
char *num = skipspace(opt);
|
|
|
|
char *option = num;
|
|
|
|
while (*option && !isspace(*option))
|
|
|
|
option++;
|
|
|
|
char c = *option;
|
|
|
|
*option = 0;
|
|
|
|
if (isnumber(num)) {
|
|
|
|
cRecording *recording = Recordings.Get(strtol(num, NULL, 10) - 1);
|
|
|
|
if (recording) {
|
|
|
|
if (c)
|
|
|
|
option = skipspace(++option);
|
|
|
|
cReplayControl::SetRecording(NULL, NULL);
|
|
|
|
cControl::Shutdown();
|
|
|
|
if (*option) {
|
|
|
|
int pos = 0;
|
2009-01-06 14:41:11 +01:00
|
|
|
if (strcasecmp(option, "BEGIN") != 0)
|
|
|
|
pos = HMSFToIndex(option, recording->FramesPerSecond());
|
|
|
|
cResumeFile resume(recording->FileName(), recording->IsPesRecording());
|
2005-08-28 10:45:19 +02:00
|
|
|
if (pos <= 0)
|
|
|
|
resume.Delete();
|
|
|
|
else
|
|
|
|
resume.Save(pos);
|
|
|
|
}
|
|
|
|
cReplayControl::SetRecording(recording->FileName(), recording->Title());
|
|
|
|
cControl::Launch(new cReplayControl);
|
|
|
|
cControl::Attach();
|
|
|
|
Reply(250, "Playing recording \"%s\" [%s]", num, recording->Title());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "Recording \"%s\" not found%s", num, Recordings.Count() ? "" : " (use LSTR before playing)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in recording number \"%s\"", num);
|
|
|
|
free(opt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing recording number");
|
|
|
|
}
|
|
|
|
|
2005-08-27 16:42:28 +02:00
|
|
|
void cSVDRP::CmdPLUG(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
char *opt = strdup(Option);
|
|
|
|
char *name = skipspace(opt);
|
|
|
|
char *option = name;
|
|
|
|
while (*option && !isspace(*option))
|
|
|
|
option++;
|
|
|
|
char c = *option;
|
|
|
|
*option = 0;
|
|
|
|
cPlugin *plugin = cPluginManager::GetPlugin(name);
|
|
|
|
if (plugin) {
|
|
|
|
if (c)
|
|
|
|
option = skipspace(++option);
|
|
|
|
char *cmd = option;
|
|
|
|
while (*option && !isspace(*option))
|
|
|
|
option++;
|
|
|
|
if (*option) {
|
|
|
|
*option++ = 0;
|
|
|
|
option = skipspace(option);
|
|
|
|
}
|
|
|
|
if (!*cmd || strcasecmp(cmd, "HELP") == 0) {
|
|
|
|
if (*cmd && *option) {
|
|
|
|
const char *hp = GetHelpPage(option, plugin->SVDRPHelpPages());
|
|
|
|
if (hp) {
|
2006-03-26 09:27:30 +02:00
|
|
|
Reply(-214, "%s", hp);
|
2005-08-27 16:42:28 +02:00
|
|
|
Reply(214, "End of HELP info");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(504, "HELP topic \"%s\" for plugin \"%s\" unknown", option, plugin->Name());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(-214, "Plugin %s v%s - %s", plugin->Name(), plugin->Version(), plugin->Description());
|
|
|
|
const char **hp = plugin->SVDRPHelpPages();
|
|
|
|
if (hp) {
|
|
|
|
Reply(-214, "SVDRP commands:");
|
|
|
|
PrintHelpTopics(hp);
|
|
|
|
Reply(214, "End of HELP info");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(214, "This plugin has no SVDRP commands");
|
|
|
|
}
|
|
|
|
}
|
2005-09-03 12:49:36 +02:00
|
|
|
else if (strcasecmp(cmd, "MAIN") == 0) {
|
2006-04-17 09:10:39 +02:00
|
|
|
if (cRemote::CallPlugin(plugin->Name()))
|
|
|
|
Reply(250, "Initiated call to main menu function of plugin \"%s\"", plugin->Name());
|
|
|
|
else
|
|
|
|
Reply(550, "A plugin call is already pending - please try again later");
|
2005-09-03 12:49:36 +02:00
|
|
|
}
|
2005-08-27 16:42:28 +02:00
|
|
|
else {
|
|
|
|
int ReplyCode = 900;
|
|
|
|
cString s = plugin->SVDRPCommand(cmd, option, ReplyCode);
|
2008-02-17 13:47:12 +01:00
|
|
|
if (*s)
|
2006-03-26 09:27:30 +02:00
|
|
|
Reply(abs(ReplyCode), "%s", *s);
|
2005-08-27 16:42:28 +02:00
|
|
|
else
|
|
|
|
Reply(500, "Command unrecognized: \"%s\"", cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(550, "Plugin \"%s\" not found (use PLUG for a list of plugins)", name);
|
|
|
|
free(opt);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reply(-214, "Available plugins:");
|
|
|
|
cPlugin *plugin;
|
|
|
|
for (int i = 0; (plugin = cPluginManager::GetPlugin(i)) != NULL; i++)
|
|
|
|
Reply(-214, "%s v%s - %s", plugin->Name(), plugin->Version(), plugin->Description());
|
|
|
|
Reply(214, "End of plugin list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-24 11:13:21 +01:00
|
|
|
void cSVDRP::CmdPUTE(const char *Option)
|
|
|
|
{
|
2009-04-13 13:35:29 +02:00
|
|
|
if (*Option) {
|
|
|
|
FILE *f = fopen(Option, "r");
|
|
|
|
if (f) {
|
|
|
|
if (cSchedules::Read(f)) {
|
|
|
|
cSchedules::Cleanup(true);
|
|
|
|
Reply(250, "EPG data processed from \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(451, "Error while processing EPG from \"%s\"", Option);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Cannot open file \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
delete PUTEhandler;
|
|
|
|
PUTEhandler = new cPUTEhandler;
|
|
|
|
Reply(PUTEhandler->Status(), "%s", PUTEhandler->Message());
|
|
|
|
if (PUTEhandler->Status() != 354)
|
|
|
|
DELETENULL(PUTEhandler);
|
|
|
|
}
|
2002-02-24 11:13:21 +01:00
|
|
|
}
|
|
|
|
|
2007-04-30 12:53:35 +02:00
|
|
|
void cSVDRP::CmdREMO(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
if (!strcasecmp(Option, "ON")) {
|
|
|
|
cRemote::SetEnabled(true);
|
|
|
|
Reply(250, "Remote control enabled");
|
|
|
|
}
|
|
|
|
else if (!strcasecmp(Option, "OFF")) {
|
|
|
|
cRemote::SetEnabled(false);
|
|
|
|
Reply(250, "Remote control disabled");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Invalid Option \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(250, "Remote control is %s", cRemote::Enabled() ? "enabled" : "disabled");
|
|
|
|
}
|
|
|
|
|
2004-01-17 15:41:52 +01:00
|
|
|
void cSVDRP::CmdSCAN(const char *Option)
|
|
|
|
{
|
|
|
|
EITScanner.ForceScan();
|
|
|
|
Reply(250, "EPG scan triggered");
|
|
|
|
}
|
|
|
|
|
2003-04-27 14:23:30 +02:00
|
|
|
void cSVDRP::CmdSTAT(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
if (strcasecmp(Option, "DISK") == 0) {
|
2004-01-31 10:15:58 +01:00
|
|
|
int FreeMB, UsedMB;
|
|
|
|
int Percent = VideoDiskSpace(&FreeMB, &UsedMB);
|
|
|
|
Reply(250, "%dMB %dMB %d%%", FreeMB + UsedMB, FreeMB, Percent);
|
2003-04-27 14:23:30 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Invalid Option \"%s\"", Option);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "No option given");
|
|
|
|
}
|
|
|
|
|
2000-09-17 09:36:50 +02:00
|
|
|
void cSVDRP::CmdUPDT(const char *Option)
|
2000-08-06 12:56:49 +02:00
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
cTimer *timer = new cTimer;
|
|
|
|
if (timer->Parse(Option)) {
|
2005-07-31 14:34:38 +02:00
|
|
|
if (!Timers.BeingEdited()) {
|
|
|
|
cTimer *t = Timers.GetTimer(timer);
|
|
|
|
if (t) {
|
|
|
|
t->Parse(Option);
|
|
|
|
delete timer;
|
|
|
|
timer = t;
|
|
|
|
isyslog("timer %s updated", *timer->ToDescr());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Timers.Add(timer);
|
|
|
|
isyslog("timer %s added", *timer->ToDescr());
|
|
|
|
}
|
|
|
|
Timers.SetModified();
|
|
|
|
Reply(250, "%d %s", timer->Index() + 1, *timer->ToText());
|
|
|
|
return;
|
2000-08-06 12:56:49 +02:00
|
|
|
}
|
2005-07-31 14:34:38 +02:00
|
|
|
else
|
|
|
|
Reply(550, "Timers are being edited - try again later");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Error in timer settings");
|
2000-08-06 12:56:49 +02:00
|
|
|
delete timer;
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Reply(501, "Missing timer settings");
|
|
|
|
}
|
|
|
|
|
2002-03-09 10:07:40 +01:00
|
|
|
void cSVDRP::CmdVOLU(const char *Option)
|
|
|
|
{
|
|
|
|
if (*Option) {
|
|
|
|
if (isnumber(Option))
|
2002-06-16 12:57:31 +02:00
|
|
|
cDevice::PrimaryDevice()->SetVolume(strtol(Option, NULL, 10), true);
|
2002-03-09 10:07:40 +01:00
|
|
|
else if (strcmp(Option, "+") == 0)
|
2002-06-16 12:57:31 +02:00
|
|
|
cDevice::PrimaryDevice()->SetVolume(VOLUMEDELTA);
|
2002-03-09 10:07:40 +01:00
|
|
|
else if (strcmp(Option, "-") == 0)
|
2002-06-16 12:57:31 +02:00
|
|
|
cDevice::PrimaryDevice()->SetVolume(-VOLUMEDELTA);
|
2002-03-09 10:07:40 +01:00
|
|
|
else if (strcasecmp(Option, "MUTE") == 0)
|
2002-06-16 12:57:31 +02:00
|
|
|
cDevice::PrimaryDevice()->ToggleMute();
|
2002-03-09 10:07:40 +01:00
|
|
|
else {
|
|
|
|
Reply(501, "Unknown option: \"%s\"", Option);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
if (cDevice::PrimaryDevice()->IsMute())
|
2002-03-09 10:07:40 +01:00
|
|
|
Reply(250, "Audio is mute");
|
|
|
|
else
|
2002-06-16 12:57:31 +02:00
|
|
|
Reply(250, "Audio volume is %d", cDevice::CurrentVolume());
|
2002-03-09 10:07:40 +01:00
|
|
|
}
|
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
#define CMD(c) (strcasecmp(Cmd, c) == 0)
|
|
|
|
|
|
|
|
void cSVDRP::Execute(char *Cmd)
|
|
|
|
{
|
2002-02-24 11:13:21 +01:00
|
|
|
// handle PUTE data:
|
|
|
|
if (PUTEhandler) {
|
|
|
|
if (!PUTEhandler->Process(Cmd)) {
|
2006-03-26 09:27:30 +02:00
|
|
|
Reply(PUTEhandler->Status(), "%s", PUTEhandler->Message());
|
2002-02-24 11:13:21 +01:00
|
|
|
DELETENULL(PUTEhandler);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2000-07-23 15:01:31 +02:00
|
|
|
// skip leading whitespace:
|
|
|
|
Cmd = skipspace(Cmd);
|
|
|
|
// find the end of the command word:
|
|
|
|
char *s = Cmd;
|
|
|
|
while (*s && !isspace(*s))
|
|
|
|
s++;
|
2001-04-01 14:13:42 +02:00
|
|
|
if (*s)
|
|
|
|
*s++ = 0;
|
2001-09-22 13:31:29 +02:00
|
|
|
s = skipspace(s);
|
2000-09-17 09:36:50 +02:00
|
|
|
if (CMD("CHAN")) CmdCHAN(s);
|
2002-08-25 10:49:02 +02:00
|
|
|
else if (CMD("CLRE")) CmdCLRE(s);
|
2000-09-17 09:36:50 +02:00
|
|
|
else if (CMD("DELC")) CmdDELC(s);
|
2001-10-27 11:47:46 +02:00
|
|
|
else if (CMD("DELR")) CmdDELR(s);
|
2000-09-17 09:36:50 +02:00
|
|
|
else if (CMD("DELT")) CmdDELT(s);
|
2005-08-28 14:18:24 +02:00
|
|
|
else if (CMD("EDIT")) CmdEDIT(s);
|
2000-09-17 11:53:35 +02:00
|
|
|
else if (CMD("GRAB")) CmdGRAB(s);
|
2000-09-17 09:36:50 +02:00
|
|
|
else if (CMD("HELP")) CmdHELP(s);
|
|
|
|
else if (CMD("HITK")) CmdHITK(s);
|
|
|
|
else if (CMD("LSTC")) CmdLSTC(s);
|
2001-04-01 15:40:43 +02:00
|
|
|
else if (CMD("LSTE")) CmdLSTE(s);
|
2001-10-27 11:47:46 +02:00
|
|
|
else if (CMD("LSTR")) CmdLSTR(s);
|
2000-09-17 09:36:50 +02:00
|
|
|
else if (CMD("LSTT")) CmdLSTT(s);
|
2001-02-18 14:18:13 +01:00
|
|
|
else if (CMD("MESG")) CmdMESG(s);
|
2000-09-17 09:36:50 +02:00
|
|
|
else if (CMD("MODC")) CmdMODC(s);
|
|
|
|
else if (CMD("MODT")) CmdMODT(s);
|
|
|
|
else if (CMD("MOVC")) CmdMOVC(s);
|
|
|
|
else if (CMD("MOVT")) CmdMOVT(s);
|
|
|
|
else if (CMD("NEWC")) CmdNEWC(s);
|
|
|
|
else if (CMD("NEWT")) CmdNEWT(s);
|
2001-09-01 09:53:01 +02:00
|
|
|
else if (CMD("NEXT")) CmdNEXT(s);
|
2005-08-28 10:45:19 +02:00
|
|
|
else if (CMD("PLAY")) CmdPLAY(s);
|
2005-08-27 16:42:28 +02:00
|
|
|
else if (CMD("PLUG")) CmdPLUG(s);
|
2002-02-24 11:13:21 +01:00
|
|
|
else if (CMD("PUTE")) CmdPUTE(s);
|
2007-04-30 12:53:35 +02:00
|
|
|
else if (CMD("REMO")) CmdREMO(s);
|
2004-01-17 15:41:52 +01:00
|
|
|
else if (CMD("SCAN")) CmdSCAN(s);
|
2003-04-27 14:23:30 +02:00
|
|
|
else if (CMD("STAT")) CmdSTAT(s);
|
2002-03-09 10:07:40 +01:00
|
|
|
else if (CMD("UPDT")) CmdUPDT(s);
|
|
|
|
else if (CMD("VOLU")) CmdVOLU(s);
|
2006-08-06 09:20:04 +02:00
|
|
|
else if (CMD("QUIT")) Close(true);
|
2000-07-23 15:01:31 +02:00
|
|
|
else Reply(500, "Command unrecognized: \"%s\"", Cmd);
|
|
|
|
}
|
|
|
|
|
2002-10-20 12:49:16 +02:00
|
|
|
bool cSVDRP::Process(void)
|
2000-07-23 15:01:31 +02:00
|
|
|
{
|
2001-02-18 14:18:13 +01:00
|
|
|
bool NewConnection = !file.IsOpen();
|
|
|
|
bool SendGreeting = NewConnection;
|
2000-07-23 15:01:31 +02:00
|
|
|
|
2000-09-17 08:23:46 +02:00
|
|
|
if (file.IsOpen() || file.Open(socket.Accept())) {
|
2000-07-23 15:01:31 +02:00
|
|
|
if (SendGreeting) {
|
|
|
|
//TODO how can we get the *full* hostname?
|
2001-09-14 14:35:40 +02:00
|
|
|
char buffer[BUFSIZ];
|
2000-07-23 15:01:31 +02:00
|
|
|
gethostname(buffer, sizeof(buffer));
|
|
|
|
time_t now = time(NULL);
|
2008-05-02 14:22:23 +02:00
|
|
|
Reply(220, "%s SVDRP VideoDiskRecorder %s; %s; %s", buffer, VDRVERSION, *TimeToString(now), cCharSetConv::SystemCharacterTable() ? cCharSetConv::SystemCharacterTable() : "UTF-8");
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
2001-02-18 14:18:13 +01:00
|
|
|
if (NewConnection)
|
|
|
|
lastActivity = time(NULL);
|
2002-01-13 16:08:45 +01:00
|
|
|
while (file.Ready(false)) {
|
|
|
|
unsigned char c;
|
|
|
|
int r = safe_read(file, &c, 1);
|
|
|
|
if (r > 0) {
|
|
|
|
if (c == '\n' || c == 0x00) {
|
|
|
|
// strip trailing whitespace:
|
|
|
|
while (numChars > 0 && strchr(" \t\r\n", cmdLine[numChars - 1]))
|
|
|
|
cmdLine[--numChars] = 0;
|
|
|
|
// make sure the string is terminated:
|
|
|
|
cmdLine[numChars] = 0;
|
|
|
|
// showtime!
|
|
|
|
Execute(cmdLine);
|
|
|
|
numChars = 0;
|
2005-11-05 11:21:38 +01:00
|
|
|
if (length > BUFSIZ) {
|
|
|
|
free(cmdLine); // let's not tie up too much memory
|
|
|
|
length = BUFSIZ;
|
|
|
|
cmdLine = MALLOC(char, length);
|
|
|
|
}
|
2002-01-13 16:08:45 +01:00
|
|
|
}
|
|
|
|
else if (c == 0x04 && numChars == 0) {
|
|
|
|
// end of file (only at beginning of line)
|
2006-08-06 09:20:04 +02:00
|
|
|
Close(true);
|
2002-01-13 16:08:45 +01:00
|
|
|
}
|
|
|
|
else if (c == 0x08 || c == 0x7F) {
|
|
|
|
// backspace or delete (last character)
|
|
|
|
if (numChars > 0)
|
|
|
|
numChars--;
|
|
|
|
}
|
|
|
|
else if (c <= 0x03 || c == 0x0D) {
|
|
|
|
// ignore control characters
|
|
|
|
}
|
2005-11-05 11:21:38 +01:00
|
|
|
else {
|
|
|
|
if (numChars >= length - 1) {
|
2011-02-25 15:25:42 +01:00
|
|
|
int NewLength = length + BUFSIZ;
|
|
|
|
if (char *NewBuffer = (char *)realloc(cmdLine, NewLength)) {
|
|
|
|
length = NewLength;
|
|
|
|
cmdLine = NewBuffer;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
esyslog("ERROR: out of memory");
|
|
|
|
Close();
|
|
|
|
break;
|
|
|
|
}
|
2005-11-05 11:21:38 +01:00
|
|
|
}
|
2002-01-13 16:08:45 +01:00
|
|
|
cmdLine[numChars++] = c;
|
|
|
|
cmdLine[numChars] = 0;
|
|
|
|
}
|
|
|
|
lastActivity = time(NULL);
|
2001-04-01 14:13:42 +02:00
|
|
|
}
|
2006-08-06 09:20:04 +02:00
|
|
|
else if (r <= 0) {
|
2002-05-13 16:35:49 +02:00
|
|
|
isyslog("lost connection to SVDRP client");
|
2001-04-01 14:13:42 +02:00
|
|
|
Close();
|
|
|
|
}
|
2001-07-14 09:49:07 +02:00
|
|
|
}
|
2002-01-13 16:08:45 +01:00
|
|
|
if (Setup.SVDRPTimeout && time(NULL) - lastActivity > Setup.SVDRPTimeout) {
|
2002-05-13 16:35:49 +02:00
|
|
|
isyslog("timeout on SVDRP connection");
|
2006-08-06 09:20:04 +02:00
|
|
|
Close(true, true);
|
2001-02-18 14:18:13 +01:00
|
|
|
}
|
2002-10-20 12:49:16 +02:00
|
|
|
return true;
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
2002-10-20 12:49:16 +02:00
|
|
|
return false;
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
|
2005-12-30 15:11:16 +01:00
|
|
|
void cSVDRP::SetGrabImageDir(const char *GrabImageDir)
|
|
|
|
{
|
|
|
|
free(grabImageDir);
|
|
|
|
grabImageDir = GrabImageDir ? strdup(GrabImageDir) : NULL;
|
|
|
|
}
|
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
//TODO more than one connection???
|