From f0e60ee577ccbef5e3544b8279731c88dae47870 Mon Sep 17 00:00:00 2001 From: Andrey Prygunkov Date: Thu, 19 Jun 2014 15:00:46 +0000 Subject: [PATCH] improvement in RPC-API: method "append" now returns id of added nzb-file or "0" on an error; this makes it easier for third-party apps to track added nzb-files; for backward compatibility with older software expecting a boolean result the old version of method "append" is still supported; the new version of method "append" has a different signature (order of parameters); parameter "content" can now be either nzb-file content (encoded in base 64) or an URL; this makes the method "appendurl" obsolete (still supported for compatibility); if an URL was added to queue the queue entry created for fetched nzb-file has the same "NZBID" for easier tracking --- daemon/queue/QueueCoordinator.cpp | 1 + daemon/queue/Scanner.cpp | 61 +++++--- daemon/queue/Scanner.h | 10 +- daemon/queue/UrlCoordinator.cpp | 2 +- daemon/remote/BinRpc.cpp | 2 +- daemon/remote/XmlRpc.cpp | 252 +++++++++++++----------------- daemon/remote/XmlRpc.h | 4 +- webui/feed.js | 4 +- webui/upload.js | 4 +- 9 files changed, 166 insertions(+), 174 deletions(-) diff --git a/daemon/queue/QueueCoordinator.cpp b/daemon/queue/QueueCoordinator.cpp index a363fd1f..61e4ebef 100644 --- a/daemon/queue/QueueCoordinator.cpp +++ b/daemon/queue/QueueCoordinator.cpp @@ -363,6 +363,7 @@ void QueueCoordinator::AddNZBFileToQueue(NZBFile* pNZBFile, NZBInfo* pUrlInfo, b if (pUrlInfo) { + pNZBInfo->SetID(pUrlInfo->GetID()); pDownloadQueue->GetQueue()->Remove(pUrlInfo); delete pUrlInfo; } diff --git a/daemon/queue/Scanner.cpp b/daemon/queue/Scanner.cpp index ae009b82..c0a10a94 100644 --- a/daemon/queue/Scanner.cpp +++ b/daemon/queue/Scanner.cpp @@ -67,7 +67,8 @@ Scanner::FileData::~FileData() Scanner::QueueData::QueueData(const char* szFilename, const char* szNZBName, const char* szCategory, int iPriority, const char* szDupeKey, int iDupeScore, EDupeMode eDupeMode, - NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo, EAddStatus* pAddStatus) + NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo, + EAddStatus* pAddStatus, int* pNZBID) { m_szFilename = strdup(szFilename); m_szNZBName = strdup(szNZBName); @@ -78,8 +79,9 @@ Scanner::QueueData::QueueData(const char* szFilename, const char* szNZBName, con m_eDupeMode = eDupeMode; m_bAddTop = bAddTop; m_bAddPaused = bAddPaused; - m_pAddStatus = pAddStatus; m_pUrlInfo = pUrlInfo; + m_pAddStatus = pAddStatus; + m_pNZBID = pNZBID; if (pParameters) { @@ -103,6 +105,14 @@ void Scanner::QueueData::SetAddStatus(EAddStatus eAddStatus) } } +void Scanner::QueueData::SetNZBID(int iNZBID) +{ + if (m_pNZBID) + { + *m_pNZBID = iNZBID; + } +} + Scanner::Scanner() { @@ -346,6 +356,7 @@ void Scanner::ProcessIncomingFile(const char* szDirectory, const char* szBaseFil bool bAdded = false; QueueData* pQueueData = NULL; NZBInfo* pUrlInfo = NULL; + int iNZBID = 0; for (QueueList::iterator it = m_QueueList.begin(); it != m_QueueList.end(); it++) { @@ -397,7 +408,7 @@ void Scanner::ProcessIncomingFile(const char* szDirectory, const char* szBaseFil if (bRenameOK) { bAdded = AddFileToQueue(szRenamedName, szNZBName, szNZBCategory, iPriority, - szDupeKey, iDupeScore, eDupeMode, pParameters, bAddTop, bAddPaused, pUrlInfo); + szDupeKey, iDupeScore, eDupeMode, pParameters, bAddTop, bAddPaused, pUrlInfo, &iNZBID); } else { @@ -409,7 +420,7 @@ void Scanner::ProcessIncomingFile(const char* szDirectory, const char* szBaseFil else if (bExists && !strcasecmp(szExtension, ".nzb")) { bAdded = AddFileToQueue(szFullFilename, szNZBName, szNZBCategory, iPriority, - szDupeKey, iDupeScore, eDupeMode, pParameters, bAddTop, bAddPaused, pUrlInfo); + szDupeKey, iDupeScore, eDupeMode, pParameters, bAddTop, bAddPaused, pUrlInfo, &iNZBID); } delete pParameters; @@ -420,6 +431,7 @@ void Scanner::ProcessIncomingFile(const char* szDirectory, const char* szBaseFil if (pQueueData) { pQueueData->SetAddStatus(eAddStatus == asFailed ? asFailed : bAdded ? asSuccess : asSkipped); + pQueueData->SetNZBID(iNZBID); } } @@ -459,7 +471,7 @@ void Scanner::InitPPParameters(const char* szCategory, NZBParameterList* pParame bool Scanner::AddFileToQueue(const char* szFilename, const char* szNZBName, const char* szCategory, int iPriority, const char* szDupeKey, int iDupeScore, EDupeMode eDupeMode, - NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo) + NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo, int* pNZBID) { const char* szBasename = Util::BaseFileName(szFilename); @@ -482,46 +494,52 @@ bool Scanner::AddFileToQueue(const char* szFilename, const char* szNZBName, cons if (bOK) { - pNZBFile->GetNZBInfo()->SetQueuedFilename(bakname2); + NZBInfo* pNZBInfo = pNZBFile->GetNZBInfo(); + pNZBInfo->SetQueuedFilename(bakname2); if (szNZBName && strlen(szNZBName) > 0) { - pNZBFile->GetNZBInfo()->SetName(NULL); + pNZBInfo->SetName(NULL); #ifdef WIN32 char* szAnsiFilename = strdup(szNZBName); WebUtil::Utf8ToAnsi(szAnsiFilename, strlen(szAnsiFilename) + 1); - pNZBFile->GetNZBInfo()->SetFilename(szAnsiFilename); + pNZBInfo->SetFilename(szAnsiFilename); free(szAnsiFilename); #else - pNZBFile->GetNZBInfo()->SetFilename(szNZBName); + pNZBInfo->SetFilename(szNZBName); #endif - pNZBFile->GetNZBInfo()->BuildDestDirName(); + pNZBInfo->BuildDestDirName(); } - pNZBFile->GetNZBInfo()->SetDupeKey(szDupeKey); - pNZBFile->GetNZBInfo()->SetDupeScore(iDupeScore); - pNZBFile->GetNZBInfo()->SetDupeMode(eDupeMode); - pNZBFile->GetNZBInfo()->SetPriority(iPriority); + pNZBInfo->SetDupeKey(szDupeKey); + pNZBInfo->SetDupeScore(iDupeScore); + pNZBInfo->SetDupeMode(eDupeMode); + pNZBInfo->SetPriority(iPriority); if (pUrlInfo) { - pNZBFile->GetNZBInfo()->SetURL(pUrlInfo->GetURL()); - pNZBFile->GetNZBInfo()->SetUrlStatus(pUrlInfo->GetUrlStatus()); + pNZBInfo->SetURL(pUrlInfo->GetURL()); + pNZBInfo->SetUrlStatus(pUrlInfo->GetUrlStatus()); } if (pNZBFile->GetPassword()) { - pNZBFile->GetNZBInfo()->GetParameters()->SetParameter("*Unpack:Password", pNZBFile->GetPassword()); + pNZBInfo->GetParameters()->SetParameter("*Unpack:Password", pNZBFile->GetPassword()); } - pNZBFile->GetNZBInfo()->GetParameters()->CopyFrom(pParameters); + pNZBInfo->GetParameters()->CopyFrom(pParameters); - for (::FileList::iterator it = pNZBFile->GetNZBInfo()->GetFileList()->begin(); it != pNZBFile->GetNZBInfo()->GetFileList()->end(); it++) + for (::FileList::iterator it = pNZBInfo->GetFileList()->begin(); it != pNZBInfo->GetFileList()->end(); it++) { FileInfo* pFileInfo = *it; pFileInfo->SetPaused(bAddPaused); } g_pQueueCoordinator->AddNZBFileToQueue(pNZBFile, pUrlInfo, bAddTop); + + if (pNZBID) + { + *pNZBID = pNZBInfo->GetID(); + } } delete pNZBFile; @@ -545,7 +563,7 @@ void Scanner::ScanNZBDir(bool bSyncMode) Scanner::EAddStatus Scanner::AddExternalFile(const char* szNZBName, const char* szCategory, int iPriority, const char* szDupeKey, int iDupeScore, EDupeMode eDupeMode, NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo, - const char* szFileName, const char* szBuffer, int iBufSize) + const char* szFileName, const char* szBuffer, int iBufSize, int* pNZBID) { bool bNZB = false; char szTempFileName[1024]; @@ -640,7 +658,8 @@ Scanner::EAddStatus Scanner::AddExternalFile(const char* szNZBName, const char* EAddStatus eAddStatus = asSkipped; QueueData* pQueueData = new QueueData(szScanFileName, szNZBName, szUseCategory, iPriority, - szDupeKey, iDupeScore, eDupeMode, pParameters, bAddTop, bAddPaused, pUrlInfo, &eAddStatus); + szDupeKey, iDupeScore, eDupeMode, pParameters, bAddTop, bAddPaused, pUrlInfo, + &eAddStatus, pNZBID); free(szUseCategory); m_QueueList.push_back(pQueueData); diff --git a/daemon/queue/Scanner.h b/daemon/queue/Scanner.h index 7eba7ac7..53b49551 100644 --- a/daemon/queue/Scanner.h +++ b/daemon/queue/Scanner.h @@ -76,12 +76,13 @@ private: bool m_bAddPaused; NZBInfo* m_pUrlInfo; EAddStatus* m_pAddStatus; + int* m_pNZBID; public: QueueData(const char* szFilename, const char* szNZBName, const char* szCategory, int iPriority, const char* szDupeKey, int iDupeScore, EDupeMode eDupeMode, NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo, - EAddStatus* pAddStatus); + EAddStatus* pAddStatus, int* pNZBID); ~QueueData(); const char* GetFilename() { return m_szFilename; } const char* GetNZBName() { return m_szNZBName; } @@ -95,6 +96,7 @@ private: bool GetAddPaused() { return m_bAddPaused; } NZBInfo* GetUrlInfo() { return m_pUrlInfo; } void SetAddStatus(EAddStatus eAddStatus); + void SetNZBID(int iNZBID); }; typedef std::deque QueueList; @@ -111,7 +113,7 @@ private: void CheckIncomingNZBs(const char* szDirectory, const char* szCategory, bool bCheckStat); bool AddFileToQueue(const char* szFilename, const char* szNZBName, const char* szCategory, int iPriority, const char* szDupeKey, int iDupeScore, EDupeMode eDupeMode, - NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo); + NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo, int* pNZBID); void ProcessIncomingFile(const char* szDirectory, const char* szBaseFilename, const char* szFullFilename, const char* szCategory); bool CanProcessFile(const char* szFullFilename, bool bCheckStat); @@ -126,8 +128,8 @@ public: void Check(); EAddStatus AddExternalFile(const char* szNZBName, const char* szCategory, int iPriority, const char* szDupeKey, int iDupeScore, EDupeMode eDupeMode, - NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, - NZBInfo* pUrlInfo, const char* szFileName, const char* szBuffer, int iBufSize); + NZBParameterList* pParameters, bool bAddTop, bool bAddPaused, NZBInfo* pUrlInfo, + const char* szFileName, const char* szBuffer, int iBufSize, int* pNZBID); void InitPPParameters(const char* szCategory, NZBParameterList* pParameters); }; diff --git a/daemon/queue/UrlCoordinator.cpp b/daemon/queue/UrlCoordinator.cpp index c68ce4fb..ed6ab0f9 100644 --- a/daemon/queue/UrlCoordinator.cpp +++ b/daemon/queue/UrlCoordinator.cpp @@ -416,7 +416,7 @@ void UrlCoordinator::UrlCompleted(UrlDownloader* pUrlDownloader) !Util::EmptyStr(pNZBInfo->GetCategory()) ? pNZBInfo->GetCategory() : pUrlDownloader->GetCategory(), pNZBInfo->GetPriority(), pNZBInfo->GetDupeKey(), pNZBInfo->GetDupeScore(), pNZBInfo->GetDupeMode(), pNZBInfo->GetParameters(), false, pNZBInfo->GetAddUrlPaused(), pNZBInfo, - pUrlDownloader->GetOutputFilename(), NULL, 0); + pUrlDownloader->GetOutputFilename(), NULL, 0, NULL); if (eAddStatus == Scanner::asSuccess) { diff --git a/daemon/remote/BinRpc.cpp b/daemon/remote/BinRpc.cpp index 40e9b1e0..f235354f 100644 --- a/daemon/remote/BinRpc.cpp +++ b/daemon/remote/BinRpc.cpp @@ -344,7 +344,7 @@ void DownloadBinCommand::Execute() bool bAddTop = ntohl(DownloadRequest.m_bAddFirst); bool bOK = g_pScanner->AddExternalFile(DownloadRequest.m_szFilename, DownloadRequest.m_szCategory, - iPriority, NULL, 0, dmScore, NULL, bAddTop, bAddPaused, NULL, NULL, pRecvBuffer, iBufLen) != Scanner::asFailed; + iPriority, NULL, 0, dmScore, NULL, bAddTop, bAddPaused, NULL, NULL, pRecvBuffer, iBufLen, NULL) != Scanner::asFailed; char tmp[1024]; snprintf(tmp, 1024, bOK ? "Collection %s added to queue" : "Download Request failed for %s", diff --git a/daemon/remote/XmlRpc.cpp b/daemon/remote/XmlRpc.cpp index 53e1ecd9..edb111a6 100644 --- a/daemon/remote/XmlRpc.cpp +++ b/daemon/remote/XmlRpc.cpp @@ -205,12 +205,6 @@ public: virtual void Execute(); }; -class DownloadUrlXmlCommand: public XmlCommand -{ -public: - virtual void Execute(); -}; - class UrlQueueXmlCommand: public XmlCommand { public: @@ -583,7 +577,7 @@ XmlCommand* XmlRpcProcessor::CreateCommand(const char* szMethodName) { command = new EditQueueXmlCommand(); } - else if (!strcasecmp(szMethodName, "append")) + else if (!strcasecmp(szMethodName, "append") || !strcasecmp(szMethodName, "appendurl")) { command = new DownloadXmlCommand(); } @@ -627,10 +621,6 @@ XmlCommand* XmlRpcProcessor::CreateCommand(const char* szMethodName) { command = new HistoryXmlCommand(); } - else if (!strcasecmp(szMethodName, "appendurl")) - { - command = new DownloadUrlXmlCommand(); - } else if (!strcasecmp(szMethodName, "urlqueue")) { command = new UrlQueueXmlCommand(); @@ -771,6 +761,18 @@ void XmlCommand::BuildBoolResponse(bool bOK) AppendResponse(szContent); } +void XmlCommand::BuildIntResponse(int iValue) +{ + const char* XML_RESPONSE_INT_BODY = "%i"; + const char* JSON_RESPONSE_INT_BODY = "%i"; + + char szContent[1024]; + snprintf(szContent, 1024, IsJson() ? JSON_RESPONSE_INT_BODY : XML_RESPONSE_INT_BODY, iValue); + szContent[1024-1] = '\0'; + + AppendResponse(szContent); +} + void XmlCommand::PrepareParams() { if (IsJson() && m_eHttpMethod == XmlRpcProcessor::hmPost) @@ -790,6 +792,21 @@ void XmlCommand::PrepareParams() } } +char* XmlCommand::XmlNextValue(char* szXml, const char* szTag, int* pValueLength) +{ + int iValueLen; + const char* szValue = WebUtil::XmlFindTag(szXml, "value", &iValueLen); + if (szValue) + { + char* szTagContent = (char*)WebUtil::XmlFindTag(szValue, szTag, pValueLength); + if (szTagContent <= szValue + iValueLen) + { + return szTagContent; + } + } + return NULL; +} + bool XmlCommand::NextParamAsInt(int* iValue) { if (m_eHttpMethod == XmlRpcProcessor::hmGet) @@ -819,10 +836,10 @@ bool XmlCommand::NextParamAsInt(int* iValue) { int iLen = 0; int iTagLen = 4; //strlen(""); - char* szParam = (char*)WebUtil::XmlFindTag(m_szRequestPtr, "i4", &iLen); + char* szParam = XmlNextValue(m_szRequestPtr, "i4", &iLen); if (!szParam) { - szParam = (char*)WebUtil::XmlFindTag(m_szRequestPtr, "int", &iLen); + szParam = XmlNextValue(m_szRequestPtr, "int", &iLen); iTagLen = 5; //strlen(""); } if (!szParam || !strchr("-+0123456789", *szParam)) @@ -893,7 +910,7 @@ bool XmlCommand::NextParamAsBool(bool* bValue) else { int iLen = 0; - char* szParam = (char*)WebUtil::XmlFindTag(m_szRequestPtr, "boolean", &iLen); + char* szParam = XmlNextValue(m_szRequestPtr, "boolean", &iLen); if (!szParam) { return false; @@ -946,7 +963,7 @@ bool XmlCommand::NextParamAsStr(char** szValue) else { int iLen = 0; - char* szParam = (char*)WebUtil::XmlFindTag(m_szRequestPtr, "string", &iLen); + char* szParam = XmlNextValue(m_szRequestPtr, "string", &iLen); if (!szParam) { return false; @@ -2125,9 +2142,10 @@ void EditQueueXmlCommand::Execute() BuildBoolResponse(bOK); } -// bool append(string NZBFilename, string Category, int Priority, bool AddToTop, string Content, bool AddPaused, string DupeKey, int DupeScore, string DupeMode) -// For backward compatibility with 0.8 parameter "Priority" is optional -// Parameters starting from "AddPaused" are optional (added in v12) +// v13 (new param order and new result type): +// int append(string NZBFilename, string NZBContent, string Category, int Priority, bool AddToTop, bool AddPaused, string DupeKey, int DupeScore, string DupeMode) +// v12 (backward compatible, some params are optional): +// bool append(string NZBFilename, string Category, int Priority, bool AddToTop, string Content, bool AddPaused, string DupeKey, int DupeScore, string DupeMode) void DownloadXmlCommand::Execute() { if (!CheckSafeMethod()) @@ -2135,24 +2153,33 @@ void DownloadXmlCommand::Execute() return; } - char* szFileName; - if (!NextParamAsStr(&szFileName)) + bool bV13 = true; + + char* szNZBFilename; + if (!NextParamAsStr(&szNZBFilename)) { - BuildErrorResponse(2, "Invalid parameter (FileName)"); + BuildErrorResponse(2, "Invalid parameter (NZBFileName)"); + return; + } + + char* szNZBContent; + if (!NextParamAsStr(&szNZBContent)) + { + BuildErrorResponse(2, "Invalid parameter (NZBContent)"); return; } char* szCategory; if (!NextParamAsStr(&szCategory)) { - BuildErrorResponse(2, "Invalid parameter (Category)"); - return; + bV13 = false; + szCategory = szNZBContent; } - DecodeStr(szFileName); + DecodeStr(szNZBFilename); DecodeStr(szCategory); - debug("FileName=%s", szFileName); + debug("FileName=%s", szNZBFilename); // For backward compatibility with 0.8 parameter "Priority" is optional (error checking omitted) int iPriority = 0; @@ -2165,12 +2192,12 @@ void DownloadXmlCommand::Execute() return; } - char* szFileContent; - if (!NextParamAsStr(&szFileContent)) + if (!bV13 && !NextParamAsStr(&szNZBContent)) { BuildErrorResponse(2, "Invalid parameter (FileContent)"); return; } + DecodeStr(szNZBContent); bool bAddPaused = false; char* szDupeKey = NULL; @@ -2183,6 +2210,7 @@ void DownloadXmlCommand::Execute() BuildErrorResponse(2, "Invalid parameter (DupeKey)"); return; } + DecodeStr(szDupeKey); if (!NextParamAsInt(&iDupeScore)) { BuildErrorResponse(2, "Invalid parameter (DupeScore)"); @@ -2198,22 +2226,66 @@ void DownloadXmlCommand::Execute() eDupeMode = !strcasecmp(szDupeMode, "all") ? dmAll : !strcasecmp(szDupeMode, "force") ? dmForce : dmScore; } - - if (IsJson()) + else if (bV13) { - // JSON-string may contain '/'-character used in Base64, which must be escaped in JSON - WebUtil::JsonDecode(szFileContent); + BuildErrorResponse(2, "Invalid parameter (AddPaused)"); + return; } - int iLen = WebUtil::DecodeBase64(szFileContent, 0, szFileContent); - szFileContent[iLen] = '\0'; - //debug("FileContent=%s", szFileContent); + if (!strncasecmp(szNZBContent, "http://", 6) || !strncasecmp(szNZBContent, "https://", 7)) + { + // add url + NZBInfo* pNZBInfo = new NZBInfo(); + pNZBInfo->SetKind(NZBInfo::nkUrl); + pNZBInfo->SetURL(szNZBContent); + pNZBInfo->SetFilename(szNZBFilename); + pNZBInfo->SetCategory(szCategory); + pNZBInfo->SetPriority(iPriority); + pNZBInfo->SetAddUrlPaused(bAddPaused); + pNZBInfo->SetDupeKey(szDupeKey ? szDupeKey : ""); + pNZBInfo->SetDupeScore(iDupeScore); + pNZBInfo->SetDupeMode(eDupeMode); + int iNZBID = pNZBInfo->GetID(); - bool bOK = g_pScanner->AddExternalFile(szFileName, szCategory, iPriority, - szDupeKey, iDupeScore, eDupeMode, NULL, bAddTop, bAddPaused, NULL, - NULL, szFileContent, iLen) != Scanner::asFailed; + char szNicename[1024]; + pNZBInfo->MakeNiceUrlName(szNZBContent, szNZBFilename, szNicename, sizeof(szNicename)); + info("Queue %s", szNicename); - BuildBoolResponse(bOK); + DownloadQueue* pDownloadQueue = DownloadQueue::Lock(); + pDownloadQueue->GetQueue()->Add(pNZBInfo, bAddTop); + pDownloadQueue->Save(); + DownloadQueue::Unlock(); + + if (bV13) + { + BuildIntResponse(iNZBID); + } + else + { + BuildBoolResponse(true); + } + } + else + { + // add file content + int iLen = WebUtil::DecodeBase64(szNZBContent, 0, szNZBContent); + szNZBContent[iLen] = '\0'; + //debug("FileContent=%s", szFileContent); + + int iNZBID = 0; + bool bOK = g_pScanner->AddExternalFile(szNZBFilename, szCategory, iPriority, + szDupeKey, iDupeScore, eDupeMode, NULL, bAddTop, bAddPaused, NULL, + NULL, szNZBContent, iLen, &iNZBID) != Scanner::asFailed; + + if (bV13) + { + BuildIntResponse(bOK ? iNZBID : 0); + } + else + { + BuildBoolResponse(bOK); + } + } } // deprecated @@ -2576,110 +2648,6 @@ const char* HistoryXmlCommand::DetectStatus(HistoryInfo* pHistoryInfo) return szStatus; } -// bool appendurl(string NZBFilename, string Category, int Priority, bool AddToTop, string URL, bool AddPaused, string DupeKey, int DupeScore, string DupeMode) -// Parameters starting from "AddPaused" are optional (added in v12) -void DownloadUrlXmlCommand::Execute() -{ - if (!CheckSafeMethod()) - { - return; - } - - char* szNZBFileName; - if (!NextParamAsStr(&szNZBFileName)) - { - BuildErrorResponse(2, "Invalid parameter (NZBFilename)"); - return; - } - - char* szCategory; - if (!NextParamAsStr(&szCategory)) - { - BuildErrorResponse(2, "Invalid parameter (Category)"); - return; - } - - int iPriority = 0; - if (!NextParamAsInt(&iPriority)) - { - BuildErrorResponse(2, "Invalid parameter (Priority)"); - return; - } - - bool bAddTop; - if (!NextParamAsBool(&bAddTop)) - { - BuildErrorResponse(2, "Invalid parameter (AddTop)"); - return; - } - - char* szURL; - if (!NextParamAsStr(&szURL)) - { - BuildErrorResponse(2, "Invalid parameter (URL)"); - return; - } - - bool bAddPaused = false; - char* szDupeKey = NULL; - int iDupeScore = 0; - EDupeMode eDupeMode = dmScore; - if (NextParamAsBool(&bAddPaused)) - { - if (!NextParamAsStr(&szDupeKey)) - { - BuildErrorResponse(2, "Invalid parameter (DupeKey)"); - return; - } - if (!NextParamAsInt(&iDupeScore)) - { - BuildErrorResponse(2, "Invalid parameter (DupeScore)"); - return; - } - char* szDupeMode = NULL; - if (!NextParamAsStr(&szDupeMode) || - (strcasecmp(szDupeMode, "score") && strcasecmp(szDupeMode, "all") && strcasecmp(szDupeMode, "force"))) - { - BuildErrorResponse(2, "Invalid parameter (DupeMode)"); - return; - } - eDupeMode = !strcasecmp(szDupeMode, "all") ? dmAll : - !strcasecmp(szDupeMode, "force") ? dmForce : dmScore; - } - - DecodeStr(szNZBFileName); - DecodeStr(szCategory); - DecodeStr(szURL); - if (szDupeKey) - { - DecodeStr(szDupeKey); - } - - debug("URL=%s", szURL); - - NZBInfo* pNZBInfo = new NZBInfo(); - pNZBInfo->SetKind(NZBInfo::nkUrl); - pNZBInfo->SetURL(szURL); - pNZBInfo->SetFilename(szNZBFileName); - pNZBInfo->SetCategory(szCategory); - pNZBInfo->SetPriority(iPriority); - pNZBInfo->SetAddUrlPaused(bAddPaused); - pNZBInfo->SetDupeKey(szDupeKey ? szDupeKey : ""); - pNZBInfo->SetDupeScore(iDupeScore); - pNZBInfo->SetDupeMode(eDupeMode); - - char szNicename[1024]; - pNZBInfo->MakeNiceUrlName(szURL, szNZBFileName, szNicename, sizeof(szNicename)); - info("Queue %s", szNicename); - - DownloadQueue* pDownloadQueue = DownloadQueue::Lock(); - pDownloadQueue->GetQueue()->Add(pNZBInfo, bAddTop); - pDownloadQueue->Save(); - DownloadQueue::Unlock(); - - BuildBoolResponse(true); -} - // Deprecated in v13 void UrlQueueXmlCommand::Execute() { diff --git a/daemon/remote/XmlRpc.h b/daemon/remote/XmlRpc.h index 7f91fcca..7f5fc230 100644 --- a/daemon/remote/XmlRpc.h +++ b/daemon/remote/XmlRpc.h @@ -1,7 +1,7 @@ /* * This file is part of nzbget * - * Copyright (C) 2007-2013 Andrey Prygunkov + * Copyright (C) 2007-2014 Andrey Prygunkov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -86,12 +86,14 @@ protected: void BuildErrorResponse(int iErrCode, const char* szErrText, ...); void BuildBoolResponse(bool bOK); + void BuildIntResponse(int iValue); void AppendResponse(const char* szPart); bool IsJson(); bool CheckSafeMethod(); bool NextParamAsInt(int* iValue); bool NextParamAsBool(bool* bValue); bool NextParamAsStr(char** szValueBuf); + char* XmlNextValue(char* szXml, const char* szTag, int* pValueLength); const char* BoolToStr(bool bValue); char* EncodeStr(const char* szStr); void DecodeStr(char* szStr); diff --git a/webui/feed.js b/webui/feed.js index 26e496af..7ddabc4e 100644 --- a/webui/feed.js +++ b/webui/feed.js @@ -350,8 +350,8 @@ var FeedDialog = (new function($) { name += '.nzb'; } - RPC.call('appendurl', [name, fetchItems[0].AddCategory, fetchItems[0].Priority, false, - fetchItems[0].URL, false, fetchItems[0].DupeKey, fetchItems[0].DupeScore, fetchItems[0].DupeMode], + RPC.call('append', [name, fetchItems[0].URL, fetchItems[0].AddCategory, fetchItems[0].Priority, false, + false, fetchItems[0].DupeKey, fetchItems[0].DupeScore, fetchItems[0].DupeMode], function() { fetchItems.shift(); diff --git a/webui/upload.js b/webui/upload.js index 36d8944d..bf7bb018 100644 --- a/webui/upload.js +++ b/webui/upload.js @@ -335,7 +335,7 @@ var Upload = (new function($) var filename = file.name.replace(/\.queued$/g, ''); var addPaused = $('#AddDialog_Paused').is(':checked'); var dupeMode = $('#AddDialog_DupeForce').is(':checked') ? "FORCE" : "SCORE"; - RPC.call('append', [filename, category, priority, false, base64str, addPaused, '', 0, dupeMode], fileCompleted, fileFailure); + RPC.call('append', [filename, base64str, category, priority, false, addPaused, '', 0, dupeMode], fileCompleted, fileFailure); }; if (reader.readAsBinaryString) @@ -379,7 +379,7 @@ var Upload = (new function($) var addPaused = $('#AddDialog_Paused').is(':checked'); var dupeMode = $('#AddDialog_DupeForce').is(':checked') ? "FORCE" : "SCORE"; - RPC.call('appendurl', ['', category, priority, false, url, addPaused, '', 0, dupeMode], urlCompleted, urlFailure); + RPC.call('append', ['', url, category, priority, false, addPaused, '', 0, dupeMode], urlCompleted, urlFailure); } function urlCompleted(result)