diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cd783966..60732fe75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,7 @@ set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") find_package(OpenSSL REQUIRED) find_package(ZLIB REQUIRED) +find_package(LibXml2 REQUIRED) if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Weverything") @@ -49,8 +50,6 @@ include_directories(${CMAKE_BINARY_DIR}) add_subdirectory(lib) if (NOT WIN32) - find_package(LibXml2 REQUIRED) - include_directories(${LIBXML2_INCLUDE_DIR}) execute_process(COMMAND chmod +x ${CMAKE_SOURCE_DIR}/code_revision.sh) execute_process(COMMAND ${CMAKE_SOURCE_DIR}/code_revision.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) execute_process(COMMAND mv ${CMAKE_SOURCE_DIR}/code_revision.cpp ${CMAKE_BINARY_DIR}) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f6e8d6c7..8644f451e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ Main documentation is available on the NZBGet.com website - [https://nzbget.com/ NZBGet natively supports for multiple platforms and build options, so each platform has their own development documenation, including: -- [General documentation, including Posix](https://github.com/nzbgetcom/nzbget/blob/develop/README) +- [General documentation, including Posix](https://github.com/nzbgetcom/nzbget/blob/develop/INSTALLATION.md) - [Windows](https://github.com/nzbgetcom/nzbget/blob/develop/windows/README-WINDOWS.txt) - [Docker](https://github.com/nzbgetcom/nzbget/blob/develop/docker/README.md) diff --git a/README b/INSTALLATION.md similarity index 87% rename from README rename to INSTALLATION.md index 992a1374b..a08d0dab2 100644 --- a/README +++ b/INSTALLATION.md @@ -1,6 +1,4 @@ -===================================== - NZBGet ReadMe -===================================== +# NZBGet installation This is a short documentation. For more information please visit NZBGet home page at @@ -19,9 +17,8 @@ Contents 9. Copyright 10. Contact -===================================== -1. About NZBGet -===================================== + +## 1. About NZBGet NZBGet is a binary newsgrabber, which downloads files from usenet based on information given in nzb-files. NZBGet can be used in @@ -40,9 +37,7 @@ Standalone-tool, server and client are all contained in only one executable file "nzbget". The mode in which the program works depends on command-line parameters passed to the program. -===================================== -2. Supported OS -===================================== +## 2. Supported OS NZBGet is written in C++ and works on Windows, OS X, Linux and most POSIX-conform OS'es. @@ -58,9 +53,7 @@ the program yourself. If you have downloaded binaries you can just jump to section "Configuration". -===================================== -3. Prerequisites on POSIX -===================================== +## 3. Prerequisites on POSIX NZBGet is developed on a linux-system, but it runs on other POSIX platforms. @@ -68,29 +61,30 @@ POSIX platforms. NZBGet absolutely needs the following libraries: - libstdc++ (usually part of compiler) - - libxml2 (https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home) + - [libxml2](https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home) And the following libraries are optional: - for curses-output-mode (enabled by default): - libcurses (usually part of commercial systems) or (better) - - libncurses (https://invisible-island.net/ncurses) + - [libncurses](https://invisible-island.net/ncurses) - for encrypted connections (TLS/SSL): - - OpenSSL (https://www.openssl.org) + - [OpenSSL](https://www.openssl.org) + or - - GnuTLS (https://gnutls.org) + - [GnuTLS](https://gnutls.org) - for gzip support in web-server and web-client (enabled by default): - - zlib (https://www.zlib.net/) + - [zlib](https://www.zlib.net/) - for configuration: - - autotools (https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) - - autoconf (https://www.gnu.org/software/autoconf/) + - [autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) + - [autoconf](https://www.gnu.org/software/autoconf/) - for managing package dependencies: - - pkg-config (https://www.freedesktop.org/wiki/Software/pkg-config/) + - [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) All these libraries are included in modern POSIX distributions and should be available as installable packages. Please note that you also @@ -98,9 +92,7 @@ need the developer packages for these libraries too, they package names have often suffix "dev" or "devel". On other systems you may need to download the libraries at the given URLs and compile them (see hints below). -===================================== -4. Installation on POSIX -===================================== +## 4. Installation on POSIX Installation from the source distribution archive (nzbget-VERSION.tar.gz): @@ -140,8 +132,8 @@ Installation from the source distribution archive (nzbget-VERSION.tar.gz): (you can skip this step if you intend to store configuration files in a non-standard location) -Configure-options ------------------ +### Configure-options +--------------------- You may run configure with additional arguments: --disable-curses - to make without curses-support. Use this option @@ -162,8 +154,8 @@ You may run configure with additional arguments: --enable-debug - to build in debug-mode, if you want to see and log debug-messages. -Optional package: par-check ---------------------------- +### Optional package: par-check +------------------------------- NZBGet can check and repair downloaded files for you. For this purpose it uses library par2. @@ -175,8 +167,8 @@ can be disabled using configure option "--disable-parcheck": ./configure --disable-parcheck -Optional package: curses -------------------------- +### Optional package: curses +---------------------------- For curses-outputmode you need ncurses or curses on your system. If you do not have one of them you can download and compile ncurses yourself. Following configure-parameters may be useful: @@ -189,7 +181,7 @@ make the program without support for curses using option "--disable-curses": ./configure --disable-curses -Optional package: TLS +### Optional package: TLS ------------------------- To enable encrypted server connections (TLS/SSL) you need to build the program with TLS/SSL support. NZBGet can use two libraries: OpenSSL or GnuTLS. @@ -212,25 +204,25 @@ TLS/SSL support using option "--disable-tls": ./configure --disable-tls -===================================== -5. Compiling on Windows -===================================== +## 5. Compiling on Windows NZBGet is developed using MS Visual Studio 2015 (Community Edition). The project file is provided. To compile the program with TLS/SSL support you need either OpenSSL or GnuTLS: - - OpenSSL (https://www.openssl.org) - or - - GnuTLS (https://gnutls.org/) + - [OpenSSL](https://www.openssl.org) + + or + - [GnuTLS](https://gnutls.org/) Also required are: - - Regex (https://gnuwin32.sourceforge.net/packages/regex.htm) - - Zlib (https://gnuwin32.sourceforge.net/packages/zlib.htm) + - [Regex](https://regexlib.com/) + - [Zlib](https://gnuwin32.sourceforge.net/packages/zlib.htm) + - [libxml2](https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home) -===================================== -6. Configuration -===================================== +We recommend using [vcpkg](https://vcpkg.io/) to install dependencies. + +## 6. Configuration NZBGet needs a configuration file. @@ -270,9 +262,7 @@ In special cases you can run program without configuration file using switch "-n". You need to use switch "-o" to pass required configuration options via command-line. -===================================== -7. Usage -===================================== +## 7. Usage NZBGet can be used in either standalone mode which downloads a single file or as a server which is able to queue up numerous download requests. @@ -283,13 +273,13 @@ in "nzbget-shell.bat". Start this script from Windows Explorer and you will be running a command shell with PATH adjusted to find NZBGet executable. Then you can type all commands without full path to nzbget.exe. -Standalone mode: ----------------- +### Standalone mode: +-------------------- nzbget -Server mode: ------------- +### Server mode: +---------------- First start the nzbget-server: @@ -384,8 +374,8 @@ or: nzbget -o createlog=no -C -Running client & server on seperate machines: ---------------------------------------------- +### Running client & server on seperate machines: +------------------------------------------------- Since nzbget communicates via TCP/IP it's possible to have a server running on one computer and adding downloads via a client on another computer. @@ -394,8 +384,8 @@ Do this by setting the "ControlIP" option in the nzbget.conf file to point to th IP of the server (default is localhost which means client and server runs on same computer) -Security warning ----------------- +### Security warning +-------------------- NZBGet communicates via unsecured socket connections. This makes it vulnerable. Although server checks the password passed by client, this password is still @@ -406,8 +396,8 @@ If you need to control server from WAN it is better to connect to server's terminal via SSH (POSIX) or remote desktop (Windows) and then run nzbget-client-commands in this terminal. -Post processing scripts ------------------------ +### Post processing scripts +--------------------------- After the download of nzb-file is completed nzbget can call post-processing scripts, defined in configuration file. @@ -420,8 +410,8 @@ To use the scripts copy them into your local directory and set options For information on writing your own post-processing scripts please visit NZBGet web site. -Web-interface -------------- +### Web-interface +----------------- NZBGet has a built-in web-server providing the access to the program functions via web-interface. @@ -450,9 +440,7 @@ Please note, that in this case the password is saved in a bookmark or in browser history in plain text and is easy to find by persons having access to your computer. -===================================== -8. Authors -===================================== +## 8. Authors NZBGet is developed and maintained by Andrey Prygunkov (hugbug@users.sourceforge.net). @@ -493,9 +481,7 @@ Boost: Boost organization and wider Boost community -===================================== -9. Copyright -===================================== +## 9. Copyright 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 @@ -506,9 +492,7 @@ The complete content of license is provided in file COPYING. Additional exemption: compiling, linking, and/or using OpenSSL is allowed. -===================================== -10. Contact -===================================== +## 10. Contact If you encounter any problem, feel free to contact us https://nzbget.com/contact/ diff --git a/Makefile.am b/Makefile.am index 7d310435a..4b7419075 100644 --- a/Makefile.am +++ b/Makefile.am @@ -320,7 +320,7 @@ linux_FILES = \ linux/build-toolchain-freebsd doc_FILES = \ - README \ + INSTALLATION.md \ ChangeLog \ COPYING diff --git a/daemon/feed/FeedFile.cpp b/daemon/feed/FeedFile.cpp index 18306bd65..a908ad31f 100644 --- a/daemon/feed/FeedFile.cpp +++ b/daemon/feed/FeedFile.cpp @@ -31,11 +31,8 @@ FeedFile::FeedFile(const char* fileName, const char* infoName) : debug("Creating FeedFile"); m_feedItems = std::make_unique(); - -#ifndef WIN32 m_feedItemInfo = nullptr; m_tagContent.Clear(); -#endif } void FeedFile::LogDebugInfo() @@ -75,295 +72,9 @@ void FeedFile::ParseSubject(FeedItemInfo& feedItemInfo) feedItemInfo.SetFilename(feedItemInfo.GetTitle()); } -#ifdef WIN32 -bool FeedFile::Parse() -{ - CoInitialize(nullptr); - - HRESULT hr; - - MSXML::IXMLDOMDocumentPtr doc; - hr = doc.CreateInstance(MSXML::CLSID_DOMDocument); - if (FAILED(hr)) - { - return false; - } - - // Load the XML document file... - doc->put_resolveExternals(VARIANT_FALSE); - doc->put_validateOnParse(VARIANT_FALSE); - doc->put_async(VARIANT_FALSE); - - _variant_t vFilename(*WString(m_fileName)); - - // 1. first trying to load via filename without URL-encoding (certain charaters doesn't work when encoded) - VARIANT_BOOL success = doc->load(vFilename); - if (success == VARIANT_FALSE) - { - // 2. now trying filename encoded as URL - char url[2048]; - EncodeUrl(m_fileName, url, 2048); - debug("url=\"%s\"", url); - _variant_t vUrl(url); - - success = doc->load(vUrl); - } - - if (success == VARIANT_FALSE) - { - _bstr_t r(doc->GetparseError()->reason); - const char* errMsg = r; - error("Error parsing rss feed %s: %s", *m_infoName, errMsg); - return false; - } - - bool ok = ParseFeed(doc); - - return ok; -} - -void FeedFile::EncodeUrl(const char* filename, char* url, int bufLen) -{ - WString widefilename(filename); - - char* end = url + bufLen; - for (wchar_t* p = widefilename; *p && url < end - 3; p++) - { - wchar_t ch = *p; - if (('0' <= ch && ch <= '9') || - ('a' <= ch && ch <= 'z') || - ('A' <= ch && ch <= 'Z') || - ch == '-' || ch == '.' || ch == '_' || ch == '~') - { - *url++ = (char)ch; - } - else - { - *url++ = '%'; - uint32 a = (uint32)ch >> 4; - *url++ = a > 9 ? a - 10 + 'A' : a + '0'; - a = ch & 0xF; - *url++ = a > 9 ? a - 10 + 'A' : a + '0'; - } - } - *url = '\0'; -} - -bool FeedFile::ParseFeed(IUnknown* nzb) -{ - MSXML::IXMLDOMDocumentPtr doc = nzb; - MSXML::IXMLDOMNodePtr root = doc->documentElement; - - MSXML::IXMLDOMNodeListPtr itemList = root->selectNodes("/rss/channel/item"); - for (int i = 0; i < itemList->Getlength(); i++) - { - MSXML::IXMLDOMNodePtr node = itemList->Getitem(i); - - m_feedItems->emplace_back(); - FeedItemInfo& feedItemInfo = m_feedItems->back(); - - MSXML::IXMLDOMNodePtr tag; - MSXML::IXMLDOMNodePtr attr; - - // Debian 6 - tag = node->selectSingleNode("title"); - if (!tag) - { - // bad rss feed - return false; - } - _bstr_t title(tag->Gettext()); - feedItemInfo.SetTitle(title); - ParseSubject(feedItemInfo); - - // Wed, 26 Jun 2013 00:02:54 -0600 - tag = node->selectSingleNode("pubDate"); - if (tag) - { - _bstr_t time(tag->Gettext()); - time_t unixtime = WebUtil::ParseRfc822DateTime(time); - if (unixtime > 0) - { - feedItemInfo.SetTime(unixtime); - } - } - - // Movies > HD - tag = node->selectSingleNode("category"); - if (tag) - { - _bstr_t category(tag->Gettext()); - feedItemInfo.SetCategory(category); - } - - // long text - tag = node->selectSingleNode("description"); - if (tag) - { - _bstr_t bdescription(tag->Gettext()); - // cleanup CDATA - CString description = (const char*)bdescription; - WebUtil::XmlStripTags(description); - WebUtil::XmlDecode(description); - WebUtil::XmlRemoveEntities(description); - feedItemInfo.SetDescription(description); - } - - // - tag = node->selectSingleNode("enclosure"); - if (tag) - { - attr = tag->Getattributes()->getNamedItem("url"); - if (attr) - { - _bstr_t url(attr->Gettext()); - feedItemInfo.SetUrl(url); - } - - attr = tag->Getattributes()->getNamedItem("length"); - if (attr) - { - _bstr_t bsize(attr->Gettext()); - int64 size = atoll(bsize); - feedItemInfo.SetSize(size); - } - } - - if (!feedItemInfo.GetUrl()) - { - // https://nzb.org/fetch/334534ce/4364564564 - tag = node->selectSingleNode("link"); - if (!tag) - { - // bad rss feed - return false; - } - _bstr_t link(tag->Gettext()); - feedItemInfo.SetUrl(link); - } - - - // newznab special - - // - if (feedItemInfo.GetSize() == 0) - { - tag = node->selectSingleNode("newznab:attr[@name='size'] | nZEDb:attr[@name='size']"); - if (tag) - { - attr = tag->Getattributes()->getNamedItem("value"); - if (attr) - { - _bstr_t bsize(attr->Gettext()); - int64 size = atoll(bsize); - feedItemInfo.SetSize(size); - } - } - } - - // - tag = node->selectSingleNode("newznab:attr[@name='imdb'] | nZEDb:attr[@name='imdb']"); - if (tag) - { - attr = tag->Getattributes()->getNamedItem("value"); - if (attr) - { - _bstr_t bval(attr->Gettext()); - int val = atoi(bval); - feedItemInfo.SetImdbId(val); - } - } - - // - tag = node->selectSingleNode("newznab:attr[@name='rageid'] | nZEDb:attr[@name='rageid']"); - if (tag) - { - attr = tag->Getattributes()->getNamedItem("value"); - if (attr) - { - _bstr_t bval(attr->Gettext()); - int val = atoi(bval); - feedItemInfo.SetRageId(val); - } - } - - // - tag = node->selectSingleNode("newznab:attr[@name='tvdbid'] | nZEDb:attr[@name='tvdbid']"); - if (tag) - { - attr = tag->Getattributes()->getNamedItem("value"); - if (attr) - { - _bstr_t bval(attr->Gettext()); - int val = atoi(bval); - feedItemInfo.SetTvdbId(val); - } - } - - // - tag = node->selectSingleNode("newznab:attr[@name='tvmazeid'] | nZEDb:attr[@name='tvmazeid']"); - if (tag) - { - attr = tag->Getattributes()->getNamedItem("value"); - if (attr) - { - _bstr_t bval(attr->Gettext()); - int val = atoi(bval); - feedItemInfo.SetTvmazeId(val); - } - } - - // - // - tag = node->selectSingleNode("newznab:attr[@name='episode'] | nZEDb:attr[@name='episode']"); - if (tag) - { - attr = tag->Getattributes()->getNamedItem("value"); - if (attr) - { - _bstr_t val(attr->Gettext()); - feedItemInfo.SetEpisode(val); - } - } - - // - // - tag = node->selectSingleNode("newznab:attr[@name='season'] | nZEDb:attr[@name='season']"); - if (tag) - { - attr = tag->Getattributes()->getNamedItem("value"); - if (attr) - { - _bstr_t val(attr->Gettext()); - feedItemInfo.SetSeason(val); - } - } - - MSXML::IXMLDOMNodeListPtr itemList = node->selectNodes("newznab:attr | nZEDb:attr"); - for (int i = 0; i < itemList->Getlength(); i++) - { - MSXML::IXMLDOMNodePtr node = itemList->Getitem(i); - MSXML::IXMLDOMNodePtr name = node->Getattributes()->getNamedItem("name"); - MSXML::IXMLDOMNodePtr value = node->Getattributes()->getNamedItem("value"); - if (name && value) - { - _bstr_t bname(name->Gettext()); - _bstr_t bval(value->Gettext()); - feedItemInfo.GetAttributes()->emplace_back(bname, bval); - } - } - } - return true; -} - -#else bool FeedFile::Parse() { -#ifdef DISABLE_LIBXML2 - error("Could not parse rss feed, program was compiled without libxml2 support"); - return false; -#else xmlSAXHandler SAX_handler = {0}; SAX_handler.startElement = reinterpret_cast(SAX_StartElement); SAX_handler.endElement = reinterpret_cast(SAX_EndElement); @@ -382,7 +93,6 @@ bool FeedFile::Parse() } return true; -#endif } void FeedFile::Parse_StartElement(const char *name, const char **atts) @@ -571,11 +281,8 @@ void FeedFile::SAX_characters(FeedFile* file, const char * xmlstr, int len) void* FeedFile::SAX_getEntity(FeedFile* file, const char * name) { -#ifdef DISABLE_LIBXML2 - void* e = nullptr; -#else xmlEntityPtr e = xmlGetPredefinedEntity((xmlChar* )name); -#endif + if (!e) { warn("entity not found"); @@ -604,4 +311,3 @@ void FeedFile::SAX_error(FeedFile* file, const char *msg, ...) for (char* pend = errMsg + strlen(errMsg) - 1; pend >= errMsg && (*pend == '\n' || *pend == '\r' || *pend == ' '); pend--) *pend = '\0'; error("Error parsing rss feed %s: %s", *file->m_infoName, errMsg); } -#endif diff --git a/daemon/feed/FeedFile.h b/daemon/feed/FeedFile.h index fa7e3eeff..2d9fe2f8f 100644 --- a/daemon/feed/FeedFile.h +++ b/daemon/feed/FeedFile.h @@ -39,10 +39,7 @@ class FeedFile CString m_infoName; void ParseSubject(FeedItemInfo& feedItemInfo); -#ifdef WIN32 - bool ParseFeed(IUnknown* nzb); - static void EncodeUrl(const char* filename, char* url, int bufLen); -#else + FeedItemInfo* m_feedItemInfo; StringBuilder m_tagContent; bool m_ignoreNextError; @@ -56,7 +53,6 @@ class FeedFile void Parse_EndElement(const char *name); void Parse_Content(const char *buf, int len); void ResetTagContent(); -#endif }; #endif diff --git a/daemon/main/nzbget.h b/daemon/main/nzbget.h index aecab84bc..fa036523f 100644 --- a/daemon/main/nzbget.h +++ b/daemon/main/nzbget.h @@ -178,13 +178,6 @@ using namespace MSXML; #include #include -#ifndef DISABLE_LIBXML2 -#include -#include -#include -#include -#endif - #ifdef HAVE_SYS_PRCTL_H #include #endif @@ -230,6 +223,11 @@ using namespace MSXML; #include #include +#include +#include +#include +#include + // NOTE: do not include in "nzbget.h". contains objects requiring // intialization, causing every unit in nzbget to have initialization routine. This in particular // is causing fatal problems in SIMD units which must not have static initialization because diff --git a/daemon/queue/NzbFile.cpp b/daemon/queue/NzbFile.cpp index 7ff73539d..fcdc540d8 100644 --- a/daemon/queue/NzbFile.cpp +++ b/daemon/queue/NzbFile.cpp @@ -439,172 +439,9 @@ void NzbFile::ReadPassword() } } -#ifdef WIN32 -bool NzbFile::Parse() -{ - CoInitialize(nullptr); - - HRESULT hr; - - MSXML::IXMLDOMDocumentPtr doc; - hr = doc.CreateInstance(MSXML::CLSID_DOMDocument); - if (FAILED(hr)) - { - return false; - } - - // Load the XML document file... - doc->put_resolveExternals(VARIANT_FALSE); - doc->put_validateOnParse(VARIANT_FALSE); - doc->put_async(VARIANT_FALSE); - - _variant_t vFilename(*WString(*m_fileName)); - - // 1. first trying to load via filename without URL-encoding (certain charaters doesn't work when encoded) - VARIANT_BOOL success = doc->load(vFilename); - if (success == VARIANT_FALSE) - { - // 2. now trying filename encoded as URL - char url[2048]; - EncodeUrl(m_fileName, url, 2048); - debug("url=\"%s\"", url); - _variant_t vUrl(url); - - success = doc->load(vUrl); - } - - if (success == VARIANT_FALSE) - { - _bstr_t r(doc->GetparseError()->reason); - const char* errMsg = r; - m_nzbInfo->AddMessage(Message::mkError, BString<1024>("Error parsing nzb-file %s: %s", - FileSystem::BaseFileName(m_fileName), errMsg)); - return false; - } - - if (!ParseNzb(doc)) - { - return false; - } - - if (m_nzbInfo->GetFileList()->empty()) - { - m_nzbInfo->AddMessage(Message::mkError, BString<1024>( - "Error parsing nzb-file %s: file has no content", FileSystem::BaseFileName(m_fileName))); - return false; - } - - ProcessFiles(); - - return true; -} - -void NzbFile::EncodeUrl(const char* filename, char* url, int bufLen) -{ - WString widefilename(filename); - - char* end = url + bufLen; - for (wchar_t* p = widefilename; *p && url < end - 3; p++) - { - wchar_t ch = *p; - if (('0' <= ch && ch <= '9') || - ('a' <= ch && ch <= 'z') || - ('A' <= ch && ch <= 'Z') || - ch == '-' || ch == '.' || ch == '_' || ch == '~') - { - *url++ = (char)ch; - } - else - { - *url++ = '%'; - uint32 a = (uint32)ch >> 4; - *url++ = a > 9 ? a - 10 + 'A' : a + '0'; - a = ch & 0xF; - *url++ = a > 9 ? a - 10 + 'A' : a + '0'; - } - } - *url = '\0'; -} - -bool NzbFile::ParseNzb(IUnknown* nzb) -{ - MSXML::IXMLDOMDocumentPtr doc = nzb; - MSXML::IXMLDOMNodePtr root = doc->documentElement; - - MSXML::IXMLDOMNodePtr node = root->selectSingleNode("/nzb/head/meta[@type='password']"); - if (node) - { - _bstr_t password(node->Gettext()); - m_password = password; - } - - MSXML::IXMLDOMNodeListPtr fileList = root->selectNodes("/nzb/file"); - for (int i = 0; i < fileList->Getlength(); i++) - { - node = fileList->Getitem(i); - MSXML::IXMLDOMNodePtr attribute = node->Getattributes()->getNamedItem("subject"); - if (!attribute) return false; - _bstr_t subject(attribute->Gettext()); - - std::unique_ptr fileInfo = std::make_unique(); - fileInfo->SetSubject(subject); - - attribute = node->Getattributes()->getNamedItem("date"); - if (attribute) - { - _bstr_t date(attribute->Gettext()); - fileInfo->SetTime(atoi(date)); - } - - MSXML::IXMLDOMNodeListPtr groupList = node->selectNodes("groups/group"); - for (int g = 0; g < groupList->Getlength(); g++) - { - MSXML::IXMLDOMNodePtr node = groupList->Getitem(g); - _bstr_t group = node->Gettext(); - fileInfo->GetGroups()->push_back((const char*)group); - } - - MSXML::IXMLDOMNodeListPtr segmentList = node->selectNodes("segments/segment"); - for (int g = 0; g < segmentList->Getlength(); g++) - { - MSXML::IXMLDOMNodePtr node = segmentList->Getitem(g); - _bstr_t bid = node->Gettext(); - BString<1024> id("<%s>", (const char*)bid); - - MSXML::IXMLDOMNodePtr attribute = node->Getattributes()->getNamedItem("number"); - if (!attribute) return false; - _bstr_t number(attribute->Gettext()); - - attribute = node->Getattributes()->getNamedItem("bytes"); - if (!attribute) return false; - _bstr_t bytes(attribute->Gettext()); - - int partNumber = atoi(number); - int lsize = atoi(bytes); - - if (partNumber > 0) - { - std::unique_ptr article = std::make_unique(); - article->SetPartNumber(partNumber); - article->SetMessageId(id); - article->SetSize(lsize); - AddArticle(fileInfo.get(), std::move(article)); - } - } - - AddFileInfo(std::move(fileInfo)); - } - return true; -} - -#else bool NzbFile::Parse() { -#ifdef DISABLE_LIBXML2 - error("Could not parse rss feed, program was compiled without libxml2 support"); - return false; -#else xmlSAXHandler SAX_handler = {0}; SAX_handler.startElement = reinterpret_cast(SAX_StartElement); SAX_handler.endElement = reinterpret_cast(SAX_EndElement); @@ -633,7 +470,6 @@ bool NzbFile::Parse() ProcessFiles(); return true; -#endif } void NzbFile::Parse_StartElement(const char *name, const char **atts) @@ -816,11 +652,8 @@ void NzbFile::SAX_characters(NzbFile* file, const char * xmlstr, int len) void* NzbFile::SAX_getEntity(NzbFile* file, const char * name) { -#ifdef DISABLE_LIBXML2 - void* e = nullptr; -#else xmlEntityPtr e = xmlGetPredefinedEntity((xmlChar* )name); -#endif + if (!e) { file->m_nzbInfo->AddMessage(Message::mkWarning, "entity not found"); @@ -850,4 +683,3 @@ void NzbFile::SAX_error(NzbFile* file, const char *msg, ...) file->m_nzbInfo->AddMessage(Message::mkError, BString<1024>("Error parsing nzb-file: %s", errMsg)); } -#endif diff --git a/daemon/queue/NzbFile.h b/daemon/queue/NzbFile.h index 62ba59f4a..fe592f8df 100644 --- a/daemon/queue/NzbFile.h +++ b/daemon/queue/NzbFile.h @@ -49,10 +49,7 @@ class NzbFile void CalcHashes(); bool HasDuplicateFilenames(); void ReadPassword(); -#ifdef WIN32 - bool ParseNzb(IUnknown* nzb); - static void EncodeUrl(const char* filename, char* url, int bufLen); -#else + std::unique_ptr m_fileInfo; ArticleInfo* m_article = nullptr; StringBuilder m_tagContent; @@ -67,7 +64,6 @@ class NzbFile void Parse_StartElement(const char *name, const char **atts); void Parse_EndElement(const char *name); void Parse_Content(const char *buf, int len); -#endif }; #endif diff --git a/nzbget.vcxproj b/nzbget.vcxproj index b692fb726..7e5336e1c 100755 --- a/nzbget.vcxproj +++ b/nzbget.vcxproj @@ -84,7 +84,7 @@ Disabled - ..\bin\Debug32;.\daemon\connect;.\daemon\extension;.\daemon\feed;.\daemon\frontend;.\daemon\main;.\daemon\nserv;.\daemon\nntp;.\daemon\postprocess;.\daemon\queue;.\daemon\remote;.\daemon\util;.\daemon\windows;.\lib\par2;.\lib\yencode;.\windows\resources;C:\Program Files (x86)\zlib\include;C:\Program Files (x86)\OpenSSL-Win32\include;.\lib\regex;%(AdditionalIncludeDirectories) + C:\vcpkg\installed\x86-windows-static\include;..\bin\Debug32;.\daemon\connect;.\daemon\extension;.\daemon\feed;.\daemon\frontend;.\daemon\main;.\daemon\nserv;.\daemon\nntp;.\daemon\postprocess;.\daemon\queue;.\daemon\remote;.\daemon\util;.\daemon\windows;.\lib\par2;.\lib\yencode;.\windows\resources;.\lib\regex;%(AdditionalIncludeDirectories) WIN32;PACKAGE="nzbget";VERSION="22.0";_DEBUG;_CONSOLE;DEBUG;_WIN32_WINNT=0x0403;%(PreprocessorDefinitions) false EnableFastChecks @@ -96,18 +96,17 @@ true - libcrypto32MTd.lib;libssl32MTd.lib;zlibstatic32.lib;Dbghelp.lib;WS2_32.lib;ole32.lib;OleAut32.Lib;comsuppwd.lib;Advapi32.lib;gdi32.lib;shell32.lib;Winmm.lib;crypt32.lib;%(AdditionalDependencies) + libcrypto.lib;libssl.lib;zlibd.lib;libxml2.lib;lzma.lib;iconv.lib;Dbghelp.lib;WS2_32.lib;ole32.lib;OleAut32.Lib;comsuppwd.lib;Advapi32.lib;gdi32.lib;shell32.lib;Winmm.lib;crypt32.lib;%(AdditionalDependencies) true Console - MachineX86 - C:\Program Files (x86)\zlib\lib\;C:\Program Files (x86)\OpenSSL-Win32\lib\VC\static;%(AdditionalLibraryDirectories) + C:\vcpkg\installed\x86-windows-static\debug\lib;%(AdditionalLibraryDirectories) msvcrt.lib; libcmt.lib; msvcrtd.lib Disabled - ..\bin\Debug64;.\daemon\connect;.\daemon\extension;.\daemon\feed;.\daemon\frontend;.\daemon\main;.\daemon\nserv;.\daemon\nntp;.\daemon\postprocess;.\daemon\queue;.\daemon\remote;.\daemon\util;.\daemon\windows;.\lib\regex;.\lib\par2;.\lib\yencode;.\windows\resources;C:\Program Files (x86)\zlib\include;C:\Program Files\OpenSSL-Win64\include;%(AdditionalIncludeDirectories) + C:\vcpkg\installed\x64-windows-static\include;..\bin\Debug64;.\daemon\connect;.\daemon\extension;.\daemon\feed;.\daemon\frontend;.\daemon\main;.\daemon\nserv;.\daemon\nntp;.\daemon\postprocess;.\daemon\queue;.\daemon\remote;.\daemon\util;.\daemon\windows;.\lib\regex;.\lib\par2;.\lib\yencode;.\windows\resources;%(AdditionalIncludeDirectories) WIN32;PACKAGE="nzbget";VERSION="22.0";_DEBUG;_CONSOLE;DEBUG;_WIN32_WINNT=0x0403;%(PreprocessorDefinitions) false EnableFastChecks @@ -121,9 +120,8 @@ true Console - C:\Program Files (x86)\zlib\lib;C:\Program Files\OpenSSL-Win64\lib\VC\static;%(AdditionalLibraryDirectories) - MachineX64 - libcrypto64MTd.lib;libssl64MTd.lib;zlibstatic64d.lib;Dbghelp.lib;WS2_32.lib;ole32.lib;OleAut32.Lib;comsuppwd.lib;Advapi32.lib;gdi32.lib;shell32.lib;Winmm.lib;crypt32.lib;%(AdditionalDependencies) + C:\vcpkg\installed\x64-windows-static\debug\lib;%(AdditionalLibraryDirectories) + libcrypto.lib;libssl.lib;zlibd.lib;libxml2.lib;lzma.lib;iconv.lib;Dbghelp.lib;WS2_32.lib;ole32.lib;OleAut32.Lib;comsuppwd.lib;Advapi32.lib;gdi32.lib;shell32.lib;Winmm.lib;crypt32.lib;%(AdditionalDependencies) false msvcrt.lib; libcmt.lib; msvcrtd.lib -s %(AdditionalOptions) @@ -134,7 +132,7 @@ - ..\bin\Release32;.\daemon\connect;.\daemon\extension;.\daemon\feed;.\daemon\frontend;.\daemon\main;.\daemon\nserv;.\daemon\nntp;.\daemon\postprocess;.\daemon\queue;.\daemon\remote;.\daemon\util;.\daemon\windows;.\lib\par2;.\lib\yencode;.\windows\resources;C:\Program Files (x86)\zlib\include;C:\Program Files (x86)\OpenSSL-Win32\include;.\lib\regex;%(AdditionalIncludeDirectories) + C:\vcpkg\installed\x86-windows-static\include;..\bin\Release32;.\daemon\connect;.\daemon\extension;.\daemon\feed;.\daemon\frontend;.\daemon\main;.\daemon\nserv;.\daemon\nntp;.\daemon\postprocess;.\daemon\queue;.\daemon\remote;.\daemon\util;.\daemon\windows;.\lib\par2;.\lib\yencode;.\windows\resources;.\lib\regex;%(AdditionalIncludeDirectories) WIN32;PACKAGE="nzbget";VERSION="22.0";NDEBUG;_CONSOLE;_WIN32_WINNT=0x0403;%(PreprocessorDefinitions) Sync MultiThreaded @@ -156,14 +154,14 @@ true - libcrypto32MT.lib;libssl32MT.lib;zlibstatic32.lib;WS2_32.lib;ole32.lib;OleAut32.Lib;comsuppwd.lib;Advapi32.lib;gdi32.lib;shell32.lib;Winmm.lib;crypt32.lib;%(AdditionalDependencies) + libcrypto.lib;libssl.lib;zlib.lib;libxml2.lib;lzma.lib;iconv.lib;WS2_32.lib;ole32.lib;OleAut32.Lib;comsuppwd.lib;Advapi32.lib;gdi32.lib;shell32.lib;Winmm.lib;crypt32.lib;%(AdditionalDependencies) true Console true true MachineX86 UseFastLinkTimeCodeGeneration - C:\Program Files (x86)\zlib\lib\;C:\Program Files (x86)\OpenSSL-Win32\lib\VC\static;%(AdditionalLibraryDirectories) + C:\vcpkg\installed\x86-windows-static\lib;%(AdditionalLibraryDirectories) NotSet msvcrt.lib; libcmtd.lib; msvcrtd.lib @@ -173,7 +171,7 @@ - ..\bin\Release64;.\daemon\connect;.\daemon\extension;.\daemon\feed;.\daemon\frontend;.\daemon\main;.\daemon\nserv;.\daemon\nntp;.\daemon\postprocess;.\daemon\queue;.\daemon\remote;.\daemon\util;.\daemon\windows;.\lib\par2;.\lib\yencode;.\windows\resources;C:\Program Files (x86)\zlib\include;C:\Program Files\OpenSSL-Win64\include;.\lib\regex;%(AdditionalIncludeDirectories) + C:\vcpkg\installed\x64-windows-static\include;..\bin\Release64;.\daemon\connect;.\daemon\extension;.\daemon\feed;.\daemon\frontend;.\daemon\main;.\daemon\nserv;.\daemon\nntp;.\daemon\postprocess;.\daemon\queue;.\daemon\remote;.\daemon\util;.\daemon\windows;.\lib\par2;.\lib\yencode;.\windows\resources;.\lib\regex;%(AdditionalIncludeDirectories) WIN32;PACKAGE="nzbget";VERSION="22.0";NDEBUG;_CONSOLE;_WIN32_WINNT=0x0403;%(PreprocessorDefinitions) Sync MultiThreaded @@ -192,13 +190,13 @@ Fast - libcrypto64MT.lib;libssl64MT.lib;zlibstatic64.lib;WS2_32.lib;ole32.lib;OleAut32.Lib;comsuppwd.lib;Advapi32.lib;gdi32.lib;shell32.lib;Winmm.lib;crypt32.lib;%(AdditionalDependencies) + libcrypto.lib;libssl.lib;zlib.lib;libxml2.lib;lzma.lib;iconv.lib;WS2_32.lib;ole32.lib;OleAut32.Lib;comsuppwd.lib;Advapi32.lib;gdi32.lib;shell32.lib;Winmm.lib;crypt32.lib;%(AdditionalDependencies) false Console true true UseLinkTimeCodeGeneration - C:\Program Files (x86)\zlib\lib;C:\Program Files\OpenSSL-Win64\lib\VC\static;%(AdditionalLibraryDirectories) + C:\vcpkg\installed\x64-windows-static\lib;%(AdditionalLibraryDirectories) msvcrt.lib; libcmtd.lib; msvcrtd.lib diff --git a/tests/feed/CMakeLists.txt b/tests/feed/CMakeLists.txt index f9a2d8664..2620cf141 100644 --- a/tests/feed/CMakeLists.txt +++ b/tests/feed/CMakeLists.txt @@ -1,6 +1,9 @@ -add_executable(FeedFilterTest +add_executable(FeedTest FeedFilterTest.cpp + FeedFileTest.cpp + main.cpp ${CMAKE_SOURCE_DIR}/daemon/feed/FeedFilter.cpp + ${CMAKE_SOURCE_DIR}/daemon/feed/FeedFile.cpp ${CMAKE_SOURCE_DIR}/daemon/feed/FeedInfo.cpp ${CMAKE_SOURCE_DIR}/daemon/main/Options.cpp ${CMAKE_SOURCE_DIR}/daemon/util/NString.cpp @@ -12,11 +15,12 @@ add_executable(FeedFilterTest ${CMAKE_SOURCE_DIR}/daemon/nntp/NewsServer.cpp ${CMAKE_SOURCE_DIR}/lib/regex/regex.c ) -target_link_libraries(FeedFilterTest PRIVATE +target_link_libraries(FeedTest PRIVATE ZLIB::ZLIB Yencode + LibXml2::LibXml2 ) -target_include_directories(FeedFilterTest PRIVATE +target_include_directories(FeedTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/feed ${CMAKE_SOURCE_DIR}/daemon/main ${CMAKE_SOURCE_DIR}/daemon/util @@ -25,6 +29,8 @@ target_include_directories(FeedFilterTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/remote ${CMAKE_SOURCE_DIR}/lib/regex ${Boost_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} ) -add_test(NAME FeedFilterTest COMMAND $ --log_level=message) +file(COPY ../testdata/feed DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +add_test(NAME FeedTest COMMAND $ --log_level=message) diff --git a/tests/feed/FeedFileTest.cpp b/tests/feed/FeedFileTest.cpp new file mode 100644 index 000000000..1067a7e89 --- /dev/null +++ b/tests/feed/FeedFileTest.cpp @@ -0,0 +1,52 @@ +/* + * This file is part of nzbget. See . + * + * Copyright (C) 2023 Denis + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "nzbget.h" + +#include + +#include +#include "FeedFile.h" + +BOOST_AUTO_TEST_CASE(FeedFileTest) +{ + std::string path = std::filesystem::current_path().string(); + std::string testFile = path + "/feed/feed.xml"; + FeedFile file(testFile.c_str(), "feedName"); + + BOOST_CHECK(file.Parse() == true); + + std::unique_ptr items = file.DetachFeedItems(); + FeedItemInfo& feedInfo = items.get()->back(); + + BOOST_CHECK(feedInfo.GetCategory() == std::string("Movies>HD")); + BOOST_CHECK(feedInfo.GetEpisode() == std::string("1")); + BOOST_CHECK(feedInfo.GetEpisodeNum() == 1); + BOOST_CHECK(feedInfo.GetSeason() == std::string("S03")); + BOOST_CHECK(feedInfo.GetSeasonNum() == 3); + BOOST_CHECK(feedInfo.GetTvmazeId() == 33877); + BOOST_CHECK(feedInfo.GetTvdbId() == 33877); + BOOST_CHECK(feedInfo.GetRageId() == 33877); + BOOST_CHECK(feedInfo.GetImdbId() == 42054); + BOOST_CHECK(feedInfo.GetUrl() == std::string("https://indexer.com/getnzb/nzb.nzb")); + BOOST_CHECK(feedInfo.GetDescription() == std::string("Description")); + BOOST_CHECK(feedInfo.GetFilename() == std::string("Crows.And.Sparrows")); + BOOST_CHECK(feedInfo.GetSize() == 7445312955); + BOOST_CHECK(feedInfo.GetTitle() == std::string("Crows.And.Sparrows")); +} diff --git a/tests/feed/FeedFilterTest.cpp b/tests/feed/FeedFilterTest.cpp index aec448724..0fec07ba6 100644 --- a/tests/feed/FeedFilterTest.cpp +++ b/tests/feed/FeedFilterTest.cpp @@ -2,6 +2,7 @@ * This file is part of nzbget. See . * * Copyright (C) 2015-2016 Andrey Prygunkov + * Copyright (C) 2023 Denis * * 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 @@ -14,13 +15,12 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * along with this program. If not, see . */ #include "nzbget.h" -#define BOOST_TEST_MODULE "FeedFilterTest" -#include +#include #include "FeedFilter.h" #include "Log.h" diff --git a/tests/feed/main.cpp b/tests/feed/main.cpp new file mode 100644 index 000000000..14a70157b --- /dev/null +++ b/tests/feed/main.cpp @@ -0,0 +1,2 @@ +#define BOOST_TEST_MODULE "FeedTest" +#include diff --git a/tests/main/CMakeLists.txt b/tests/main/CMakeLists.txt index 7280d3a9c..c38b58b74 100644 --- a/tests/main/CMakeLists.txt +++ b/tests/main/CMakeLists.txt @@ -17,6 +17,7 @@ add_executable(MainTests target_link_libraries(MainTests PRIVATE ZLIB::ZLIB Yencode + LibXml2::LibXml2 ) target_include_directories(MainTests PRIVATE ${CMAKE_SOURCE_DIR}/daemon/main @@ -29,6 +30,7 @@ target_include_directories(MainTests PRIVATE ${CMAKE_SOURCE_DIR}/lib/regex ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} ) add_test(NAME MainTests COMMAND $ --log_level=message) diff --git a/tests/nntp/CMakeLists.txt b/tests/nntp/CMakeLists.txt index fcfc0e22a..5c06ecc5d 100644 --- a/tests/nntp/CMakeLists.txt +++ b/tests/nntp/CMakeLists.txt @@ -20,6 +20,7 @@ target_link_libraries(ServerPoolTest PRIVATE ZLIB::ZLIB Par2 Yencode + LibXml2::LibXml2 ) target_include_directories(ServerPoolTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/main @@ -33,6 +34,7 @@ target_include_directories(ServerPoolTest PRIVATE ${CMAKE_SOURCE_DIR}/lib/par2 ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} ) add_test(NAME ServerPoolTest COMMAND $ --log_level=message) diff --git a/tests/postprocess/CMakeLists.txt b/tests/postprocess/CMakeLists.txt index fa5d711c5..73e68a577 100644 --- a/tests/postprocess/CMakeLists.txt +++ b/tests/postprocess/CMakeLists.txt @@ -5,6 +5,8 @@ file(GLOB PostprocessTestsSrc ParCheckerTest.cpp ParRenamerTest.cpp RarReaderTest.cpp + RarReaderTest.cpp + RarRenamerTest.cpp ../suite/TestUtil.cpp ${CMAKE_SOURCE_DIR}/daemon/postprocess/DirectUnpack.cpp ${CMAKE_SOURCE_DIR}/daemon/postprocess/DupeMatcher.cpp @@ -12,6 +14,7 @@ file(GLOB PostprocessTestsSrc ${CMAKE_SOURCE_DIR}/daemon/postprocess/ParParser.cpp ${CMAKE_SOURCE_DIR}/daemon/postprocess/ParRenamer.cpp ${CMAKE_SOURCE_DIR}/daemon/postprocess/RarReader.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/RarRenamer.cpp ${CMAKE_SOURCE_DIR}/daemon/main/Options.cpp ${CMAKE_SOURCE_DIR}/daemon/util/NString.cpp ${CMAKE_SOURCE_DIR}/daemon/util/Util.cpp @@ -35,6 +38,7 @@ target_link_libraries(PostprocessTests PRIVATE Par2 OpenSSL::SSL OpenSSL::Crypto + LibXml2::LibXml2 ) target_include_directories(PostprocessTests PRIVATE ../suite @@ -49,6 +53,7 @@ target_include_directories(PostprocessTests PRIVATE ${CMAKE_SOURCE_DIR}/lib/yencode ${CMAKE_SOURCE_DIR}/lib/par2 ${Boost_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} ) file(COPY ../testdata/rarrenamer DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/postprocess/RarRenamerTest.cpp b/tests/postprocess/RarRenamerTest.cpp index 1cf8c1add..8df3ff589 100644 --- a/tests/postprocess/RarRenamerTest.cpp +++ b/tests/postprocess/RarRenamerTest.cpp @@ -20,7 +20,7 @@ #include "nzbget.h" -#include "catch.h" +#include #include "Options.h" #include "RarRenamer.h" @@ -39,195 +39,195 @@ RarRenamerMock::RarRenamerMock() SetDestDir(TestUtil::WorkingDir().c_str()); } -TEST_CASE("Rar-renamer: rename not needed", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameNotEeededTest) { RarRenamerMock rarRenamer; rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 0); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 0); } -TEST_CASE("Rar-renamer: rename not needed 2", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameNotEeeded2Test) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::CopyFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); - REQUIRE(FileSystem::CopyFile((TestUtil::WorkingDir() + "/testfile3oldnam.r00").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamB.r00").c_str())); + BOOST_CHECK(FileSystem::CopyFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); + BOOST_CHECK(FileSystem::CopyFile((TestUtil::WorkingDir() + "/testfile3oldnam.r00").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamB.r00").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 0); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 0); } -TEST_CASE("Rar-renamer: rename rar3", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE("Rar-renamer: rename rar3", "[Rar][RarRenamer][Slow][TestData]") { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12345").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12342").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12346").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12345").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12342").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12346").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } -TEST_CASE("Rar-renamer: rename rar5", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameRar5Test) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12344").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12344").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } -TEST_CASE("Rar-renamer: missing parts", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(MissingPartsTest) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); - REQUIRE(FileSystem::DeleteFile((TestUtil::WorkingDir() + "/testfile5.part03.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); + BOOST_CHECK(FileSystem::DeleteFile((TestUtil::WorkingDir() + "/testfile5.part03.rar").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 0); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 0); } -TEST_CASE("Rar-renamer: rename rar3 bad naming", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameRar3BadNamingTest) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3.part04.rar").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3.part04.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } -TEST_CASE("Rar-renamer: rename rar3 bad naming 2", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(Rar3BadNaming2) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3.part2.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3.part2.rar").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } -TEST_CASE("Rar-renamer: rename rar3 bad naming 3", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameRar3BadNaming3Test) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3-1.part02.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3-1.part02.rar").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } -TEST_CASE("Rar-renamer: rename rar3 bad naming 4", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameRar3BadNaming4Test) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/testfil-3.part02.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/testfil-3.part02.rar").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } -TEST_CASE("Rar-renamer: rename rar3 bad naming 5", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameRar3BadNaming5Test) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3oldnam.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamA.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3oldnam.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamA.rar").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 1); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 1); } -TEST_CASE("Rar-renamer: rename rar3 bad naming 6", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameRar3BadNaming6Test) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3oldnam.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamA.rar").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3oldnam.r00").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamB.r00").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3oldnam.r01").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamA.r01").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3oldnam.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamA.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3oldnam.r00").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamB.r00").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3oldnam.r01").c_str(), (TestUtil::WorkingDir() + "/testfile3oldnamA.r01").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } -TEST_CASE("Rar-renamer: rename two sets", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameTwoSetsTest) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12345").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12342").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12346").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12344").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12345").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12342").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12346").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12344").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 6); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 6); } -TEST_CASE("Rar-renamer: rename duplicate", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameDuplicateTest) { RarRenamerMock rarRenamer; - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12345").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12342").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12346").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part01.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3.dat.part0001.rar").c_str())); - REQUIRE(FileSystem::DeleteFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str())); - REQUIRE(FileSystem::DeleteFile((TestUtil::WorkingDir() + "/testfile5.part03.rar").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12345").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12342").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12346").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5.part01.rar").c_str(), (TestUtil::WorkingDir() + "/testfile3.dat.part0001.rar").c_str())); + BOOST_CHECK(FileSystem::DeleteFile((TestUtil::WorkingDir() + "/testfile5.part02.rar").c_str())); + BOOST_CHECK(FileSystem::DeleteFile((TestUtil::WorkingDir() + "/testfile5.part03.rar").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } #ifndef DISABLE_TLS -TEST_CASE("Rar-renamer: rename rar5 encrypted", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameRar5EncryptedTest) { RarRenamerMock rarRenamer; rarRenamer.SetPassword("123"); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5encnam.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5encnam.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5encnam.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12344").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5encnam.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5encnam.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile5encnam.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12344").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } -TEST_CASE("Rar-renamer: rename rar3 encrypted", "[Rar][RarRenamer][Slow][TestData]") +BOOST_AUTO_TEST_CASE(RenameRar3EncryptedTest) { RarRenamerMock rarRenamer; rarRenamer.SetPassword("123"); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3encnam.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3encnam.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); - REQUIRE(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3encnam.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12344").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3encnam.part01.rar").c_str(), (TestUtil::WorkingDir() + "/12348").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3encnam.part02.rar").c_str(), (TestUtil::WorkingDir() + "/12343").c_str())); + BOOST_CHECK(FileSystem::MoveFile((TestUtil::WorkingDir() + "/testfile3encnam.part03.rar").c_str(), (TestUtil::WorkingDir() + "/12344").c_str())); rarRenamer.Execute(); - REQUIRE(rarRenamer.GetRenamedCount() == 3); + BOOST_CHECK(rarRenamer.GetRenamedCount() == 3); } #endif diff --git a/tests/queue/CMakeLists.txt b/tests/queue/CMakeLists.txt index 34501656d..bb535efd5 100644 --- a/tests/queue/CMakeLists.txt +++ b/tests/queue/CMakeLists.txt @@ -16,6 +16,7 @@ add_executable(NzbFileTest target_link_libraries(NzbFileTest PRIVATE ZLIB::ZLIB Yencode + LibXml2::LibXml2 ) target_include_directories(NzbFileTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/main @@ -27,6 +28,7 @@ target_include_directories(NzbFileTest PRIVATE ${CMAKE_SOURCE_DIR}/lib/yencode ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} ) file(COPY ../testdata/nzbfile DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/testdata/feed/feed.xml b/tests/testdata/feed/feed.xml new file mode 100644 index 000000000..a03499634 --- /dev/null +++ b/tests/testdata/feed/feed.xml @@ -0,0 +1,43 @@ + + + + + DS + DS RSS Details + https://indexer.com/ + en-gb + ds@indexer.com DS + indexer, ds, slug + nZEDb + 10 + https://indexer.com/rss-info/ + + + + + Crows.And.Sparrows + https://indexer.com/details/9bdef3a6cb1a370598f9af73ba50d40df354b327 + https://indexer.com/getnzb/9bdef3a6cb1a370598f9af73ba50d40df354b327.nzb&i=60790&r=4ad82a6e8c985b3060ef8972e6224daa + https://indexer.com/details/9bdef3a6cb1a370598f9af73ba50d40df354b327#comments + Mon, 04 Dec 2023 05:48:03 +0000 + Movies > HD + Description + + + + + + + + + + + + + + + + + + + diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt index 8ffb232fb..dbc154363 100644 --- a/tests/util/CMakeLists.txt +++ b/tests/util/CMakeLists.txt @@ -17,7 +17,7 @@ add_executable(UtilTests ${UtilTestSrc}) target_link_libraries(UtilTests PRIVATE ZLIB::ZLIB Yencode - ${LIBXML2_LIBRARIES} + LibXml2::LibXml2 ) target_include_directories(UtilTests PRIVATE ${CMAKE_SOURCE_DIR}/daemon/main @@ -27,6 +27,7 @@ target_include_directories(UtilTests PRIVATE ${ZLIB_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} ) add_test(NAME UtilTests COMMAND $ --log_level=message) diff --git a/windows/build-nzbget-vs22.bat b/windows/build-nzbget-vs22.bat index e562367a3..d0ad96670 100644 --- a/windows/build-nzbget-vs22.bat +++ b/windows/build-nzbget-vs22.bat @@ -186,7 +186,7 @@ copy windows\README-WINDOWS.txt ..\distrib\NZBGet if errorlevel 1 goto BUILD_FAILED copy ChangeLog ..\distrib\NZBGet if errorlevel 1 goto BUILD_FAILED -copy README ..\distrib\NZBGet +copy INSTALLATION.md ..\distrib\NZBGet if errorlevel 1 goto BUILD_FAILED copy COPYING ..\distrib\NZBGet if errorlevel 1 goto BUILD_FAILED diff --git a/windows/build-nzbget.bat b/windows/build-nzbget.bat index 5913aa78f..ee3779994 100644 --- a/windows/build-nzbget.bat +++ b/windows/build-nzbget.bat @@ -200,7 +200,7 @@ copy windows\README-WINDOWS.txt ..\distrib\NZBGet if errorlevel 1 goto BUILD_FAILED copy ChangeLog ..\distrib\NZBGet if errorlevel 1 goto BUILD_FAILED -copy README ..\distrib\NZBGet +copy INSTALLATION.md ..\distrib\NZBGet if errorlevel 1 goto BUILD_FAILED copy COPYING ..\distrib\NZBGet if errorlevel 1 goto BUILD_FAILED