diff options
author | lado <herrlado@gmail.com> | 2013-04-03 10:00:02 +0200 |
---|---|---|
committer | lado <herrlado@gmail.com> | 2013-04-03 10:00:02 +0200 |
commit | 7b14565379b6334090c84db2f8911b7757212e5b (patch) | |
tree | 6266cc964c56d0bfb6abae3c1fa9fc7298500000 | |
parent | f5b4b051f856fb5c58e1b9269d2a9f82e3c894f9 (diff) | |
download | vdr-manager-7b14565379b6334090c84db2f8911b7757212e5b.tar.gz vdr-manager-7b14565379b6334090c84db2f8911b7757212e5b.tar.bz2 |
current changes
-rw-r--r-- | vdr-vdrmanager/HISTORY | 8 | ||||
-rw-r--r-- | vdr-vdrmanager/Makefile | 2 | ||||
-rw-r--r-- | vdr-vdrmanager/examples/plugin.vdrmanager.conf | 2 | ||||
-rw-r--r-- | vdr-vdrmanager/examples/vdr.vdrmanager | 3 | ||||
-rw-r--r-- | vdr-vdrmanager/handler.cpp | 16 | ||||
-rw-r--r-- | vdr-vdrmanager/helpers.cpp | 84 | ||||
-rw-r--r-- | vdr-vdrmanager/helpers.h | 2 | ||||
-rw-r--r-- | vdr-vdrmanager/sock.h | 15 | ||||
-rw-r--r-- | vdr-vdrmanager/vdrmanager.cpp | 34 | ||||
-rw-r--r-- | vdr-vdrmanager/vdrmanagerthread.cpp | 5 | ||||
-rw-r--r-- | vdr-vdrmanager/vdrmanagerthread.h | 3 |
11 files changed, 69 insertions, 105 deletions
diff --git a/vdr-vdrmanager/HISTORY b/vdr-vdrmanager/HISTORY index 34ed4d1..e62cb01 100644 --- a/vdr-vdrmanager/HISTORY +++ b/vdr-vdrmanager/HISTORY @@ -1,5 +1,11 @@ VDR Plugin 'vdrmanager' Revision History ------------------------------------ + +2013-04-xx: Version 0.10 (http://projects.vdr-developer.org/versions/show/328) +- Bug #1314: -f has not function, remove it. Deleting timers is always beeing forced +- Feature #790: use some compression (zlib, gzip) to compress responses server sides +- Feature #1319: Recording Folders + 2013-01-xx: Version 0.9 (http://projects.vdr-developer.org/versions/show/312) - Improved Timer/Recording deletion - Improved recording information (recordings command) @@ -39,7 +45,7 @@ VDR Plugin 'vdrmanager' Revision History 2011-11-06: Version 0.3 - Check against svdrphosts.conf file only if a) forced via command line argument -s or no password was specified via -P -- arguments parsing by getopts +- arguments parsing by getopts 2011-10-12: Version 0.2 - Recording Info via recordings command diff --git a/vdr-vdrmanager/Makefile b/vdr-vdrmanager/Makefile index 4fae6b6..c43fa6a 100644 --- a/vdr-vdrmanager/Makefile +++ b/vdr-vdrmanager/Makefile @@ -47,7 +47,7 @@ SOFILE = libvdr-$(PLUGIN).so ### The object files (add further files here): -OBJS = $(PLUGIN).o sock.o vdrmanagerthread.o select.o handler.o helpers.o +OBJS = $(PLUGIN).o sock.o vdrmanagerthread.o select.o handler.o helpers.o compressor.o ### The main target: diff --git a/vdr-vdrmanager/examples/plugin.vdrmanager.conf b/vdr-vdrmanager/examples/plugin.vdrmanager.conf index ec4cad3..c0c9a7d 100644 --- a/vdr-vdrmanager/examples/plugin.vdrmanager.conf +++ b/vdr-vdrmanager/examples/plugin.vdrmanager.conf @@ -5,5 +5,7 @@ # -p port port number to listen to\n" # -P password password (none if not given)" # -s force check against svdrphosts.conf even if -P option was given (password)"; +# -c selects the compression mode to use (zlib or gzip). Default is zlib" -p 6420 -P change +-c diff --git a/vdr-vdrmanager/examples/vdr.vdrmanager b/vdr-vdrmanager/examples/vdr.vdrmanager index e1d1ddb..ba53505 100644 --- a/vdr-vdrmanager/examples/vdr.vdrmanager +++ b/vdr-vdrmanager/examples/vdr.vdrmanager @@ -5,4 +5,5 @@ # -p port port number to listen to\n" # -P password password (none if not given)" # -s force check against svdrphosts.conf"; -_EXTRAOPTS="-p 6420 -P change" +# -c selects the compression mode to use (zlib or gzip). Default is zlib" +_EXTRAOPTS="-p 6420 -P change -c" diff --git a/vdr-vdrmanager/handler.cpp b/vdr-vdrmanager/handler.cpp index 43b500a..ea15296 100644 --- a/vdr-vdrmanager/handler.cpp +++ b/vdr-vdrmanager/handler.cpp @@ -17,6 +17,8 @@ bool cHandler::HandleNewClient(cVdrmanagerClientSocket * sock) bool cHandler::HandleClientRequest(cVdrmanagerClientSocket * sock) { + bool closeSocket = true; + while(sock->Read()) { // get lines @@ -48,6 +50,12 @@ bool cHandler::HandleClientRequest(cVdrmanagerClientSocket * sock) sock->SetLoggedIn(); sock->PutLine("!OK\r\n"); } + closeSocket = false; + } + else if (cmd == "COMPRESS") + { + sock->ActivateCompression(); + closeSocket = false; } else if (cmd == "TIMERS") { @@ -97,9 +105,15 @@ bool cHandler::HandleClientRequest(cVdrmanagerClientSocket * sock) else if (cmd == "QUIT") { // close socket - sock->PutLine(string("Good bye! :-)\n")); + sock->PutLine(string("Good bye! :-)\r\n")); sock->Disconnect(); } + + if (closeSocket) { + sock->Disconnect(); + } + + sock->Flush(); } } diff --git a/vdr-vdrmanager/helpers.cpp b/vdr-vdrmanager/helpers.cpp index 80721f3..7dcef54 100644 --- a/vdr-vdrmanager/helpers.cpp +++ b/vdr-vdrmanager/helpers.cpp @@ -709,6 +709,10 @@ string cHelpers::ToText(cRecording * recording) { } } + result += ":"; + //Feature #1319 + result += recording->Name(); + result += "\r\n"; return result; } @@ -1066,86 +1070,6 @@ int cHelpers::RecordingLengthInSeconds(cRecording* recording) { return Duration(recording) * 60; } -/** Compress a STL string using zlib with given compression level and return - * the binary data. */ -string cHelpers::compress_string(const string& str, int compressionlevel) { - z_stream zs; // z_stream is zlib's control structure - memset(&zs, 0, sizeof(zs)); - - if (deflateInit(&zs, compressionlevel) != Z_OK) - throw(runtime_error("deflateInit failed while compressing.")); - - zs.next_in = (Bytef*) str.data(); - zs.avail_in = str.size(); // set the z_stream's input - - int ret; - char outbuffer[32768]; - string outstring; - -// retrieve the compressed bytes blockwise - do { - zs.next_out = reinterpret_cast<Bytef*>(outbuffer); - zs.avail_out = sizeof(outbuffer); - - ret = deflate(&zs, Z_FINISH); - - if (outstring.size() < zs.total_out) { - // append the block to the output string - outstring.append(outbuffer, zs.total_out - outstring.size()); - } - } while (ret == Z_OK); - - deflateEnd(&zs); - - if (ret != Z_STREAM_END) { // an error occurred that was not EOF - ostringstream oss; - oss << "Exception during zlib compression: (" << ret << ") " << zs.msg; - throw(runtime_error(oss.str())); - } - - return outstring; -} - -/** Decompress an STL string using zlib and return the original data. */ -string cHelpers::decompress_string(const string& str) { - z_stream zs; // z_stream is zlib's control structure - memset(&zs, 0, sizeof(zs)); - - if (inflateInit(&zs) != Z_OK) - throw(runtime_error("inflateInit failed while decompressing.")); - - zs.next_in = (Bytef*) str.data(); - zs.avail_in = str.size(); - - int ret; - char outbuffer[32768]; - string outstring; - -// get the decompressed bytes blockwise using repeated calls to inflate - do { - zs.next_out = reinterpret_cast<Bytef*>(outbuffer); - zs.avail_out = sizeof(outbuffer); - - ret = inflate(&zs, 0); - - if (outstring.size() < zs.total_out) { - outstring.append(outbuffer, zs.total_out - outstring.size()); - } - - } while (ret == Z_OK); - - inflateEnd(&zs); - - if (ret != Z_STREAM_END) { // an error occurred that was not EOF - ostringstream oss; - oss << "Exception during zlib decompression: (" << ret << ") " - << zs.msg; - throw(runtime_error(oss.str())); - } - - return outstring; -} - //These three methodes were stolen from vdr-restfulapi project. Thanks! std::queue<int> cHelpers::ConvertToBinary(int v) { int b; diff --git a/vdr-vdrmanager/helpers.h b/vdr-vdrmanager/helpers.h index b9ebee5..18576be 100644 --- a/vdr-vdrmanager/helpers.h +++ b/vdr-vdrmanager/helpers.h @@ -31,8 +31,6 @@ public: static string ToUpper(string text); static string ToLower(string text); static string Trim(string text); - static string decompress_string(const string& str); - static string compress_string(const string& str, int compressionlevel = Z_BEST_COMPRESSION); static long Duration(cRecording* recording); private: static string SafeCall(string (*)()); diff --git a/vdr-vdrmanager/sock.h b/vdr-vdrmanager/sock.h index 0234afc..25a7b83 100644 --- a/vdr-vdrmanager/sock.h +++ b/vdr-vdrmanager/sock.h @@ -5,6 +5,7 @@ #ifndef _VDRMON_SOCK #define _VDRMON_SOCK +#include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <string> @@ -17,6 +18,7 @@ protected: int sock; const char * password; bool forceCheckSvdrp; + int compressionMode; protected: cVdrmanagerSocket(); bool IsPasswordSet(); @@ -33,11 +35,18 @@ class cVdrmanagerClientSocket : public cVdrmanagerSocket private: string readbuf; string writebuf; + char * sendbuf; + size_t sendsize; + size_t sendoffset; bool disconnected; + bool initDisconnect; int client; bool login; + bool compression; + bool initCompression; + int compressionMode; public: - cVdrmanagerClientSocket(const char * password); + cVdrmanagerClientSocket(const char * password, int compressionMode); virtual ~cVdrmanagerClientSocket(); bool Attach(int fd); bool IsLineComplete(); @@ -51,6 +60,8 @@ public: bool WritePending(); bool IsLoggedIn(); void SetLoggedIn(); + void ActivateCompression(); + void Compress(); }; class cVdrmanagerServerSocket : public cVdrmanagerSocket @@ -58,7 +69,7 @@ class cVdrmanagerServerSocket : public cVdrmanagerSocket public: cVdrmanagerServerSocket(); virtual ~cVdrmanagerServerSocket(); - bool Create(int port, const char * password, bool forceCheckSvdrp); + bool Create(int port, const char * password, bool forceCheckSvdrp, int compressionMode); cVdrmanagerClientSocket * Accept(); }; diff --git a/vdr-vdrmanager/vdrmanager.cpp b/vdr-vdrmanager/vdrmanager.cpp index 2b81464..6542c89 100644 --- a/vdr-vdrmanager/vdrmanager.cpp +++ b/vdr-vdrmanager/vdrmanager.cpp @@ -12,10 +12,11 @@ #include <vdr/device.h> #include <vdr/player.h> #include "vdrmanagerthread.h" +#include "compressor.h" #define VDRMANAGER_PORT 6420 -static const char *VERSION = "0.9"; +static const char *VERSION = "0.10"; static const char *DESCRIPTION = "VDR-Manager support plugin"; class cVdrManager: public cPlugin { @@ -25,7 +26,7 @@ private: int port; const char * password; bool forceCheckSvdrp; - bool forceDelete; + int compressionMode; protected: public: cVdrManager(void); @@ -57,7 +58,6 @@ cVdrManager::cVdrManager(void) { port = VDRMANAGER_PORT; password = ""; forceCheckSvdrp = false; - forceDelete = false; } cVdrManager::~cVdrManager() { @@ -73,12 +73,15 @@ cMenuSetupPage * cVdrManager::SetupMenu(void) { } const char * cVdrManager::CommandLineHelp(void) { - return " -p port port number to listen to\n -P password password (none if not given). No password forces check against svdrphosts.conf.\n -s force check against svdrphosts.conf, even if a password was given\n -f force delete of a timer or a recording even if they are active\n"; + return " -p port port number to listen to\n" + " -P password password (none if not given). No password forces check against svdrphosts.conf.\n" + " -s force check against svdrphosts.conf, even if a password was given\n" + " -c compression selects the compression mode to use (zlib or gzip). Default is zlib"; } bool cVdrManager::ProcessArgs(int argc, char *argv[]) { int c; - while ((c = getopt(argc, argv, "p:P:s:f")) != -1) + while ((c = getopt(argc, argv, "c::p:P:s")) != -1) switch (c) { case 'p': port = atoi(optarg); @@ -89,16 +92,18 @@ bool cVdrManager::ProcessArgs(int argc, char *argv[]) { case 's': forceCheckSvdrp = true; break; - case 'f': - forceDelete = true; + case 'c': + if (!optarg) { + compressionMode = COMPRESSION_ZLIB; + } else if (optarg[0] == 'g') { + compressionMode = COMPRESSION_GZIP; + } else if (optarg[0] == 'z') { + compressionMode = COMPRESSION_ZLIB; + } else { + return false; + } break; case '?': - if (optopt == 'c') { - fprintf(stderr, "Option -%c requires an argument.\n", optopt); - } else if (isprint(optopt)) - fprintf(stderr, "Unknown option `-%c'.\n", optopt); - else - fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); return false; default: return false; @@ -115,7 +120,8 @@ bool cVdrManager::Initialize(void) { // Initialize any background activities the plugin shall perform. // Start any background activities the plugin shall perform. - Thread = new cVdrManagerThread(port, password, forceCheckSvdrp); + Thread = new cVdrManagerThread(port, password, forceCheckSvdrp, + compressionMode); return Thread != NULL; } diff --git a/vdr-vdrmanager/vdrmanagerthread.cpp b/vdr-vdrmanager/vdrmanagerthread.cpp index 2a4ca64..51301e5 100644 --- a/vdr-vdrmanager/vdrmanagerthread.cpp +++ b/vdr-vdrmanager/vdrmanagerthread.cpp @@ -8,12 +8,13 @@ #include "select.h" #include "helpers.h" -cVdrManagerThread::cVdrManagerThread(int port, const char * password, bool forceCheckSvdrp) +cVdrManagerThread::cVdrManagerThread(int port, const char * password, bool forceCheckSvdrp, int compressionMode) { select = NULL; this -> port = port; this -> password = password; this -> forceCheckSvdrp = forceCheckSvdrp; + this -> compressionMode = compressionMode; } cVdrManagerThread::~cVdrManagerThread() @@ -43,7 +44,7 @@ bool cVdrManagerThread::Init() // create server socket cVdrmanagerServerSocket * sock = new cVdrmanagerServerSocket(); - if (sock == NULL || !sock->Create(port, password, forceCheckSvdrp)) + if (sock == NULL || !sock->Create(port, password, forceCheckSvdrp, compressionMode)) return false; // register server socket diff --git a/vdr-vdrmanager/vdrmanagerthread.h b/vdr-vdrmanager/vdrmanagerthread.h index 83f5f31..0dd3646 100644 --- a/vdr-vdrmanager/vdrmanagerthread.h +++ b/vdr-vdrmanager/vdrmanagerthread.h @@ -22,8 +22,9 @@ private: int port; const char * password; bool forceCheckSvdrp; + int compressionMode; public: - cVdrManagerThread(int port, const char * password, bool forceCheckSvdrp); + cVdrManagerThread(int port, const char * password, bool forceCheckSvdrp, int compressionMode); virtual void Action(void); void Shutdown(); private: |