summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2006-08-06 09:20:04 +0200
committerKlaus Schmidinger <vdr@tvdr.de>2006-08-06 09:20:04 +0200
commitf4138799367f1cf9ff1562567503ede6f9470057 (patch)
tree7f524deff72842950509b135681cfc8c3c9d3152
parentc78a784fb234c0687be00a4cbef0ee4ddb0a3184 (diff)
downloadvdr-f4138799367f1cf9ff1562567503ede6f9470057.tar.gz
vdr-f4138799367f1cf9ff1562567503ede6f9470057.tar.bz2
Modified the cSVDRP::Close() function to avoid code duplication1.4.1-3
-rw-r--r--HISTORY3
-rw-r--r--svdrp.c36
-rw-r--r--svdrp.h4
3 files changed, 19 insertions, 24 deletions
diff --git a/HISTORY b/HISTORY
index ba2e38c5..1a35c12a 100644
--- a/HISTORY
+++ b/HISTORY
@@ -4835,7 +4835,7 @@ Video Disk Recorder Revision History
only done for normal keypresses, not for repeated ones. This allows the user to
scroll the value all the way to the limit by keeping the key pressed.
-2006-08-05: Version 1.4.1-3
+2006-08-06: Version 1.4.1-3
- Fixed assigning schedules to channels in case there is no initial EPG information
(thanks to Frank Schmirler).
@@ -4857,3 +4857,4 @@ Video Disk Recorder Revision History
- Avoiding shutdown message "Recording in ... minutes, shut down anyway?" with
a negative number of minutes (reported by Udo Richter).
- Fixed getting the next active timer when shutting down (thanks to Udo Richter).
+- Modified the cSVDRP::Close() function to avoid code duplication.
diff --git a/svdrp.c b/svdrp.c
index 6972681e..b2317527 100644
--- a/svdrp.c
+++ b/svdrp.c
@@ -10,7 +10,7 @@
* and interact with the Video Disk Recorder - or write a full featured
* graphical interface that sits on top of an SVDRP connection.
*
- * $Id: svdrp.c 1.98 2006/07/22 13:59:43 kls Exp $
+ * $Id: svdrp.c 1.99 2006/08/06 09:17:58 kls Exp $
*/
#include "svdrp.h"
@@ -378,17 +378,19 @@ cSVDRP::cSVDRP(int Port)
cSVDRP::~cSVDRP()
{
- Close();
+ Close(true);
free(cmdLine);
}
-void cSVDRP::Close(bool Timeout)
+void cSVDRP::Close(bool SendReply, bool Timeout)
{
if (file.IsOpen()) {
- //TODO how can we get the *full* hostname?
- char buffer[BUFSIZ];
- gethostname(buffer, sizeof(buffer));
- Reply(221, "%s closing connection%s", buffer, Timeout ? " (timeout)" : "");
+ 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)" : "");
+ }
isyslog("closing SVDRP connection"); //TODO store IP#???
file.Close();
DELETENULL(PUTEhandler);
@@ -401,7 +403,7 @@ bool cSVDRP::Send(const char *s, int length)
length = strlen(s);
if (safe_write(file, s, length) < 0) {
LOG_ERROR;
- file.Close();
+ Close();
return false;
}
return true;
@@ -423,10 +425,8 @@ void cSVDRP::Reply(int Code, const char *fmt, ...)
cont = '-';
char number[16];
sprintf(number, "%03d%c", abs(Code), cont);
- if (!(Send(number) && Send(s, n ? n - s : -1) && Send("\r\n"))) {
- Close();
+ if (!(Send(number) && Send(s, n ? n - s : -1) && Send("\r\n")))
break;
- }
s = n ? n + 1 : NULL;
}
free(buffer);
@@ -1530,7 +1530,7 @@ void cSVDRP::Execute(char *Cmd)
else if (CMD("STAT")) CmdSTAT(s);
else if (CMD("UPDT")) CmdUPDT(s);
else if (CMD("VOLU")) CmdVOLU(s);
- else if (CMD("QUIT")) Close();
+ else if (CMD("QUIT")) Close(true);
else Reply(500, "Command unrecognized: \"%s\"", Cmd);
}
@@ -1570,7 +1570,7 @@ bool cSVDRP::Process(void)
}
else if (c == 0x04 && numChars == 0) {
// end of file (only at beginning of line)
- Close();
+ Close(true);
}
else if (c == 0x08 || c == 0x7F) {
// backspace or delete (last character)
@@ -1590,20 +1590,14 @@ bool cSVDRP::Process(void)
}
lastActivity = time(NULL);
}
- else if (r < 0) {
+ else if (r <= 0) {
isyslog("lost connection to SVDRP client");
Close();
}
- else {
- isyslog("SVDRP client closed connection");
- //TODO give cSVDRP::Close() an extra parameter to avoid this code duplication
- file.Close();
- DELETENULL(PUTEhandler);
- }
}
if (Setup.SVDRPTimeout && time(NULL) - lastActivity > Setup.SVDRPTimeout) {
isyslog("timeout on SVDRP connection");
- Close(true);
+ Close(true, true);
}
return true;
}
diff --git a/svdrp.h b/svdrp.h
index 1229f8ef..65d2f69c 100644
--- a/svdrp.h
+++ b/svdrp.h
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: svdrp.h 1.27 2005/12/30 14:46:38 kls Exp $
+ * $Id: svdrp.h 1.28 2006/08/06 08:51:09 kls Exp $
*/
#ifndef __SVDRP_H
@@ -50,7 +50,7 @@ private:
char *cmdLine;
time_t lastActivity;
static char *grabImageDir;
- void Close(bool Timeout = false);
+ void Close(bool SendReply = false, bool Timeout = false);
bool Send(const char *s, int length = -1);
void Reply(int Code, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
void PrintHelpTopics(const char **hp);