diff --git a/ChangeLog b/ChangeLog index b59e0ea1..3adbc039 100644 --- a/ChangeLog +++ b/ChangeLog @@ -61,6 +61,7 @@ nzbget-0.3.1: if it was not possible; - Printed messages are now translated to oem-codepage to correctly print filenames with non-english characters (windows only); + - Added remote-command "-V (--serverversion)" to print the server's version; - Added option "ThreadLimit" to prevent program from crash if it wants to create too many threads (sometimes could occur in special cases); - Fixed error on parsing of nzb-files containing percent and other special diff --git a/MessageBase.h b/MessageBase.h index c1bdd463..f3811eee 100644 --- a/MessageBase.h +++ b/MessageBase.h @@ -56,7 +56,8 @@ enum eRemoteRequest eRemoteRequestDumpDebug, eRemoteRequestEditQueue, eRemoteRequestLog, - eRemoteRequestShutdown + eRemoteRequestShutdown, + eRemoteRequestVersion }; // Possible values for field "m_iAction" of struct "SNZBEditQueueRequest": @@ -279,6 +280,21 @@ struct SNZBShutdownResponse //char m_szText[m_iTrailingDataLength]; // variable sized }; +// Server version request +struct SNZBVersionRequest +{ + SNZBRequestBase m_MessageBase; // Must be the first in the struct +}; + +// Server version response +struct SNZBVersionResponse +{ + SNZBResponseBase m_MessageBase; // Must be the first in the struct + int32_t m_bSuccess; // 0 - command failed, 1 - command executed successfully + int32_t m_iTrailingDataLength; // Length of Text-string (m_szText), following to this record + //char m_szText[m_iTrailingDataLength]; // variable sized +}; + #ifdef HAVE_PRAGMA_PACK #pragma pack() #endif diff --git a/Options.cpp b/Options.cpp index 78288370..374c4aa8 100644 --- a/Options.cpp +++ b/Options.cpp @@ -64,6 +64,7 @@ static struct option long_options[] = {"server", no_argument, 0, 's' }, {"daemon", no_argument, 0, 'D' }, {"version", no_argument, 0, 'v'}, + {"serverversion", no_argument, 0, 'V'}, {"option", required_argument, 0, 'o'}, {"append", no_argument, 0, 'A'}, {"list", no_argument, 0, 'L'}, @@ -76,14 +77,11 @@ static struct option long_options[] = {"edit", required_argument, 0, 'E'}, {"connect", no_argument, 0, 'C'}, {"quit", no_argument, 0, 'Q'}, -#ifdef DEBUG - {"test", no_argument, 0, 't'}, -#endif {0, 0, 0, 0} }; #endif -static char short_options[] = "c:hno:psvABDCG:LPUR:TE:Q"; +static char short_options[] = "c:hno:psvABDCG:LPUR:TE:QV"; // Program options static const char* OPTION_DESTDIR = "DestDir"; @@ -719,6 +717,9 @@ void Options::InitCommandLine(int argc, char* argv[]) case 'Q': m_eClientOperation = opClientRequestShutdown; break; + case 'V': + m_eClientOperation = opClientRequestVersion; + break; case '?': exit(-1); break; @@ -744,6 +745,7 @@ void Options::PrintUsage(char* com) #ifndef WIN32 " -D, --daemon Start nzbget as a server in daemon-mode\n" #endif + " -V, --serverversion Print server's version and exit\n" " -Q, --quit Shutdown the server\n" " -A, --append Send file to the server's download queue\n" " -C, --connect Attach client to server\n" diff --git a/Options.h b/Options.h index 9a869efa..6e274e3c 100644 --- a/Options.h +++ b/Options.h @@ -43,7 +43,8 @@ public: opClientRequestDumpDebug, opClientRequestEditQueue, opClientRequestLog, - opClientRequestShutdown + opClientRequestShutdown, + opClientRequestVersion }; enum EMessageTarget { diff --git a/RemoteClient.cpp b/RemoteClient.cpp index 3399dc60..00208c15 100644 --- a/RemoteClient.cpp +++ b/RemoteClient.cpp @@ -559,3 +559,24 @@ bool RemoteClient::RequestServerShutdown() m_pConnection->Disconnect(); return OK; } + +bool RemoteClient::RequestServerVersion() +{ + if (!InitConnection()) return false; + + SNZBVersionRequest VersionRequest; + InitMessageBase(&VersionRequest.m_MessageBase, eRemoteRequestVersion, sizeof(VersionRequest)); + + bool OK = m_pConnection->Send((char*)(&VersionRequest), sizeof(VersionRequest)) >= 0; + if (OK) + { + OK = ReceiveBoolResponse(); + } + else + { + perror("m_pConnection->Send"); + } + + m_pConnection->Disconnect(); + return OK; +} diff --git a/RemoteClient.h b/RemoteClient.h index 20a1071f..9a293955 100644 --- a/RemoteClient.h +++ b/RemoteClient.h @@ -56,6 +56,7 @@ public: bool RequestServerEditQueue(int iAction, int iOffset, int* pIDList, int iIDCount, bool bSmartOrder); bool RequestServerLog(int iLines); bool RequestServerShutdown(); + bool RequestServerVersion(); }; #endif diff --git a/RemoteServer.cpp b/RemoteServer.cpp index 2c6e4a4f..fb1f0535 100644 --- a/RemoteServer.cpp +++ b/RemoteServer.cpp @@ -278,6 +278,12 @@ void RequestProcessor::Dispatch() break; } + case eRemoteRequestVersion: + { + command = new VersionCommand(); + break; + } + default: error("Received unsupported request %i", ntohl(m_MessageBase.m_iType)); break; @@ -375,6 +381,17 @@ void ShutdownCommand::Execute() ExitProc(); } +void VersionCommand::Execute() +{ + SNZBVersionRequest VersionRequest; + if (!ReceiveRequest(&VersionRequest, sizeof(VersionRequest))) + { + return; + } + + SendBoolResponse(true, VERSION); +} + void DownloadCommand::Execute() { SNZBDownloadRequest DownloadRequest; diff --git a/RemoteServer.h b/RemoteServer.h index 2c0aa72d..9b62fae4 100644 --- a/RemoteServer.h +++ b/RemoteServer.h @@ -124,4 +124,10 @@ public: virtual void Execute(); }; +class VersionCommand: public MessageCommand +{ +public: + virtual void Execute(); +}; + #endif diff --git a/nzbget.cpp b/nzbget.cpp index e88647a5..359cee2b 100644 --- a/nzbget.cpp +++ b/nzbget.cpp @@ -321,6 +321,10 @@ void ProcessClientRequest() { Client->RequestServerDownload(g_pOptions->GetArgFilename(), g_pOptions->GetAddTop()); } + else if (g_pOptions->GetClientOperation() == Options::opClientRequestVersion) + { + Client->RequestServerVersion(); + } delete Client; }