diff options
-rw-r--r-- | gentoo/vdr-vdrmanager-0.12.ebuild | 29 | ||||
-rw-r--r-- | gentoo/vdr-vdrmanager-9999.ebuild | 30 | ||||
-rw-r--r-- | vdr-vdrmanager/Makefile | 21 | ||||
-rw-r--r-- | vdr-vdrmanager/clientsock.cpp | 55 | ||||
-rw-r--r-- | vdr-vdrmanager/clientsock.h | 24 | ||||
-rw-r--r-- | vdr-vdrmanager/compressor.cpp | 20 | ||||
-rw-r--r-- | vdr-vdrmanager/compressor.h | 11 | ||||
-rw-r--r-- | vdr-vdrmanager/select.cpp | 9 | ||||
-rw-r--r-- | vdr-vdrmanager/serversock.cpp | 9 | ||||
-rw-r--r-- | vdr-vdrmanager/serversock.h | 3 | ||||
-rw-r--r-- | vdr-vdrmanager/sock.cpp | 1 | ||||
-rw-r--r-- | vdr-vdrmanager/sock.h | 3 | ||||
-rw-r--r-- | vdr-vdrmanager/vdrmanager.cpp | 73 | ||||
-rw-r--r-- | vdr-vdrmanager/vdrmanagerthread.cpp | 18 | ||||
-rw-r--r-- | vdr-vdrmanager/vdrmanagerthread.h | 15 |
15 files changed, 264 insertions, 57 deletions
diff --git a/gentoo/vdr-vdrmanager-0.12.ebuild b/gentoo/vdr-vdrmanager-0.12.ebuild index 8f4bc4a..b05c5c8 100644 --- a/gentoo/vdr-vdrmanager-0.12.ebuild +++ b/gentoo/vdr-vdrmanager-0.12.ebuild @@ -15,13 +15,14 @@ SRC_URI="mirror://vdr-developerorg/${VERSION}/${P}.tar.gz" KEYWORDS="~x86 ~amd64" SLOT="0" LICENSE="GPL-2" -IUSE="-stream" +IUSE="-stream +ssl +zlib -gzip" DEPEND=">=media-video/vdr-2 - dev-libs/openssl - sys-libs/zlib - app-arch/gzip" -RDEPEND="stream? ( media-plugins/vdr-streamdev[server] )" + ssl? ( dev-libs/openssl ) + zlib? ( sys-libs/zlib )" +RDEPEND="stream? ( media-plugins/vdr-streamdev[server] ) + gzip? ( app-arch/gzip ) + $DEPEND" VDRMANAGER_SSL_KEY_DIR="/etc/vdr/plugins/vdrmanager" VDRMANAGER_SSL_KEY_FILE="${VDRMANAGER_SSL_KEY_DIR}/vdrmanager" @@ -48,12 +49,21 @@ make_vdrmanager_cert() { fperms 600 "${ROOT}${VDRMANAGER_SSL_KEY_FILE}.pem" } +src_prepare() { + + use ssl || BUILD_PARAMS="$BUILD_PARAMS VDRMANAGER_USE_SSL=0" + use gzip || BUILD_PARAMS="$BUILD_PARAMS VDRMANAGER_USE_GZIP=0" + use zlib || BUILD_PARAMS="$BUILD_PARAMS VDRMANAGER_USE_ZLIB=0" + + vdr-plugin-2_src_prepare +} + pkg_postinst() { vdr-plugin-2_pkg_postinst einfo "Add a password to /etc/conf.d/vdr.vdrmanager" - if use ssl ; then + if use ssl; then if path_exists -a "${ROOT}${VDRMANAGER_SSL_KEY_FILE}.pem"; then einfo "found an existing SSL cert, to create a new SSL cert, run:\n" einfo "emerge --config ${PN}" @@ -61,6 +71,13 @@ pkg_postinst() { einfo "No SSL cert found, creating a default one now" make_vdrmanager_cert fi + einfo + fi + + if use gzip; then + einfo 'The plugin was installed with USE flag "gzip" set.' + einfo 'You must install app-arch/gzip to use the gzip' + einfo 'compression method.' fi } diff --git a/gentoo/vdr-vdrmanager-9999.ebuild b/gentoo/vdr-vdrmanager-9999.ebuild index e26e236..632028f 100644 --- a/gentoo/vdr-vdrmanager-9999.ebuild +++ b/gentoo/vdr-vdrmanager-9999.ebuild @@ -14,13 +14,15 @@ HOMEPAGE="http://projects.vdr-developer.org/projects/vdr-manager/wiki" KEYWORDS="~x86 ~amd64" SLOT="0" LICENSE="GPL-2" -IUSE="-stream ssl gzip zlib" + +IUSE="-stream +ssl +zlib -gzip" DEPEND=">=media-video/vdr-2 - dev-libs/openssl - sys-libs/zlib - app-arch/gzip" -RDEPEND="stream? ( media-plugins/vdr-streamdev[server] )" + ssl? ( dev-libs/openssl ) + zlib? ( sys-libs/zlib )" +RDEPEND="stream? ( media-plugins/vdr-streamdev[server] ) + gzip? ( app-arch/gzip ) + $DEPEND" VDRMANAGER_SSL_KEY_DIR="/etc/vdr/plugins/vdrmanager" VDRMANAGER_SSL_KEY_FILE="${VDRMANAGER_SSL_KEY_DIR}/vdrmanager" @@ -52,12 +54,21 @@ src_unpack() { S=${WORKDIR}/${P}/${PN} } +src_prepare() { + + use ssl || BUILD_PARAMS="$BUILD_PARAMS VDRMANAGER_USE_SSL=0" + use gzip || BUILD_PARAMS="$BUILD_PARAMS VDRMANAGER_USE_GZIP=0" + use zlib || BUILD_PARAMS="$BUILD_PARAMS VDRMANAGER_USE_ZLIB=0" + + vdr-plugin-2_src_prepare +} + pkg_postinst() { vdr-plugin-2_pkg_postinst einfo "Add a password to /etc/conf.d/vdr.vdrmanager" - if use ssl ; then + if use ssl; then if path_exists -a "${ROOT}${VDRMANAGER_SSL_KEY_FILE}.pem"; then einfo "found an existing SSL cert, to create a new SSL cert, run:\n" einfo "emerge --config ${PN}" @@ -65,6 +76,13 @@ pkg_postinst() { einfo "No SSL cert found, creating a default one now" make_vdrmanager_cert fi + einfo + fi + + if use gzip; then + einfo 'The plugin was installed with USE flag "gzip" set.' + einfo 'You must install app-arch/gzip to use the gzip' + einfo 'compression method.' fi } diff --git a/vdr-vdrmanager/Makefile b/vdr-vdrmanager/Makefile index a5119ce..0e483f1 100644 --- a/vdr-vdrmanager/Makefile +++ b/vdr-vdrmanager/Makefile @@ -45,6 +45,25 @@ SOFILE = libvdr-$(PLUGIN).so -DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' +### Conditionally definitions + +VDRMANAGER_USE_SSL := 1 +ifneq ($(VDRMANAGER_USE_SSL), 0) +ADDITIONAL_LIBS = $(shell pkg-config --libs openssl) +DEFINES += -DVDRMANAGER_USE_SSL=$(VDRMANAGER_USE_SSL) +endif + +VDRMANAGER_USE_ZLIB := 1 +ifneq ($(VDRMANAGER_USE_ZLIB), 0) +ADDITIONAL_LIBS += $(shell pkg-config --libs zlib) +DEFINES += -DVDRMANAGER_USE_ZLIB=$(VDRMANAGER_USE_ZLIB) +endif + +VDRMANAGER_USE_GZIP := 1 +ifneq ($(VDRMANAGER_USE_GZIP), 0) +DEFINES += -DVDRMANAGER_USE_GZIP=$(VDRMANAGER_USE_GZIP) +endif + ### The object files (add further files here): OBJS = $(PLUGIN).o sock.o serversock.o clientsock.o vdrmanagerthread.o select.o handler.o helpers.o compressor.o @@ -96,7 +115,7 @@ install-i18n: $(I18Nmsgs) ### Targets: $(SOFILE): $(OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@ -lz -lssl + $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared $(OBJS) -o $@ $(ADDITIONAL_LIBS) install-lib: $(SOFILE) install -D $^ $(LIBDIR)/$^.$(APIVERSION) diff --git a/vdr-vdrmanager/clientsock.cpp b/vdr-vdrmanager/clientsock.cpp index 91e6704..3f78007 100644 --- a/vdr-vdrmanager/clientsock.cpp +++ b/vdr-vdrmanager/clientsock.cpp @@ -3,7 +3,11 @@ */ #include <unistd.h> #include <vdr/plugin.h> + +#if VDRMANAGER_USE_SSL #include <openssl/err.h> +#endif + #include "clientsock.h" #include "helpers.h" #include "compressor.h" @@ -27,15 +31,19 @@ cVdrmanagerClientSocket::cVdrmanagerClientSocket(const char * password, int comp login = false; compression = false; initCompression = false; +#if VDRMANAGER_USE_SSL ssl = NULL; sslReadWrite = SSL_NO_RETRY; sslWantsSelect = SSL_ERROR_NONE; +#endif } cVdrmanagerClientSocket::~cVdrmanagerClientSocket() { +#if VDRMANAGER_USE_SSL if (ssl) { SSL_free(ssl); } +#endif } bool cVdrmanagerClientSocket::IsLineComplete() { @@ -73,16 +81,14 @@ bool cVdrmanagerClientSocket::Read() { if (Disconnected()) return false; - sslReadWrite = SSL_NO_RETRY; - sslWantsSelect = SSL_ERROR_NONE; - int rc; for(;;) { - if (ssl) { +#if VDRMANAGER_USE_SSL + if (ssl) rc = ReadSSL(); - } else { + else +#endif rc = ReadNoSSL(); - } // something read? if (rc <= 0) @@ -138,6 +144,8 @@ int cVdrmanagerClientSocket::ReadNoSSL() { return -2; } +#if VDRMANAGER_USE_SSL + int cVdrmanagerClientSocket::ReadSSL() { sslReadWrite = SSL_NO_RETRY; @@ -174,6 +182,7 @@ int cVdrmanagerClientSocket::ReadSSL() { esyslog("[vdrmanager] error reading from SSL (%ld) %s", errorCode, errorText); return -2; } +#endif bool cVdrmanagerClientSocket::Disconnected() { return disconnected; @@ -199,8 +208,10 @@ bool cVdrmanagerClientSocket::Flush() { sendbuf = (char *)malloc(writebuf.length()+1); strcpy(sendbuf, writebuf.c_str()); sendsize = writebuf.length(); +#if VDRMANAGER_USE_GZIP || VDRMANAGER_USE_ZLIB } else { Compress(); +#endif } sendoffset = 0; writebuf.clear(); @@ -209,11 +220,14 @@ bool cVdrmanagerClientSocket::Flush() { // write so many bytes as possible int rc; for(;sendsize > 0;) { - if (ssl) { + +#if VDRMANAGER_USE_SSL + if (ssl) rc = FlushSSL(); - } else { + else +#endif rc = FlushNoSSL(); - } + if (rc <= 0) { break; } @@ -276,6 +290,8 @@ int cVdrmanagerClientSocket::FlushNoSSL() { return -1; } +#if VDRMANAGER_USE_SSL + int cVdrmanagerClientSocket::FlushSSL() { sslReadWrite = SSL_NO_RETRY; @@ -307,12 +323,15 @@ int cVdrmanagerClientSocket::FlushSSL() { return -1; } +#endif + bool cVdrmanagerClientSocket::Attach(int fd, SSL_CTX * sslCtx) { sock = fd; if (!MakeDontBlock()) { return false; } +#if VDRMANAGER_USE_SSL if (sslCtx) { ssl = SSL_new(sslCtx); SSL_set_accept_state(ssl); @@ -320,6 +339,7 @@ bool cVdrmanagerClientSocket::Attach(int fd, SSL_CTX * sslCtx) { SSL_set_bio(ssl, bio, bio); BIO_set_nbio(bio, 1); } +#endif return true; } @@ -343,15 +363,20 @@ void cVdrmanagerClientSocket::SetLoggedIn() { void cVdrmanagerClientSocket::ActivateCompression() { string mode = "NONE"; + switch (compressionMode) { +#if VDRMANAGER_USE_GZIP case COMPRESSION_GZIP: mode = "GZIP"; initCompression = true; break; +#endif +#if VDRMANAGER_USE_ZLIB case COMPRESSION_ZLIB: mode = "ZLIB"; initCompression = true; break; +#endif default: mode = "NONE"; break; @@ -360,16 +385,22 @@ void cVdrmanagerClientSocket::ActivateCompression() { Write("!OK " + mode + "\r\n"); } +#if VDRMANAGER_USE_GZIP || VDRMANAGER_USE_ZLIB + void cVdrmanagerClientSocket::Compress() { cCompressor compressor = cCompressor(); switch (compressionMode) { +#if VDRMANAGER_USE_GZIP case COMPRESSION_GZIP: compressor.CompressGzip(writebuf); break; +#endif +#if VDRMANAGER_USE_ZLIB case COMPRESSION_ZLIB: compressor.CompressZlib(writebuf); break; +#endif } sendbuf = compressor.GetData(); @@ -379,6 +410,10 @@ void cVdrmanagerClientSocket::Compress() { dsyslog("[vdrmanager] Compression stats: raw %ld, compressed %ld, ratio %f:1", writebuf.length(), sendsize, ratio); } +#endif + +#if VDRMANAGER_USE_SSL + int cVdrmanagerClientSocket::GetSslReadWrite() { return sslReadWrite; } @@ -390,3 +425,5 @@ int cVdrmanagerClientSocket::GetSslWantsSelect() { bool cVdrmanagerClientSocket::IsSSL() { return ssl != NULL; } + +#endif diff --git a/vdr-vdrmanager/clientsock.h b/vdr-vdrmanager/clientsock.h index d921650..6c3fba3 100644 --- a/vdr-vdrmanager/clientsock.h +++ b/vdr-vdrmanager/clientsock.h @@ -8,7 +8,13 @@ #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> + +#if VDRMANAGER_USE_SSL #include <openssl/ssl.h> +#else +#define SSL_CTX void +#endif + #include <string> #include "sock.h" @@ -30,9 +36,11 @@ private: bool compression; bool initCompression; int compressionMode; +#if VDRMANAGER_USE_SSL SSL * ssl; int sslReadWrite; int sslWantsSelect; +#endif public: cVdrmanagerClientSocket(const char * password, int compressionMode); virtual ~cVdrmanagerClientSocket(); @@ -42,21 +50,25 @@ public: void Write(string line); bool Read(); int ReadNoSSL(); - int ReadSSL(); - bool Disconnected(); - void Disconnect(); bool Flush(); int FlushNoSSL(); +#if VDRMANAGER_USE_SSL + int ReadSSL(); int FlushSSL(); + int GetSslReadWrite(); + int GetSslWantsSelect(); + bool IsSSL(); +#endif + bool Disconnected(); + void Disconnect(); int GetClientId(); bool WritePending(); bool IsLoggedIn(); void SetLoggedIn(); void ActivateCompression(); +#if VDRMANAGER_USE_GZIP || VDRMANAGER_USE_ZLIB void Compress(); - int GetSslReadWrite(); - int GetSslWantsSelect(); - bool IsSSL(); +#endif }; #endif diff --git a/vdr-vdrmanager/compressor.cpp b/vdr-vdrmanager/compressor.cpp index c8322b8..b4c9051 100644 --- a/vdr-vdrmanager/compressor.cpp +++ b/vdr-vdrmanager/compressor.cpp @@ -5,14 +5,21 @@ * Author: bju */ -#include "compressor.h" +#if VDRMANAGER_USE_ZLIB || VDRMANAGER_USE_GZIP -#include <zlib.h> #include <malloc.h> #include <string.h> #include <stdlib.h> +#include <unistd.h> + +#include "compressor.h" + +#if VDRMANAGER_USE_ZLIB +#include <zlib.h> #define CHUNK 16384 +#endif + cCompressor::cCompressor() { size = 0; @@ -23,6 +30,8 @@ cCompressor::~cCompressor() { } +#if VDRMANAGER_USE_GZIP + bool cCompressor::CompressGzip(string text) { int in_fd[2]; @@ -94,6 +103,10 @@ bool cCompressor::CompressGzip(string text) { return true; } +#endif + +#if VDRMANAGER_USE_ZLIB + bool cCompressor::CompressZlib(string text) { int ret, flush; @@ -160,6 +173,8 @@ bool cCompressor::CompressZlib(string text) { return true; } +#endif + char * cCompressor::GetData() { return data; } @@ -168,3 +183,4 @@ size_t cCompressor::getDataSize() { return size; } +#endif diff --git a/vdr-vdrmanager/compressor.h b/vdr-vdrmanager/compressor.h index fbcc14f..933d4c0 100644 --- a/vdr-vdrmanager/compressor.h +++ b/vdr-vdrmanager/compressor.h @@ -4,13 +4,15 @@ * Created on: 23.03.2013 * Author: bju */ - #ifndef COMPRESSOR_H_ #define COMPRESSOR_H_ #include <string> #define COMPRESSION_NONE 0 + +#if VDRMANAGER_USE_ZLIB || VDRMANAGER_USE_GZIP + #define COMPRESSION_ZLIB 1 #define COMPRESSION_GZIP 2 @@ -23,10 +25,17 @@ private: public: cCompressor(); virtual ~cCompressor(); +#if VDRMANAGER_USE_GZIP bool CompressGzip(string text); +#endif +#if VDRMANAGER_USE_ZLIB bool CompressZlib(string text); +#endif char * GetData(); size_t getDataSize(); }; + +#endif + #endif /* COMPRESSOR_H_ */ diff --git a/vdr-vdrmanager/select.cpp b/vdr-vdrmanager/select.cpp index 2080ad0..5e78584 100644 --- a/vdr-vdrmanager/select.cpp +++ b/vdr-vdrmanager/select.cpp @@ -134,6 +134,7 @@ int cSelect::CreatePollfds() { while (curnode) { cVdrmanagerClientSocket * sock = curnode->socket; pollfds[i].fd = sock->GetSocket(); +#if VDRMANAGER_USE_SSL if (sock->IsSSL()) { if (sock->GetSslWantsSelect() == SSL_ERROR_WANT_READ) { pollfds[i].events = POLLIN | POLLHUP; @@ -145,10 +146,13 @@ int cSelect::CreatePollfds() { pollfds[i].events |= POLLOUT; } } else { +#endif pollfds[i].events = POLLIN | POLLHUP; if (curnode->socket->WritePending()) pollfds[i].events |= POLLOUT; +#if VDRMANAGER_USE_SSL } +#endif pollfds[i++].revents = 0; curnode = curnode->next; } @@ -180,13 +184,16 @@ bool cSelect::Poll() { for (int i = (sslServersocket ? 2 : 1); i < count; i++) { cVdrmanagerClientSocket * sock = GetClientSocket(pollfds[i].fd); if (sock) { +#if VDRMANAGER_USE_SSL if ((pollfds[i].revents & (POLLIN|POLLOUT)) && sock->GetSslReadWrite() != SSL_NO_RETRY) { if (sock->GetSslReadWrite() == SSL_RETRY_READ) { handler->HandleClientRequest(sock); } else { sock->Flush(); } - } else if (pollfds[i].revents & POLLOUT) { + } else +#endif + if (pollfds[i].revents & POLLOUT) { // possibly outstanding writes sock->Flush(); } else if (pollfds[i].revents & (POLLIN | POLLHUP)) { diff --git a/vdr-vdrmanager/serversock.cpp b/vdr-vdrmanager/serversock.cpp index 927a788..e118b0b 100644 --- a/vdr-vdrmanager/serversock.cpp +++ b/vdr-vdrmanager/serversock.cpp @@ -3,7 +3,11 @@ */ #include <unistd.h> #include <vdr/plugin.h> + +#if VDRMANAGER_USE_SSL #include <openssl/err.h> +#endif + #include "serversock.h" #include "helpers.h" #include "compressor.h" @@ -19,8 +23,10 @@ cVdrmanagerServerSocket::cVdrmanagerServerSocket() : cVdrmanagerSocket() { } 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, @@ -68,6 +74,8 @@ bool cVdrmanagerServerSocket::Create(int port, const char * password, bool force return false; } +#if VDRMANAGER_USE_SSL + if (certFile) { isyslog("[vdrmanager] initialize SSL"); @@ -104,6 +112,7 @@ bool cVdrmanagerServerSocket::Create(int port, const char * password, bool force SSL_CTX_set_mode(sslCtx, SSL_MODE_ENABLE_PARTIAL_WRITE); } +#endif return true; } diff --git a/vdr-vdrmanager/serversock.h b/vdr-vdrmanager/serversock.h index 53eec62..e8c939e 100644 --- a/vdr-vdrmanager/serversock.h +++ b/vdr-vdrmanager/serversock.h @@ -8,14 +8,15 @@ #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> -#include <openssl/ssl.h> #include <string> #include "clientsock.h" +#if VDRMANAGER_USE_SSL #define SSL_NO_RETRY 0 #define SSL_RETRY_READ 1 #define SSL_RETRY_WRITE 2 +#endif using namespace std; diff --git a/vdr-vdrmanager/sock.cpp b/vdr-vdrmanager/sock.cpp index 7e7da70..fbd8499 100644 --- a/vdr-vdrmanager/sock.cpp +++ b/vdr-vdrmanager/sock.cpp @@ -3,7 +3,6 @@ */ #include <unistd.h> #include <vdr/plugin.h> -#include <openssl/err.h> #include "sock.h" #include "helpers.h" #include "compressor.h" diff --git a/vdr-vdrmanager/sock.h b/vdr-vdrmanager/sock.h index f9e3ebf..bc19d6d 100644 --- a/vdr-vdrmanager/sock.h +++ b/vdr-vdrmanager/sock.h @@ -8,12 +8,13 @@ #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> -#include <openssl/ssl.h> #include <string> +#if VDRMANAGER_USE_SSL #define SSL_NO_RETRY 0 #define SSL_RETRY_READ 1 #define SSL_RETRY_WRITE 2 +#endif using namespace std; diff --git a/vdr-vdrmanager/vdrmanager.cpp b/vdr-vdrmanager/vdrmanager.cpp index 7f25f72..10dc2b5 100644 --- a/vdr-vdrmanager/vdrmanager.cpp +++ b/vdr-vdrmanager/vdrmanager.cpp @@ -15,9 +15,25 @@ #include "compressor.h" #define VDRMANAGER_PORT 6420 + +#if VDRMANAGER_USE_SSL #define VDRMANAGER_SSL_PORT 6421 #define VDRMANAGER_CRT_FILE "/etc/vdr/plugins/vdrmanager/vdrmanager.pem" #define VDRMANAGER_KEY_FILE "/etc/vdr/plugins/vdrmanager/vdrmanager.pem" +#endif + +#define VDRMANAGER_ARGS_COMMON "p:P:s" +#if VDRMANAGER_USE_SSL +#define VDRMANAGER_ARGS_SSL "k:" +#else +#define VDRMANAGER_ARGS_SSL +#endif +#if VDRMNAGER_USE_GZIP || VDRMANAGER_USE_ZLIB +#define VDRMANAGER_ARGS_COMPRESS "c::" +#else +#define VDRMANAGER_ARGS_COMPRESS +#endif +#define VDRMANAGER_ARGS VDRMANAGER_ARGS_COMMON VDRMANAGER_ARGS_SSL VDRMANAGER_ARGS_COMPRESS static const char *VERSION = "0.12"; static const char *DESCRIPTION = "VDR-Manager support plugin"; @@ -27,12 +43,14 @@ private: // Add any member variables or functions you may need here. cVdrManagerThread * Thread; int port; - int sslport; const char * password; bool forceCheckSvdrp; int compressionMode; +#if VDRMANAGER_USE_SSL + int sslport; const char * certFile; const char * keyFile; +#endif protected: public: cVdrManager(void); @@ -62,12 +80,14 @@ cVdrManager::cVdrManager(void) { // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT! Thread = NULL; port = VDRMANAGER_PORT; - sslport = VDRMANAGER_SSL_PORT; password = ""; forceCheckSvdrp = false; compressionMode = COMPRESSION_NONE; +#if VDRMANAGER_USE_SSL + sslport = VDRMANAGER_SSL_PORT; certFile = VDRMANAGER_CRT_FILE; keyFile = VDRMANAGER_KEY_FILE; +#endif } cVdrManager::~cVdrManager() { @@ -88,15 +108,19 @@ const char * cVdrManager::CommandLineHelp(void) { " -s force check against svdrphosts.conf, even if a password was given\n" " -c compression selects the compression mode to use ('z' for zlib or 'g' for gzip and 'n' for none).\n" " Zlib compression is enabled as default or is default compression if youf specify -c without arguments"; - " -k certfile[,keyfile] cert and key file for SSL (or one file for both)"; +#if VDRMANAGER_USE_SSL + " -k certfile[,keyfile] cert and key file for SSL (or one file for both)" +#endif + ; } bool cVdrManager::ProcessArgs(int argc, char *argv[]) { int c; - while ((c = getopt(argc, argv, "c::p:P:st:k:")) != -1) + while ((c = getopt(argc, argv, VDRMANAGER_ARGS)) != -1) switch (c) { case 'p': port = atoi(optarg); +#if VDRMANAGER_USE_SSL { const char * sep = strchr(optarg, ','); if (sep) @@ -104,6 +128,7 @@ bool cVdrManager::ProcessArgs(int argc, char *argv[]) { else sslport = port + 1; } +#endif break; case 'P': password = optarg; @@ -111,6 +136,7 @@ bool cVdrManager::ProcessArgs(int argc, char *argv[]) { case 's': forceCheckSvdrp = true; break; +#if VDRMANAGER_USE_GZIP || VDRMANAGER_USE_ZLIB case 'c': if (!optarg) { compressionMode = COMPRESSION_ZLIB; @@ -124,27 +150,34 @@ bool cVdrManager::ProcessArgs(int argc, char *argv[]) { return false; } break; - case 'k': { - const char * sep = strchr(optarg, ','); - if (sep == NULL) { - certFile = keyFile = optarg; - } else { - certFile = strndup(optarg, sep - optarg); - keyFile = sep; - } - } +#endif +#if VDRMANAGER_USE_SSL + case 'k': + { + const char * sep = strchr(optarg, ','); + if (sep == NULL) { + certFile = keyFile = optarg; + } else { + certFile = strndup(optarg, sep - optarg); + keyFile = sep; + } + } break; +#endif case '?': return false; default: return false; } -// default port + // default port if (port <= 0) port = VDRMANAGER_PORT; + +#if VDRMANAGER_USE_SSL if (sslport <= 0) sslport = port + 1; +#endif return true; } @@ -153,8 +186,16 @@ bool cVdrManager::Initialize(void) { // Initialize any background activities the plugin shall perform. // Start any background activities the plugin shall perform. - Thread = new cVdrManagerThread(port, sslport, password, forceCheckSvdrp, - compressionMode, certFile, keyFile); + Thread = new cVdrManagerThread(port, +#if VDRMANAGER_USE_SSL + sslport, +#endif + password, forceCheckSvdrp + , compressionMode +#if VDRMANAGER_USE_SSL + , certFile, keyFile +#endif + ); return Thread != NULL; } diff --git a/vdr-vdrmanager/vdrmanagerthread.cpp b/vdr-vdrmanager/vdrmanagerthread.cpp index 4076881..b0c37ba 100644 --- a/vdr-vdrmanager/vdrmanagerthread.cpp +++ b/vdr-vdrmanager/vdrmanagerthread.cpp @@ -8,17 +8,27 @@ #include "select.h" #include "helpers.h" -cVdrManagerThread::cVdrManagerThread(int port, int sslPort, const char * password, bool forceCheckSvdrp, int compressionMode, - const char * certFile, const char * keyFile) +cVdrManagerThread::cVdrManagerThread(int port, +#if VDRMANAGER_USE_SSL + int sslPort, +#endif + const char * password, bool forceCheckSvdrp, + int compressionMode +#if VDRMANAGER_USE_SSL + , const char * certFile, const char * keyFile +#endif + ) { select = NULL; this->port = port; - this->sslPort = sslPort; this->password = password; this->forceCheckSvdrp = forceCheckSvdrp; this->compressionMode = compressionMode; +#if VDRMANAGER_USE_SSL + this->sslPort = sslPort; this->certFile = certFile; this->keyFile = keyFile; +#endif } cVdrManagerThread::~cVdrManagerThread() @@ -56,6 +66,7 @@ bool cVdrManagerThread::Init() // register server sockets select->SetServerSockets(sock, NULL); +#if VDRMANAGER_USE_SSL cVdrmanagerServerSocket * sslSock; if (!access(certFile, R_OK) && !access(keyFile, R_OK)) { sslSock = new cVdrmanagerServerSocket(); @@ -69,6 +80,7 @@ bool cVdrManagerThread::Init() // register server sockets select->SetServerSockets(sock, sslSock); +#endif return true; } diff --git a/vdr-vdrmanager/vdrmanagerthread.h b/vdr-vdrmanager/vdrmanagerthread.h index 57e129b..96866b7 100644 --- a/vdr-vdrmanager/vdrmanagerthread.h +++ b/vdr-vdrmanager/vdrmanagerthread.h @@ -20,15 +20,24 @@ class cVdrManagerThread : public cThread { private: cSelect * select; int port; - int sslPort; const char * password; bool forceCheckSvdrp; int compressionMode; +#if VDRMANAGER_USE_SSL + int sslPort; const char * certFile; const char * keyFile; +#endif public: - cVdrManagerThread(int port, int sslPort, const char * password, bool forceCheckSvdrp, int compressionMode, - const char * certFile, const char * keyFile); + cVdrManagerThread(int port, +#if VDRMANAGER_USE_SSL + int sslPort, +#endif + const char * password, bool forceCheckSvdrp, int compressionMode +#if VDRMANAGER_USE_SSL + , const char * certFile, const char * keyFile +#endif + ); virtual void Action(void); void Shutdown(); private: |