added remote-command <-V> (--serverversion) to print the server's version

This commit is contained in:
Andrey Prygunkov
2008-01-23 18:17:00 +00:00
parent 1eddc76630
commit 21be45e89a
9 changed files with 75 additions and 6 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -43,7 +43,8 @@ public:
opClientRequestDumpDebug,
opClientRequestEditQueue,
opClientRequestLog,
opClientRequestShutdown
opClientRequestShutdown,
opClientRequestVersion
};
enum EMessageTarget
{

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;

View File

@@ -124,4 +124,10 @@ public:
virtual void Execute();
};
class VersionCommand: public MessageCommand
{
public:
virtual void Execute();
};
#endif

View File

@@ -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;
}