[vdr-plugin-vdrmanager] 02/07: New upstream version 0.12+git20180217

Tobias Grimm tiber-guest at moszumanska.debian.org
Sat Feb 17 12:24:53 UTC 2018


This is an automated email from the git hooks/post-receive script.

tiber-guest pushed a commit to branch master
in repository vdr-plugin-vdrmanager.

commit bee35fcf0658cbda534b6693aeb9714eb159ab9e
Author: Tobias Grimm <git at e-tobi.net>
Date:   Sat Feb 17 13:22:36 2018 +0100

    New upstream version 0.12+git20180217
---
 .gitignore           |  12 ++++
 README               |   5 ++
 clientsock.cpp       |  81 ++++++++++++++++++++---
 clientsock.h         |   6 +-
 helpers.cpp          | 182 ++++++++++++++++++++++++++++++++-------------------
 helpers.h            |  14 ++--
 select.cpp           |   4 +-
 serversock.cpp       | 107 +++++++++++-------------------
 serversock.h         |   1 -
 sock.h               |   2 +
 vdrmanager.cpp       |   4 +-
 vdrmanagerthread.cpp |   9 ++-
 12 files changed, 265 insertions(+), 162 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9c5df3e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,12 @@
+/clientsock.o
+/compressor.o
+/handler.o
+/helpers.o
+/libvdr-vdrmanager.so
+/select.o
+/serversock.o
+/sock.o
+/vdrmanager.o
+/vdrmanagerthread.o
+.settings/*
+.dependencies
diff --git a/README b/README
index 610904f..51a29c8 100644
--- a/README
+++ b/README
@@ -2,6 +2,10 @@ This is a "plugin" for the Video Disk Recorder (VDR).
 
 See the file COPYING for license information.
 
+This software is released under the GPL, version 2 (see COPYING).
+Additionally, compiling, linking, and/or using the OpenSSL toolkit in
+conjunction with this software is allowed.
+
 Description:
 
 This helper plugin allows remote programming VDR using
@@ -11,3 +15,4 @@ Installation:
 http://www.vdr-wiki.de/wiki/index.php/Plugin_Installation
 
 If you use a vdr version lower then 1.7.36, use Makefile.pre.1.7.36
+
diff --git a/clientsock.cpp b/clientsock.cpp
index 3f78007..0bce192 100644
--- a/clientsock.cpp
+++ b/clientsock.cpp
@@ -17,7 +17,7 @@ static int clientno = 0;
 /*
  * cVdrmonClientSocket
  */
-cVdrmanagerClientSocket::cVdrmanagerClientSocket(const char * password, int compressionMode) {
+cVdrmanagerClientSocket::cVdrmanagerClientSocket(const char * password, int compressionMode, const char * certFile, const char * keyFile) {
 	readbuf = "";
 	writebuf = "";
 	sendbuf = NULL;
@@ -28,6 +28,8 @@ cVdrmanagerClientSocket::cVdrmanagerClientSocket(const char * password, int comp
 	client = ++clientno;
 	this->password = password;
 	this->compressionMode = compressionMode;
+	this->certFile = certFile;
+	this->keyFile = keyFile;
 	login = false;
 	compression = false;
 	initCompression = false;
@@ -43,6 +45,9 @@ cVdrmanagerClientSocket::~cVdrmanagerClientSocket() {
   if (ssl) {
     SSL_free(ssl);
   }
+  if (sslCtx) {
+    SSL_CTX_free(sslCtx);
+  }
 #endif
 }
 
@@ -292,6 +297,64 @@ int cVdrmanagerClientSocket::FlushNoSSL() {
 
 #if VDRMANAGER_USE_SSL
 
+bool cVdrmanagerClientSocket::LoadCerts() {
+
+  if (certFile) {
+    isyslog("[vdrmanager] initialize SSL context");
+
+    SSL_METHOD * method = (SSL_METHOD *)SSLv23_server_method();
+    sslCtx = SSL_CTX_new(method);
+    if (sslCtx == NULL) {
+      long errorCode = ERR_get_error();
+      char * error = ERR_error_string(errorCode, NULL);
+      esyslog("[vdrmanager] Error initializing SSL context: %s", error);
+      SSL_CTX_free(sslCtx);
+      sslCtx = NULL;
+      return false;
+    }
+    SSL_CTX_set_options(sslCtx, SSL_OP_NO_SSLv3);
+
+    /* set the local certificate from CertFile */
+    if (SSL_CTX_use_certificate_chain_file(sslCtx, certFile) != 1) {
+      long errorCode = ERR_get_error();
+      char * error = ERR_error_string(errorCode, NULL);
+      esyslog("[vdrmanager] Error loading cert chain file %s: %s", certFile, error);
+      SSL_CTX_free(sslCtx);
+      sslCtx = NULL;
+    } else {
+      isyslog("[vdrmanager] cert chain file loaded %s", certFile);  
+    }
+
+    /* set the private key from KeyFile */
+    if (SSL_CTX_use_PrivateKey_file(sslCtx, keyFile, SSL_FILETYPE_PEM) != 1) {
+      long errorCode = ERR_get_error();
+      char * error = ERR_error_string(errorCode, NULL);
+      esyslog("[vdrmanager] Error loading key file %s: %s", keyFile, error);
+      SSL_CTX_free(sslCtx);
+      sslCtx = NULL;
+      return false;
+    } else {
+      isyslog("[vdrmanager] key file loaded %s", keyFile);  
+    }
+
+    /* verify private key */
+    if (!SSL_CTX_check_private_key(sslCtx)) {
+      long errorCode = ERR_get_error();
+      char * error = ERR_error_string(errorCode, NULL);
+      esyslog("[vdrmanager] Error checking SSL keys: %s", error);
+      SSL_CTX_free(sslCtx);
+      sslCtx = NULL;
+      return false;
+    }
+
+    SSL_CTX_set_mode(sslCtx, SSL_MODE_ENABLE_PARTIAL_WRITE);
+
+    return true;
+  }
+
+  return true;
+}
+
 int cVdrmanagerClientSocket::FlushSSL() {
 
   sslReadWrite = SSL_NO_RETRY;
@@ -325,20 +388,22 @@ int cVdrmanagerClientSocket::FlushSSL() {
 
 #endif
 
-bool cVdrmanagerClientSocket::Attach(int fd, SSL_CTX * sslCtx) {
+bool cVdrmanagerClientSocket::Attach(int fd) {
 	sock = fd;
 	if (!MakeDontBlock()) {
 	  return false;
 	}
 
 #if VDRMANAGER_USE_SSL
-	if (sslCtx) {
-	  ssl = SSL_new(sslCtx);
-    SSL_set_accept_state(ssl);
-    BIO *bio = BIO_new_socket(sock, BIO_NOCLOSE);
-	  SSL_set_bio(ssl, bio, bio);
-	  BIO_set_nbio(bio, 1);
+
+	if (!LoadCerts()) {
+	  return false;
 	}
+  ssl = SSL_new(sslCtx);
+  SSL_set_accept_state(ssl);
+  BIO *bio = BIO_new_socket(sock, BIO_NOCLOSE);
+  SSL_set_bio(ssl, bio, bio);
+  BIO_set_nbio(bio, 1);
 #endif
 
 	return true;
diff --git a/clientsock.h b/clientsock.h
index 6c3fba3..c2062e6 100644
--- a/clientsock.h
+++ b/clientsock.h
@@ -37,14 +37,15 @@ private:
   bool initCompression;
   int compressionMode;
 #if VDRMANAGER_USE_SSL
+  SSL_CTX * sslCtx;
   SSL * ssl;
   int sslReadWrite;
   int sslWantsSelect;
 #endif
 public:
-  cVdrmanagerClientSocket(const char * password, int compressionMode);
+  cVdrmanagerClientSocket(const char * password, int compressionMode, const char * certFile, const char * keyFile);
   virtual ~cVdrmanagerClientSocket();
-  bool Attach(int fd, SSL_CTX * sslCtx);
+  bool Attach(int fd);
   bool IsLineComplete();
   bool GetLine(string& line);
   void Write(string line);
@@ -58,6 +59,7 @@ public:
   int GetSslReadWrite();
   int GetSslWantsSelect();
   bool IsSSL();
+  bool LoadCerts();
 #endif
   bool Disconnected();
   void Disconnect();
diff --git a/helpers.cpp b/helpers.cpp
index cc9dedb..7cbca5d 100644
--- a/helpers.cpp
+++ b/helpers.cpp
@@ -25,6 +25,49 @@
 #define INDEXFILESUFFIX   "/index.vdr"
 #define LENGTHFILESUFFIX  "/length.vdr"
 
+#ifdef DEF_LIST_LOCK
+
+#define READ_LOCK_BASE(Class, Define) LOCK_##Define##_READ; const c##Class * the##Class = Class
+#define WRITE_LOCK_BASE(Class, Define) LOCK_##Define##_WRITE; c##Class * the##Class = Class
+
+#define READ_LOCK_TIMERS READ_LOCK_BASE(Timers, TIMERS)
+#define WRITE_LOCK_TIMERS WRITE_LOCK_BASE(Timers, TIMERS)
+
+#define READ_LOCK_RECORDINGS READ_LOCK_BASE(Recordings, RECORDINGS)
+#define WRITE_LOCK_RECORDINGS WRITE_LOCK_BASE(Recordings, RECORDINGS)
+
+#define READ_LOCK_CHANNELS READ_LOCK_BASE(Channels, CHANNELS)
+#define WRITE_LOCK_CHANNELS WRITE_LOCK_BASE(Channels, CHANNELS)
+
+#define READ_LOCK_SCHEDULES READ_LOCK_BASE(Schedules, SCHEDULES)
+#define WRITE_LOCK_SCHEDULES WRITE_LOCK_BASE(Schedules, SCHEDULES)
+
+#define RECORDING_CONTROLS_PROCESS cRecordControls::Process(theTimers, time(NULL))
+#define LIST_ELEM_CONST const
+
+#else
+
+#define READ_LOCK_BASE(Class) c##Class * the##Class = &Class
+#define WRITE_LOCK_BASE(Class) c##Class * the##Class = &Class
+
+#define READ_LOCK_TIMERS READ_LOCK_BASE(Timers)
+#define WRITE_LOCK_TIMERS WRITE_LOCK_BASE(Timers)
+
+#define READ_LOCK_RECORDINGS READ_LOCK_BASE(Recordings)
+#define WRITE_LOCK_RECORDINGS WRITE_LOCK_BASE(Recordings)
+
+#define READ_LOCK_CHANNELS READ_LOCK_BASE(Channels)
+#define WRITE_LOCK_CHANNELS WRITE_LOCK_BASE(Channels)
+
+#define LOCKED_SCHEDULES cSchedulesLock schedulesLock; const cSchedules * theSchedules = cSchedules::Schedules(schedulesLock);
+#define READ_LOCK_SCHEDULES  LOCKED_SCHEDULES
+#define WRITE_LOCK_SCHEDULES LOCKED_SCHEDULES
+
+#define RECORDING_CONTROLS_PROCESS cRecordControls::Process(time(NULL))
+#define LIST_ELEM_CONST
+
+#endif
+
 static char ServiceInterface[] = "Epgsearch-services-v1.1";
 
 string cHelpers::GetRecordings(string args) {
@@ -103,7 +146,8 @@ string cHelpers::GetTimersIntern(string options) {
 	string result = "START\r\n";
 
 	// iterate through all timers
-	for (cTimer * timer = Timers.First(); timer; timer = Timers.Next(timer)) {
+	READ_LOCK_TIMERS;
+	for (const cTimer * timer = theTimers->First(); timer; timer = theTimers->Next(timer)) {
 		result += ToText(timer, conflicts);
 	}
 
@@ -127,9 +171,10 @@ string cHelpers::GetRecordingsIntern() {
 	string result = sstm.str();
 
 	//iterate through all recordings
-	cRecording* recording = NULL;
-	for (int i = 0; i < Recordings.Count(); i++) {
-		recording = Recordings.Get(i);
+	READ_LOCK_RECORDINGS;
+	const cRecording* recording = NULL;
+	for (int i = 0; i < theRecordings->Count(); i++) {
+		recording = theRecordings->Get(i);
 		result += ToText(recording);
 	}
 	return result + "END\r\n";
@@ -141,8 +186,9 @@ string cHelpers::GetChannelsIntern(string wantedChannels) {
 	string currentGroup = "";
 
 	char number[10];
-	for (cChannel * channel = Channels.First(); channel; channel =
-			Channels.Next(channel)) {
+	READ_LOCK_CHANNELS;
+	for (const cChannel * channel = theChannels->First(); channel; channel =
+			theChannels->Next(channel)) {
 
 		// channel group
 		if (channel->GroupSep()) {
@@ -186,7 +232,7 @@ string cHelpers::SetChannelIntern(const string args) {
 		return "!ERROR:SetChannel;empty args\r\n";
 	}
 
-	cChannel *channel;
+	const cChannel *channel;
 	bool isnum = true;
 	for (int i = 0; i < (int) args.length(); i++) {
 		if (!std::isdigit(args[i])) {
@@ -196,12 +242,13 @@ string cHelpers::SetChannelIntern(const string args) {
 
 	}
 
+	READ_LOCK_CHANNELS;
 	if (isnum) {
 		int nr = atoi(args.c_str());
-		channel = Channels.GetByNumber(nr);
+		channel = theChannels->GetByNumber(nr);
 	} else {
 		tChannelID chid = tChannelID::FromString(args.c_str());
-		channel = Channels.GetByChannelID(chid);
+		channel = theChannels->GetByChannelID(chid);
 	}
 
 	if (!channel) {
@@ -259,21 +306,21 @@ string cHelpers::GetEventsIntern(string wantedChannels, string when) {
 
 	string result = "START\r\n";
 
-	cSchedulesLock schedulesLock;
-	const cSchedules * schedules = cSchedules::Schedules(schedulesLock);
-	for (cSchedule * schedule = schedules->First(); schedule; schedule =
-			schedules->Next(schedule)) {
+	READ_LOCK_SCHEDULES;
+	READ_LOCK_CHANNELS;
+	for (const cSchedule * schedule = theSchedules->First(); schedule; schedule =
+			theSchedules->Next(schedule)) {
 
-		cChannel * channel = Channels.GetByChannelID(schedule->ChannelID());
+		const cChannel * channel = theChannels->GetByChannelID(schedule->ChannelID());
 		if (!IsWantedChannel(channel, wantedChannels)) {
 			continue;
 		}
 
 		const cList<cEvent> * events = schedule->Events();
-		for (cEvent * event = events->First(); event;
+		for (const cEvent * event = events->First(); event;
 				event = events->Next(event)) {
 			if (IsWantedTime(wantedTime, event)) {
-				cEvent * match = event;
+				const cEvent * match = event;
 				if (when == "NEXT") {
 					match = events->Next(match);
 					if (!match) {
@@ -307,7 +354,8 @@ string cHelpers::DelRecording(cRecording * recording) {
 #else
 	if (RecordingsHandler.GetUsage(FileName)) {
 		RecordingsHandler.Del(FileName);
-		recording = Recordings.GetByName(FileName); // RecordingsHandler.Del() might have deleted it if it was the edited version
+		WRITE_LOCK_RECORDINGS;
+		recording = theRecordings->GetByName(FileName); // RecordingsHandler.Del() might have deleted it if it was the edited version
 		// we continue with the code below even if recording is NULL,
 		// in order to have the menu updated etc.
 	}
@@ -318,9 +366,10 @@ string cHelpers::DelRecording(cRecording * recording) {
 		cControl::Shutdown();
 	}
 
+	WRITE_LOCK_RECORDINGS;
 	if (!recording || recording->Delete()) {
 		cReplayControl::ClearLastReplayed(FileName);
-		Recordings.DelByName(FileName);
+		theRecordings->DelByName(FileName);
 #if VDRVERSNUM > 10727
 		cVideoDiskUsage::ForceCheck();
 #endif
@@ -337,7 +386,11 @@ string cHelpers::DelRecordingIntern(string args) {
 
 	int index = atoi(args.c_str());
 
-	cRecording *recording = Recordings.Get(index);
+	cRecording *recording = NULL;
+	{
+		WRITE_LOCK_RECORDINGS;
+		recording = theRecordings->Get(index);
+	}
 	if (!recording) {
 		return Error("Recording not found");
 	}
@@ -362,12 +415,13 @@ string cHelpers::DelRecordingIntern(string args) {
 	cTimer *timer = rc->Timer();
 	if (timer) {
 		timer->Skip();
-		cRecordControls::Process(time(NULL));
+		WRITE_LOCK_TIMERS;
+		RECORDING_CONTROLS_PROCESS;
 		if (timer->IsSingleEvent()) {
 			isyslog("deleting timer %s", *timer->ToDescr());
-			Timers.Del(timer);
+			theTimers->Del(timer);
 		}
-		Timers.SetModified();
+		theTimers->SetModified();
 	}
 	return cHelpers::DelRecording(recording);
 }
@@ -397,23 +451,20 @@ string cHelpers::SetTimerIntern(char op, string param) {
 			return Error("Error in timer settings");
 		}
 
-		cTimer* checkTimer = Timers.GetTimer(newTimer.get());
+		WRITE_LOCK_TIMERS;
+		cTimer* checkTimer = theTimers->GetTimer(newTimer.get());
 		if (checkTimer) {
 			return Error("Timer already defined");
 		}
 
-		Timers.Add(newTimer.get());
-		Timers.SetModified();
+		theTimers->Add(newTimer.get());
+		theTimers->SetModified();
 		dsyslog("[vdrmanager] timer %s added", *newTimer->ToDescr());
 		newTimer.release();
 		break;
 	}
 	case 'D':
 	case 'd': {
-		if (Timers.BeingEdited()) {
-			return Error("Timers are being edited - try again later");
-		}
-
 		dsyslog("[vdrmanager] try parse %s ", param.c_str());
 
 		auto_ptr<cTimer> timer(new cTimer);
@@ -423,7 +474,8 @@ string cHelpers::SetTimerIntern(char op, string param) {
 
 		dsyslog("[vdrmanager] timer %s parsed", *timer->ToDescr());
 
-		cTimer * t = Timers.GetTimer(timer.get());
+		WRITE_LOCK_TIMERS;
+		cTimer * t = theTimers->GetTimer(timer.get());
 
 		if (!t) {
 			return Error("Timer not defined");
@@ -437,24 +489,20 @@ string cHelpers::SetTimerIntern(char op, string param) {
 		if (t->Recording()) {
 			if (forceDelete == true) {
 				t->Skip();
-				cRecordControls::Process(time(NULL));
+				RECORDING_CONTROLS_PROCESS;
 			} else {
 				return Error("Timer  is recording");
 			}
 		}
 
 		dsyslog("[vdrmanager] deleting timer %s", *t->ToDescr());
-		Timers.Del(t);
-		Timers.SetModified();
+		theTimers->Del(t);
+		theTimers->SetModified();
 		break;
 	}
 	case 'M':
 	case 'm': {
 
-		if (Timers.BeingEdited()) {
-			return Error("Timers are being edited - try again later");
-		}
-
 		string sep = string(TIMER_SEP);
 
 		size_t idx = param.find(sep);
@@ -470,7 +518,8 @@ string cHelpers::SetTimerIntern(char op, string param) {
 			return Error("Error in timer settings");
 		}
 
-		cTimer* oldTimer = Timers.GetTimer(otimer.get());
+		WRITE_LOCK_TIMERS;
+		cTimer* oldTimer = theTimers->GetTimer(otimer.get());
 		if (oldTimer == 0) {
 			return Error("Timer not defined");
 		}
@@ -481,7 +530,7 @@ string cHelpers::SetTimerIntern(char op, string param) {
 		}
 
 		*oldTimer = copy;
-		Timers.SetModified();
+		theTimers->SetModified();
 		dsyslog("[vdrmanager] timer %s modified (%s)", *oldTimer->ToDescr(),
 				oldTimer->HasFlags(tfActive) ? "active" : "inactive");
 
@@ -489,22 +538,19 @@ string cHelpers::SetTimerIntern(char op, string param) {
 	}
 	case 'T':
 	case 't': {
-		if (Timers.BeingEdited()) {
-			return Error("Timers are being edited - try again later");
-		}
-
 		auto_ptr<cTimer> timer(new cTimer);
 		if (!timer->Parse(param.c_str())) {
 			return Error("Error in timer settings");
 		}
 
-		cTimer* toggleTimer = Timers.GetTimer(timer.get());
+		WRITE_LOCK_TIMERS;
+		cTimer* toggleTimer = theTimers->GetTimer(timer.get());
 		if (toggleTimer == 0) {
 			return Error("Timer not defined");
 		}
 
 		toggleTimer->OnOff();
-		Timers.SetModified();
+		theTimers->SetModified();
 		dsyslog("[vdrmanager] timer %s toggled %s", *toggleTimer->ToDescr(),
 				toggleTimer->HasFlags(tfActive) ? "on" : "off");
 		break;
@@ -524,10 +570,6 @@ string cHelpers::SetTimerIntern(string args) {
 //return "!ERROR:no separator found\r\n";
 //}
 
-	if (Timers.BeingEdited()) {
-		return Error("Timers are being edited - try again later");
-	}
-
 	char operation = args[0];
 
 	args = Trim(args.substr(1));
@@ -557,18 +599,18 @@ string cHelpers::SearchEventsIntern(string wantedChannels, string pattern) {
 
 	string result = "START\r\n";
 
-	cSchedulesLock schedulesLock;
-	const cSchedules * schedules = cSchedules::Schedules(schedulesLock);
-	for (cSchedule * schedule = schedules->First(); schedule; schedule =
-			schedules->Next(schedule)) {
+	READ_LOCK_SCHEDULES;
+	READ_LOCK_CHANNELS;
+	for (const cSchedule * schedule = theSchedules->First(); schedule; schedule =
+			theSchedules->Next(schedule)) {
 
-		cChannel * channel = Channels.GetByChannelID(schedule->ChannelID());
+		const cChannel * channel = theChannels->GetByChannelID(schedule->ChannelID());
 		if (!IsWantedChannel(channel, wantedChannels)) {
 			continue;
 		}
 
 		const cList<cEvent> * events = schedule->Events();
-		for (cEvent * event = events->First(); event;
+		for (const cEvent * event = events->First(); event;
 				event = events->Next(event)) {
 
 			if (IsWantedTime(0, event) && IsWantedEvent(event, pattern)) { //time must be ok, so stop > now
@@ -582,7 +624,7 @@ string cHelpers::SearchEventsIntern(string wantedChannels, string pattern) {
 
 //copied from vdr-live
 
-long cHelpers::Duration(cRecording* recording) {
+long cHelpers::Duration(const cRecording* recording) {
 	long RecLength = 0;
 	if (!recording->FileName())
 		return 0;
@@ -623,7 +665,7 @@ long cHelpers::Duration(cRecording* recording) {
 	return RecLength;
 }
 
-string cHelpers::ToText(cRecording * recording) {
+string cHelpers::ToText(const cRecording * recording) {
 	const cRecordingInfo * info = recording->Info();
 #if APIVERSNUM >= 10705
 	const cEvent * event = info->GetEvent();
@@ -755,7 +797,7 @@ string cHelpers::ToText(cRecording * recording) {
 	return result;
 }
 
-string cHelpers::ToText(cTimer * timer, set<string> conflicts) {
+string cHelpers::ToText(const cTimer * timer, set<string> conflicts) {
 
 	const cChannel * channel = timer->Channel();
 	const char * channelName = channel->Name();
@@ -808,16 +850,16 @@ string cHelpers::ToText(cTimer * timer, set<string> conflicts) {
 	const cEvent * event = timer->Event();
 	if (!event) {
 		dsyslog("[vdrmanager] timer's event is NULL. Try find it");
-		cChannel * channel = Channels.GetByChannelID(
+		READ_LOCK_CHANNELS;
+		const cChannel * channel = theChannels->GetByChannelID(
 				timer->Channel()->GetChannelID());
 		if (channel) {
-			cSchedulesLock schedulesLock;
-			const cSchedules * schedules = cSchedules::Schedules(schedulesLock);
-			const cSchedule * schedule = schedules->GetSchedule(
+			READ_LOCK_SCHEDULES;
+			const cSchedule * schedule = theSchedules->GetSchedule(
 					channel->GetChannelID());
 			if (schedule) {
 				const cList<cEvent> * events = schedule->Events();
-				for (cEvent * ev = events->First(); event;
+				for (const cEvent * ev = events->First(); event;
 						ev = events->Next(ev)) {
 					if (timer->StartTime() <= ev->StartTime()
 							&& timer->StopTime()
@@ -873,7 +915,8 @@ string cHelpers::ToText(cTimer * timer, set<string> conflicts) {
 
 string cHelpers::ToText(const cEvent * event) {
 
-	cChannel * channel = Channels.GetByChannelID(
+	READ_LOCK_CHANNELS;
+	LIST_ELEM_CONST cChannel * channel = theChannels->GetByChannelID(
 			event->Schedule()->ChannelID());
 
 // search assigned timer
@@ -936,7 +979,8 @@ string cHelpers::ToText(const cEvent * event) {
 
 	result += "\r\n";
 
-	cTimer * eventTimer = Timers.GetMatch(event);
+	READ_LOCK_TIMERS;
+	LIST_ELEM_CONST cTimer * eventTimer = theTimers->GetMatch(event);
 
 	if (eventTimer) {
 		result += ToText(eventTimer, set<string>());
@@ -945,7 +989,7 @@ string cHelpers::ToText(const cEvent * event) {
 	return result;
 }
 
-bool cHelpers::IsWantedEvent(cEvent * event, string pattern) {
+bool cHelpers::IsWantedEvent(const cEvent * event, string pattern) {
 
 	string text = event->Title();
 	if (event->Description()) {
@@ -955,7 +999,7 @@ bool cHelpers::IsWantedEvent(cEvent * event, string pattern) {
 	return ToLower(text).find(ToLower(pattern)) != string::npos;
 }
 
-bool cHelpers::IsWantedChannel(cChannel * channel, string wantedChannels) {
+bool cHelpers::IsWantedChannel(const cChannel * channel, string wantedChannels) {
 
 	if (!channel) {
 		return false;
@@ -998,7 +1042,7 @@ bool cHelpers::IsWantedChannel(cChannel * channel, string wantedChannels) {
 	return found;
 }
 
-bool cHelpers::IsWantedTime(time_t when, cEvent * event) {
+bool cHelpers::IsWantedTime(time_t when, const cEvent * event) {
 
 	time_t startTime = event->StartTime();
 	time_t stopTime = startTime + event->Duration();
@@ -1142,7 +1186,7 @@ string cHelpers::UnMapSpecialChars(string text) {
 /**
  * based on vdr-restfulapi's RecordingLengthInSeconds
  */
-int cHelpers::RecordingLengthInSeconds(cRecording* recording) {
+int cHelpers::RecordingLengthInSeconds(const cRecording* recording) {
 	return Duration(recording) * 60;
 }
 
diff --git a/helpers.h b/helpers.h
index d6e2a14..75701d7 100644
--- a/helpers.h
+++ b/helpers.h
@@ -32,7 +32,7 @@ public:
   static string ToUpper(string text);
   static string ToLower(string text);
   static string Trim(string text);
-  static long 	Duration(cRecording* recording);
+  static long 	Duration(const cRecording* recording);
 private:
   static string SafeCall(string (*)());
   static string SafeCall(string (*)(string), string arg);
@@ -45,21 +45,21 @@ private:
   static string DelRecordingIntern(string index);
   static string SetTimerIntern(string args);
   static string SearchEventsIntern(string wantedChannels, string pattern);
-  static bool IsWantedEvent(cEvent * event, string pattern);
-  static bool IsWantedChannel(cChannel * channel, string wantedChannels);
-  static bool IsWantedTime(time_t when, cEvent * event);
+  static bool IsWantedEvent(const cEvent * event, string pattern);
+  static bool IsWantedChannel(const cChannel * channel, string wantedChannels);
+  static bool IsWantedTime(time_t when, const cEvent * event);
   static string MapSpecialChars(const char * text);
   static string MapSpecialChars(const cString text);
   static string MapSpecialChars(const string text);
   static string ToText(const cEvent * event);
-  static string ToText(cTimer * timer, set<string> conflicts);
-  static string ToText(cRecording * recording);
+  static string ToText(const cTimer * timer, set<string> conflicts);
+  static string ToText(const cRecording * recording);
   static string GetAudioTracks(const cChannel* channel);
   static string replaceAll(const string& where, const string& what, const string& replacement);
   static string UnMapSpecialChars(string text);
   static string Error(const string &error);
   static string SetTimerIntern(char c, string params);
-  static int RecordingLengthInSeconds(cRecording* recording);
+  static int RecordingLengthInSeconds(const cRecording* recording);
   static string ConvertWeekdays(int v);
   static int ConvertWeekdays(string v);
   static queue<int> ConvertToBinary(int v);
diff --git a/select.cpp b/select.cpp
index 5e78584..f1cb34b 100644
--- a/select.cpp
+++ b/select.cpp
@@ -172,7 +172,7 @@ bool cSelect::Poll() {
 	}
 	if (rc < 0) {
 		LOG_ERROR;
-		delete pollfds;
+		delete[] pollfds;
 		return false;
 	}
 
@@ -227,7 +227,7 @@ bool cSelect::Poll() {
     }
 	}
 
-	delete pollfds;
+	delete[] pollfds;
 
 	return true;
 }
diff --git a/serversock.cpp b/serversock.cpp
index 0cd9f1f..0c44a45 100644
--- a/serversock.cpp
+++ b/serversock.cpp
@@ -19,14 +19,9 @@ static int clientno = 0;
  */
 cVdrmanagerServerSocket::cVdrmanagerServerSocket() : cVdrmanagerSocket() {
   port = -1;
-  sslCtx = NULL;
 }
 
 cVdrmanagerServerSocket::~cVdrmanagerServerSocket() {
-#if VDRMANAGER_USE_SSL
-  if (sslCtx)
-    SSL_CTX_free(sslCtx);
-#endif
 }
 
 bool cVdrmanagerServerSocket::Create(int port, const char * password, bool forceCheckSvrp, int compressionMode,
@@ -34,8 +29,10 @@ bool cVdrmanagerServerSocket::Create(int port, const char * password, bool force
 
   this->port = port;
   this->password = password;
-	this->forceCheckSvdrp = forceCheckSvrp;
-	this->compressionMode = compressionMode;
+  this->forceCheckSvdrp = forceCheckSvrp;
+  this->compressionMode = compressionMode;
+  this->certFile = certFile;
+  this->keyFile = keyFile;
 
 	// create socket
 	sock = socket(PF_INET, SOCK_STREAM, 0);
@@ -75,8 +72,7 @@ bool cVdrmanagerServerSocket::Create(int port, const char * password, bool force
 	}
 
 #if VDRMANAGER_USE_SSL
-
-  if (certFile) {
+	if (certFile) {
     isyslog("[vdrmanager] initialize SSL");
 
     OpenSSL_add_all_algorithms();
@@ -86,71 +82,44 @@ bool cVdrmanagerServerSocket::Create(int port, const char * password, bool force
 
     SSL_load_error_strings();
     SSL_library_init();
-
-    SSL_METHOD * method = (SSL_METHOD *)SSLv23_server_method();
-    sslCtx = SSL_CTX_new(method);
-    if (sslCtx == NULL) {
-      long errorCode = ERR_get_error();
-      char * error = ERR_error_string(errorCode, NULL);
-      esyslog("[vdrmanager] Error initializing SSL context: %s", error);
-      Close();
-      return false;
-    }
-    SSL_CTX_set_options(sslCtx, SSL_OP_NO_SSLv3);
-
-    /* set the local certificate from CertFile */
-   SSL_CTX_use_certificate_file(sslCtx, certFile, SSL_FILETYPE_PEM);
-    /* set the private key from KeyFile */
-   SSL_CTX_use_PrivateKey_file(sslCtx, keyFile, SSL_FILETYPE_PEM);
-    /* verify private key */
-   if (!SSL_CTX_check_private_key(sslCtx)) {
-     long errorCode = ERR_get_error();
-     char * error = ERR_error_string(errorCode, NULL);
-     esyslog("[vdrmanager] Error checking SSL keys: %s", error);
-     Close();
-     return false;
-   }
-
-   SSL_CTX_set_mode(sslCtx, SSL_MODE_ENABLE_PARTIAL_WRITE);
-  }
+	}
 #endif
-
 	return true;
 }
 
 cVdrmanagerClientSocket * cVdrmanagerServerSocket::Accept() {
-        cVdrmanagerClientSocket * newsocket = NULL;
-
-        isyslog("[vdrmanager] new %sclient on port %d", sslCtx ? "SSL " : "", port);
-
-        // accept the connection
-        struct sockaddr_in clientname;
-        uint size = sizeof(clientname);
-        int newsock = accept(sock, (struct sockaddr *) &clientname, &size);
-        if (newsock > 0) {
-                // create client socket
-                newsocket = new cVdrmanagerClientSocket(password, compressionMode);
-                if (!newsocket->Attach(newsock, sslCtx)) {
-                        delete newsocket;
-                        return NULL;
-                }
-
-                if (!IsPasswordSet() || forceCheckSvdrp == true) {
-                        bool accepted = SVDRPhosts.Acceptable(clientname.sin_addr.s_addr);
-                        if (!accepted) {
-                                newsocket->Write(string("NACC Access denied.\n"));
-                                newsocket->Flush();
-                                delete newsocket;
-                                newsocket = NULL;
-                        }
-                        dsyslog(
-                                        "[vdrmanager] connect from %s, port %hd - %s", inet_ntoa(clientname.sin_addr), ntohs(clientname.sin_port), accepted ? "accepted" : "DENIED");
-                }
-        } else if (errno != EINTR && errno != EAGAIN
-                )
-                LOG_ERROR;
-
-        return newsocket;
+  cVdrmanagerClientSocket * newsocket = NULL;
+
+  isyslog("[vdrmanager] new client on port %d", port);
+
+  // accept the connection
+  struct sockaddr_in clientname;
+  uint size = sizeof(clientname);
+  int newsock = accept(sock, (struct sockaddr *) &clientname, &size);
+  if (newsock > 0) {
+    // create client socket
+    newsocket = new cVdrmanagerClientSocket(password, compressionMode, certFile, keyFile);
+    if (!newsocket->Attach(newsock)) {
+      delete newsocket;
+      return NULL;
+    }
+
+    if (!IsPasswordSet() || forceCheckSvdrp == true) {
+      bool accepted = SVDRPhosts.Acceptable(clientname.sin_addr.s_addr);
+      if (!accepted) {
+        newsocket->Write(string("NACC Access denied.\n"));
+        newsocket->Flush();
+        delete newsocket;
+        newsocket = NULL;
+      }
+      dsyslog("[vdrmanager] connect from %s, port %hd - %s",
+          inet_ntoa(clientname.sin_addr), ntohs(clientname.sin_port),
+          accepted ? "accepted" : "DENIED");
+    }
+  } else if (errno != EINTR && errno != EAGAIN)
+    LOG_ERROR;
+
+  return newsocket;
 }
 
 int cVdrmanagerServerSocket::GetPort() {
diff --git a/serversock.h b/serversock.h
index e8c939e..6269574 100644
--- a/serversock.h
+++ b/serversock.h
@@ -24,7 +24,6 @@ class cVdrmanagerServerSocket : public cVdrmanagerSocket
 {
 private:
   int port;
-  SSL_CTX * sslCtx;
 public:
   cVdrmanagerServerSocket();
   virtual ~cVdrmanagerServerSocket();
diff --git a/sock.h b/sock.h
index bc19d6d..4cc550f 100644
--- a/sock.h
+++ b/sock.h
@@ -25,6 +25,8 @@ protected:
   const char * password;
   bool forceCheckSvdrp;
   int compressionMode;
+  const char * certFile;
+  const char * keyFile;
 protected:
   cVdrmanagerSocket();
   bool IsPasswordSet();
diff --git a/vdrmanager.cpp b/vdrmanager.cpp
index de1fbe3..791d6a5 100644
--- a/vdrmanager.cpp
+++ b/vdrmanager.cpp
@@ -35,7 +35,7 @@
 #endif
 #define VDRMANAGER_ARGS VDRMANAGER_ARGS_COMMON VDRMANAGER_ARGS_SSL VDRMANAGER_ARGS_COMPRESS
 
-static const char *VERSION = "0.13";
+static const char *VERSION = "0.14";
 static const char *DESCRIPTION = "VDR-Manager plugin";
 
 class cVdrManager: public cPlugin {
@@ -159,7 +159,7 @@ bool cVdrManager::ProcessArgs(int argc, char *argv[]) {
 		      certFile = keyFile = optarg;
 		    } else {
 		      certFile = strndup(optarg, sep - optarg);
-		      keyFile = sep;
+		      keyFile = sep+1;
 		    }
 		  }
 			break;
diff --git a/vdrmanagerthread.cpp b/vdrmanagerthread.cpp
index b0c37ba..3eaae36 100644
--- a/vdrmanagerthread.cpp
+++ b/vdrmanagerthread.cpp
@@ -68,14 +68,19 @@ bool cVdrManagerThread::Init()
 
 #if VDRMANAGER_USE_SSL
   cVdrmanagerServerSocket * sslSock;
-  if (!access(certFile, R_OK) && !access(keyFile, R_OK))  {
+  bool certFileOk = !access(certFile, R_OK);
+  bool keyFileOk = !access(keyFile, R_OK);
+  if (certFileOk && keyFileOk)  {
     sslSock = new cVdrmanagerServerSocket();
     if (sslSock == NULL || !sslSock->Create(sslPort, password, forceCheckSvdrp, compressionMode, certFile, keyFile)) {
       return false;
     }
   } else {
     sslSock = NULL;
-    esyslog("[vdrmanager] SSL key files %s and %s can't be read. SSL disabled.", certFile, keyFile);
+    if (!certFileOk)
+      esyslog("[vdrmanager] SSL cert file %s can't be read (errno %d). SSL disabled.", certFile, errno);
+    if (!keyFileOk)
+      esyslog("[vdrmanager] SSL key file %s can't be read (errno %d). SSL disabled.", keyFile, errno);
   }
 
   // register server sockets

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-vdr-dvb/vdr-plugin-vdrmanager.git



More information about the pkg-vdr-dvb-changes mailing list