mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-04 21:29:21 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b34eb1e895 | |||
| b857acd081 | |||
| 988aca1281 | |||
| 378c7ee854 | |||
| da9606bfae | |||
| 8423803b6e | |||
| c1ce2febf0 | |||
| 5ebb7bd151 | |||
| 50f0cad0c6 | |||
| 3717649bb3 | |||
| c32b56e9d8 | |||
| de54a4c2ad | |||
| 26fdca8f4d | |||
| 00bcdaee23 | |||
| 3787dbe7f3 | |||
| 282c86597a | |||
| c41e63248a | |||
| 641626029a | |||
| 0c507c581f | |||
| af0b600b54 | |||
| c984a69fd1 | |||
| 20002ce937 | |||
| 3caa31113d | |||
| 0373d227c1 | |||
| a8be7e443a | |||
| f327523a07 |
+3
-3
@@ -1,6 +1,6 @@
|
||||
m4_pattern_allow([PKG_CHECK_EXISTS])
|
||||
|
||||
AC_INIT([rtorrent],[0.16.21],[sundell.software@gmail.com])
|
||||
AC_INIT([rtorrent],[0.16.23],[sundell.software@gmail.com])
|
||||
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_MACRO_DIRS([scripts])
|
||||
@@ -14,7 +14,7 @@ AX_CXX_COMPILE_STDCXX(20, noext, mandatory)
|
||||
|
||||
PKG_PROG_PKG_CONFIG
|
||||
|
||||
AC_DEFINE([API_VERSION], [26], [api version])
|
||||
AC_DEFINE([API_VERSION], [27], [api version])
|
||||
|
||||
RAK_CHECK_CFLAGS
|
||||
RAK_CHECK_CXXFLAGS
|
||||
@@ -49,7 +49,7 @@ fi
|
||||
|
||||
PKG_CHECK_MODULES([CPPUNIT], [cppunit],, [no_cppunit="yes"])
|
||||
PKG_CHECK_MODULES([ZLIB], [zlib])
|
||||
PKG_CHECK_MODULES([DEPENDENCIES], [libtorrent >= 0.16.21])
|
||||
PKG_CHECK_MODULES([DEPENDENCIES], [libtorrent >= 0.16.23])
|
||||
|
||||
AC_LANG_PUSH(C++)
|
||||
TORRENT_WITH_XMLRPC_C
|
||||
|
||||
@@ -431,6 +431,9 @@ p_call_target(const torrent::Object::list_type& args) {
|
||||
const std::string& peer_id = itr++->as_string();
|
||||
const std::string& command_key = itr++->as_string();
|
||||
|
||||
if (download == nullptr)
|
||||
throw torrent::input_error("invalid parameters: info-hash not found");
|
||||
|
||||
torrent::HashString hash;
|
||||
|
||||
if (peer_id.size() != 40)
|
||||
|
||||
@@ -157,7 +157,7 @@ system_method_insert_object(const torrent::Object::list_type& args, int flags) {
|
||||
torrent::Object valueList = torrent::Object::create_list();
|
||||
torrent::Object::list_type& valueListType = valueList.as_list();
|
||||
|
||||
if ((itrArgs)->is_list())
|
||||
if (itrArgs != args.end() && (itrArgs)->is_list())
|
||||
valueListType = (itrArgs)->as_list();
|
||||
|
||||
control->object_storage()->insert_str(raw_key, valueList, flags);
|
||||
|
||||
+9
-1
@@ -131,7 +131,7 @@ ipv4_range_parse(const char* address, uint32_t* address_start, uint32_t* address
|
||||
// copy everything up to '#' to address_copy and work from there
|
||||
while(address[address_start_index] != '#' && address[address_start_index] != '\r' &&
|
||||
address[address_start_index] != '\n' && address[address_start_index] != '\0' &&
|
||||
address_start_index < 4096 ) {
|
||||
address_start_index < 4095 ) {
|
||||
|
||||
address_copy[address_start_index] = address[address_start_index];
|
||||
address_start_index++;
|
||||
@@ -206,6 +206,9 @@ ipv4_range_parse(const char* address, uint32_t* address_start, uint32_t* address
|
||||
if (mask_bits == 0) {
|
||||
mask = 0;
|
||||
end_mask = ~(uint32_t)0;
|
||||
} else if (mask_bits == 32) {
|
||||
mask = ~(uint32_t)0;
|
||||
end_mask = 0;
|
||||
} else {
|
||||
mask = (~mask) << (32-mask_bits);
|
||||
end_mask = (~end_mask) >> mask_bits;
|
||||
@@ -316,6 +319,11 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) {
|
||||
ipv4_filter_parse(buffer, value);
|
||||
}
|
||||
|
||||
if (file.fail() && !file.eof()) {
|
||||
lineNumber++;
|
||||
throw torrent::input_error("Exceeded max line length.");
|
||||
}
|
||||
|
||||
} catch (torrent::input_error& e) {
|
||||
snprintf(buffer, 2048, "Error in ip filter file: %s:%u: %s", filename.c_str(), lineNumber, e.what());
|
||||
|
||||
|
||||
@@ -83,7 +83,9 @@ apply_throttle(const torrent::Object::list_type& args, bool up) {
|
||||
throw torrent::input_error("Missing throttle rate for '" + name + "'.");
|
||||
|
||||
int64_t rate;
|
||||
rpc::parse_whole_value_nothrow(arg_itr->as_string().c_str(), &rate);
|
||||
|
||||
if (!rpc::parse_whole_value_nothrow(arg_itr->as_string().c_str(), &rate))
|
||||
throw torrent::input_error("Invalid throttle rate for '" + name + "'.");
|
||||
|
||||
if (rate < 0)
|
||||
throw torrent::input_error("Throttle rate must be non-negative.");
|
||||
|
||||
@@ -132,11 +132,12 @@ DhtManager::save_dht_cache() {
|
||||
torrent::Object cache = torrent::Object::create_map();
|
||||
cache_file << *torrent::runtime::network_manager()->dht_controller()->store_cache(&cache);
|
||||
|
||||
// The data only reaches the kernel here, so this is where a full disk is seen.
|
||||
cache_file.close();
|
||||
|
||||
if (!cache_file.good())
|
||||
return;
|
||||
|
||||
cache_file.close();
|
||||
|
||||
::rename(filename_tmp.c_str(), filename.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <sys/stat.h>
|
||||
#include <torrent/utils/log.h>
|
||||
#include <torrent/utils/resume.h>
|
||||
#include <torrent/object.h>
|
||||
@@ -39,6 +40,11 @@ static constexpr const char* session_invalid_message = "Session data is invalid,
|
||||
|
||||
static std::unique_ptr<torrent::Object>
|
||||
download_factory_load_stream(const char* filename, bool* is_invalid) {
|
||||
struct stat sb;
|
||||
|
||||
if (stat(filename, &sb) != 0 || !S_ISREG(sb.st_mode))
|
||||
return std::unique_ptr<torrent::Object>();
|
||||
|
||||
std::fstream stream(filename, std::ios::in | std::ios::binary);
|
||||
|
||||
if (!stream.is_open())
|
||||
@@ -167,11 +173,19 @@ void
|
||||
DownloadFactory::receive_success() {
|
||||
bool session_invalid = false;
|
||||
|
||||
auto rtorrent_object = download_factory_load_stream((expand_path(m_uri) + ".rtorrent").c_str(), &session_invalid);
|
||||
auto libtorrent_resume_object = download_factory_load_stream((expand_path(m_uri) + ".libtorrent_resume").c_str(), &session_invalid);
|
||||
std::unique_ptr<torrent::Object> rtorrent_object;
|
||||
std::unique_ptr<torrent::Object> libtorrent_resume_object;
|
||||
|
||||
if (session_invalid)
|
||||
lt_log_print(torrent::LOG_ERROR, "%s: %s", session_invalid_message, m_uri.c_str());
|
||||
if (m_session) {
|
||||
if (m_uri.empty())
|
||||
throw torrent::input_error("Session torrent URI is empty.");
|
||||
|
||||
rtorrent_object = download_factory_load_stream((expand_path(m_uri) + ".rtorrent").c_str(), &session_invalid);
|
||||
libtorrent_resume_object = download_factory_load_stream((expand_path(m_uri) + ".libtorrent_resume").c_str(), &session_invalid);
|
||||
|
||||
if (session_invalid)
|
||||
lt_log_print(torrent::LOG_ERROR, "%s: %s", session_invalid_message, m_uri.c_str());
|
||||
}
|
||||
|
||||
uint32_t tracker_key;
|
||||
|
||||
|
||||
@@ -301,7 +301,7 @@ DownloadList::set_state_stopped(Download* download) {
|
||||
void
|
||||
DownloadList::update_paused_state(Download* download) {
|
||||
rpc::call_command("d.state_changed.set", torrent::this_thread::cached_seconds().count(), rpc::make_target(download));
|
||||
rpc::call_command("d.state_counter.set", rpc::call_command_value("d.state_counter", rpc::make_target(download)), rpc::make_target(download));
|
||||
rpc::call_command("d.state_counter.set", rpc::call_command_value("d.state_counter", rpc::make_target(download)) + 1, rpc::make_target(download));
|
||||
|
||||
// If initial seeding is complete, don't try it again when restarting.
|
||||
if (download->is_done() &&
|
||||
@@ -726,11 +726,10 @@ DownloadList::process_meta_download(Download* download) {
|
||||
return;
|
||||
}
|
||||
|
||||
torrent::Object* bencode = new torrent::Object(torrent::Object::create_map());
|
||||
auto bencode = std::make_unique<torrent::Object>(torrent::Object::create_map());
|
||||
file >> bencode->insert_key("info", torrent::Object());
|
||||
|
||||
if (file.fail()) {
|
||||
delete bencode;
|
||||
lt_log_print(torrent::LOG_TORRENT_ERROR, "Could not create download, the input is not a valid torrent.");
|
||||
return;
|
||||
}
|
||||
@@ -746,7 +745,7 @@ DownloadList::process_meta_download(Download* download) {
|
||||
|
||||
erase_ptr(download);
|
||||
|
||||
control->core()->try_create_download_from_meta_download(bencode, metafile);
|
||||
control->core()->try_create_download_from_meta_download(std::move(bencode), metafile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-3
@@ -195,14 +195,14 @@ Manager::try_create_download(const std::string& uri, int flags, const command_li
|
||||
return;
|
||||
|
||||
// Adding download.
|
||||
DownloadFactory* f = new DownloadFactory(this);
|
||||
auto f = std::make_unique<DownloadFactory>(this);
|
||||
|
||||
f->variables()["tied_to_file"] = (int64_t)(bool)(flags & create_tied);
|
||||
f->commands().insert(f->commands().end(), commands.begin(), commands.end());
|
||||
|
||||
f->set_start(flags & create_start);
|
||||
f->set_print_log(!(flags & create_quiet));
|
||||
f->slot_finished([f]() { delete f; });
|
||||
f->slot_finished([factory = f.get()]() { delete factory; });
|
||||
|
||||
if (is_data_uri(uri)) {
|
||||
// Allow the use of data URIs, primarily for JSON-RPC which
|
||||
@@ -216,10 +216,13 @@ Manager::try_create_download(const std::string& uri, int flags, const command_li
|
||||
}
|
||||
|
||||
f->commit();
|
||||
|
||||
// From here the finished slot deletes it.
|
||||
f.release();
|
||||
}
|
||||
|
||||
void
|
||||
Manager::try_create_download_from_meta_download(torrent::Object* bencode, const std::string& metafile) {
|
||||
Manager::try_create_download_from_meta_download(std::unique_ptr<torrent::Object> bencode, const std::string& metafile) {
|
||||
DownloadFactory* f = new DownloadFactory(this);
|
||||
|
||||
f->variables()["tied_to_file"] = (int64_t)true;
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public:
|
||||
// Temporary, find a better place for this.
|
||||
void try_create_download(const std::string& uri, int flags, const command_list_type& commands);
|
||||
void try_create_download_expand(const std::string& uri, int flags, command_list_type commands = command_list_type());
|
||||
void try_create_download_from_meta_download(torrent::Object* bencode, const std::string& metafile);
|
||||
void try_create_download_from_meta_download(std::unique_ptr<torrent::Object> bencode, const std::string& metafile);
|
||||
|
||||
private:
|
||||
void create_http(const std::string& uri);
|
||||
|
||||
+2
-2
@@ -216,7 +216,7 @@ View::set_not_visible(Download* download) {
|
||||
|
||||
void
|
||||
View::next_focus(unsigned int i) {
|
||||
if (empty())
|
||||
if (empty_visible())
|
||||
return;
|
||||
|
||||
// If at the boundary, roll over
|
||||
@@ -239,7 +239,7 @@ View::next_focus(unsigned int i) {
|
||||
|
||||
void
|
||||
View::prev_focus(unsigned int i) {
|
||||
if (empty())
|
||||
if (empty_visible())
|
||||
return;
|
||||
|
||||
// If at the boundary, roll over
|
||||
|
||||
@@ -25,7 +25,10 @@ WindowFileList::WindowFileList(const ui::ElementFileList* element) :
|
||||
// Convert std::string to std::wstring of given width (in screen positions),
|
||||
// taking into account that some characters may be occupying two screen positions.
|
||||
std::wstring
|
||||
wstring_width(const std::string& i_str, [[maybe_unused]] int width) {
|
||||
wstring_width(const std::string& i_str, int width) {
|
||||
if (width < 0)
|
||||
width = 0;
|
||||
|
||||
std::wstring result(width + 1, L' ');
|
||||
size_t length = std::mbstowcs(result.data(), i_str.c_str(), width);
|
||||
|
||||
|
||||
@@ -61,14 +61,20 @@ CommandScheduler::call_item(value_type item) {
|
||||
// Remove the item before calling the command if it should be
|
||||
// removed.
|
||||
|
||||
std::string key = item->key();
|
||||
|
||||
try {
|
||||
rpc::call_object(item->command());
|
||||
|
||||
} catch (torrent::input_error& e) {
|
||||
if (m_slotErrorMessage)
|
||||
m_slotErrorMessage("Scheduled command failed: " + item->key() + ": " + e.what());
|
||||
m_slotErrorMessage("Scheduled command failed: " + key + ": " + e.what());
|
||||
}
|
||||
|
||||
// The command is allowed to erase or replace this item, which deletes it.
|
||||
if (std::find(begin(), end(), item) == end())
|
||||
return;
|
||||
|
||||
// Still schedule if we caught a torrrent::input_error?
|
||||
auto next = item->next_time_scheduled();
|
||||
|
||||
|
||||
@@ -181,6 +181,11 @@ parse_command_file(const std::string& path) {
|
||||
getCount = 0;
|
||||
}
|
||||
|
||||
if (file.fail() && !file.eof()) {
|
||||
lineNumber++;
|
||||
throw torrent::input_error("Exceeded max line length.");
|
||||
}
|
||||
|
||||
} catch (torrent::input_error& e) {
|
||||
snprintf(buffer, 2048, "Error in option file: %s:%u: %s", path.c_str(), lineNumber, e.what());
|
||||
|
||||
|
||||
@@ -93,7 +93,8 @@ SCgiTask::close() {
|
||||
// The callbacks are guaranteed to be finished/canceled at this point.
|
||||
auto lock = std::lock_guard<std::mutex>(m_result_mutex);
|
||||
|
||||
m_buffer.clear();
|
||||
// clear() would keep the capacity, and the task is pooled for the lifetime of the process.
|
||||
std::vector<char>().swap(m_buffer);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ class SCgiTask : public torrent::system::Event {
|
||||
public:
|
||||
static constexpr int default_buffer_size = 8191;
|
||||
static constexpr int max_header_size = 2000;
|
||||
static constexpr int max_content_size = (2 << 23);
|
||||
static constexpr int max_content_size = (1 << 26);
|
||||
|
||||
static constexpr auto timeout_request = std::chrono::seconds(60);
|
||||
|
||||
|
||||
+7
-6
@@ -44,10 +44,9 @@ xmlrpc_list_entry_to_object(xmlrpc_env* env, xmlrpc_value* src, int index) {
|
||||
if (env->fault_occurred)
|
||||
throw xmlrpc_error_c(env);
|
||||
|
||||
torrent::Object obj = xmlrpc_to_object(env, tmp);
|
||||
xmlrpc_DECREF(tmp);
|
||||
utils::scope_guard guard([tmp]() { xmlrpc_DECREF(tmp); });
|
||||
|
||||
return obj;
|
||||
return xmlrpc_to_object(env, tmp);
|
||||
}
|
||||
|
||||
int64_t
|
||||
@@ -77,16 +76,18 @@ xmlrpc_list_entry_to_value(xmlrpc_env* env, xmlrpc_value* src, int index) {
|
||||
{
|
||||
const char* str;
|
||||
xmlrpc_read_string(env, tmp, &str);
|
||||
xmlrpc_DECREF(tmp);
|
||||
|
||||
if (env->fault_occurred)
|
||||
throw xmlrpc_error_c(env);
|
||||
|
||||
const char* end = str;
|
||||
int64_t v3 = ::strtoll(str, (char**)&end, 0);
|
||||
bool invalid = *str == '\0' || *end != '\0';
|
||||
|
||||
::free((void*)str);
|
||||
|
||||
if (*str == '\0' || *end != '\0')
|
||||
if (invalid)
|
||||
throw xmlrpc_error_c(XMLRPC_TYPE_ERROR, "Invalid index.");
|
||||
|
||||
return v3;
|
||||
@@ -211,11 +212,11 @@ xmlrpc_to_object(xmlrpc_env* env, xmlrpc_value* value, int call_type, rpc::targe
|
||||
if (env->fault_occurred)
|
||||
throw xmlrpc_error_c(env);
|
||||
|
||||
utils::scope_guard guard([tmp]() { xmlrpc_DECREF(tmp); });
|
||||
|
||||
if (target != nullptr)
|
||||
std::tie(*target, *deleter) = xmlrpc_to_target(env, tmp, call_type);
|
||||
|
||||
xmlrpc_DECREF(tmp);
|
||||
|
||||
if (env->fault_occurred)
|
||||
throw xmlrpc_error_c(env);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "rpc/tinyxml2/tinyxml2.h"
|
||||
#include "rpc/rpc_manager.h"
|
||||
#include "utils/base64.h"
|
||||
#include "utils/functional.h"
|
||||
#include "xmlrpc.h"
|
||||
|
||||
namespace rpc {
|
||||
@@ -258,6 +259,8 @@ execute_command(std::string method_name, const tinyxml2::XMLElement* params_elem
|
||||
torrent::Object params_raw = torrent::Object::create_list();
|
||||
torrent::Object::list_type& params = params_raw.as_list();
|
||||
rpc::target_type target = rpc::make_target();
|
||||
std::function<void()> deleter = []() {};
|
||||
utils::scope_guard guard([&deleter]() { deleter(); });
|
||||
|
||||
if (params_element != nullptr) {
|
||||
if (std::strncmp(params_element->Name(), "params", sizeof("params")) == 0) {
|
||||
@@ -265,8 +268,6 @@ execute_command(std::string method_name, const tinyxml2::XMLElement* params_elem
|
||||
const auto* child = params_element->FirstChildElement("param");
|
||||
|
||||
if (child != nullptr) {
|
||||
std::function<void()> deleter = []() {};
|
||||
|
||||
RpcManager::object_to_target(xml_value_to_object(child->FirstChildElement("value")), cmd_itr->second.m_flags, &target, &deleter);
|
||||
child = child->NextSiblingElement("param");
|
||||
|
||||
@@ -282,8 +283,6 @@ execute_command(std::string method_name, const tinyxml2::XMLElement* params_elem
|
||||
const auto* child = params_element->FirstChildElement("data")->FirstChildElement("value");
|
||||
|
||||
if (child != nullptr) {
|
||||
std::function<void()> deleter = []() {};
|
||||
|
||||
RpcManager::object_to_target(xml_value_to_object(child), cmd_itr->second.m_flags, &target, &deleter);
|
||||
child = child->NextSiblingElement("value");
|
||||
|
||||
|
||||
@@ -127,8 +127,12 @@ save_stream(const std::string& path, bool use_fsyncdisk, const std::stringstream
|
||||
if (!output.good())
|
||||
throw torrent::storage_error("failed to write stream to file : " + path);
|
||||
|
||||
// The data only reaches the kernel here, so this is where a full disk is seen.
|
||||
output.close();
|
||||
|
||||
if (!output.good())
|
||||
throw torrent::storage_error("failed to flush stream to file : " + path);
|
||||
|
||||
// Ensure that the new file is actually written to the disk
|
||||
int fd = ::open(path.c_str(), O_WRONLY);
|
||||
|
||||
@@ -137,13 +141,19 @@ save_stream(const std::string& path, bool use_fsyncdisk, const std::stringstream
|
||||
|
||||
if (use_fsyncdisk) {
|
||||
#ifdef __APPLE__
|
||||
::fsync(fd);
|
||||
int sync_result = ::fsync(fd);
|
||||
#else
|
||||
::fdatasync(fd);
|
||||
int sync_result = ::fdatasync(fd);
|
||||
#endif
|
||||
|
||||
if (sync_result == -1) {
|
||||
::close(fd);
|
||||
throw torrent::storage_error("failed to sync file to disk : " + path);
|
||||
}
|
||||
}
|
||||
|
||||
::close(fd);
|
||||
if (::close(fd) == -1)
|
||||
throw torrent::storage_error("failed to close file descriptor : " + path);
|
||||
}
|
||||
|
||||
} // namespace anonymous
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int parse_main_options(int argc, char** argv);
|
||||
void parse_config_file(int argc, char** argv, std::function<void (const std::string&)> parse_fn);
|
||||
|
||||
+3
-2
@@ -467,6 +467,9 @@ Root::save_input_history() {
|
||||
history_file << entry << "|" + category.at((pitr->second + i) % m_input_history_length) + "\n";
|
||||
}
|
||||
|
||||
// The data only reaches the kernel here, so this is where a full disk is seen.
|
||||
history_file.close();
|
||||
|
||||
if (!history_file.good()) {
|
||||
lt_log_print(torrent::LOG_DEBUG, "input history file corrupted during writing, discarding (path:%s)", history_filename.c_str());
|
||||
return;
|
||||
@@ -474,8 +477,6 @@ Root::save_input_history() {
|
||||
lt_log_print(torrent::LOG_DEBUG, "input history file written (path:%s)", history_filename.c_str());
|
||||
}
|
||||
|
||||
history_file.close();
|
||||
|
||||
std::rename(history_filename_tmp.c_str(), history_filename.c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <zlib.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "utils/functional.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
void
|
||||
@@ -21,6 +23,8 @@ gzip_compress_to_vector(const char* buffer, unsigned int length, std::vector<cha
|
||||
if (deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits | gzip_encoding, gzip_level, Z_DEFAULT_STRATEGY) != Z_OK)
|
||||
throw torrent::internal_error("gzip_compress_to_vector(...) could not initialize gzip deflate.");
|
||||
|
||||
scope_guard guard([&zs]() { deflateEnd(&zs); });
|
||||
|
||||
auto max_response_size = deflateBound(&zs, length);
|
||||
|
||||
output.resize(offset + max_response_size);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define RTORRENT_UTILS_GZIP_H
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace utils {
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ rtorrent_Test_Rpc_SOURCES = $(rtorrent_Test_Common) \
|
||||
rtorrent_Test_Src_SOURCES = $(rtorrent_Test_Common) \
|
||||
src/test_command_dynamic.cc \
|
||||
src/test_command_dynamic.h \
|
||||
src/test_command_ip.cc \
|
||||
src/test_command_ip.h \
|
||||
src/test_command_system.cc \
|
||||
src/test_command_system.h \
|
||||
src/test_command_path.cc \
|
||||
|
||||
@@ -61,3 +61,24 @@ TestCommandDynamic::test_old_style() {
|
||||
rpc::commands.call_command("method.insert", rpc::create_object_list("test_old_style.4", "simple", "cat=test.3"));
|
||||
CPPUNIT_ASSERT(rpc::commands.call_command("test_old_style.4", torrent::Object()).as_string() == "test.3");
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandDynamic::test_insert_list() {
|
||||
torrent::Object key_only = torrent::Object::create_list();
|
||||
key_only.as_list().push_back("test_insert_list.1");
|
||||
|
||||
rpc::commands.call_command("method.insert.list", key_only);
|
||||
|
||||
torrent::Object result = rpc::commands.call_command("test_insert_list.1", torrent::Object());
|
||||
|
||||
CPPUNIT_ASSERT(result.is_list());
|
||||
CPPUNIT_ASSERT(result.as_list().empty());
|
||||
|
||||
rpc::commands.call_command("method.insert.list",
|
||||
rpc::create_object_list("test_insert_list.2", rpc::create_object_list("a", "b")));
|
||||
|
||||
torrent::Object filled = rpc::commands.call_command("test_insert_list.2", torrent::Object());
|
||||
|
||||
CPPUNIT_ASSERT(filled.is_list());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, filled.as_list().size());
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ class TestCommandDynamic : public test_fixture {
|
||||
CPPUNIT_TEST(test_basics);
|
||||
CPPUNIT_TEST(test_get_set);
|
||||
CPPUNIT_TEST(test_old_style);
|
||||
CPPUNIT_TEST(test_insert_list);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
@@ -18,6 +19,7 @@ public:
|
||||
void test_get_set();
|
||||
|
||||
void test_old_style();
|
||||
void test_insert_list();
|
||||
|
||||
private:
|
||||
std::unique_ptr<TestMainThread> m_test_main_thread;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "test/src/test_command_ip.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestCommandIp);
|
||||
|
||||
bool ipv4_range_parse(const char* address, uint32_t* address_start, uint32_t* address_end);
|
||||
|
||||
static uint32_t
|
||||
ipv4(uint32_t a, uint32_t b, uint32_t c, uint32_t d) {
|
||||
return (a << 24) | (b << 16) | (c << 8) | d;
|
||||
}
|
||||
|
||||
#define RANGE_ASSERT(address, expected_start, expected_end) \
|
||||
{ \
|
||||
uint32_t start = 0; \
|
||||
uint32_t end = 0; \
|
||||
\
|
||||
CPPUNIT_ASSERT(ipv4_range_parse(address, &start, &end)); \
|
||||
CPPUNIT_ASSERT_EQUAL(expected_start, start); \
|
||||
CPPUNIT_ASSERT_EQUAL(expected_end, end); \
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandIp::test_single_address() {
|
||||
RANGE_ASSERT("10.1.2.3", ipv4(10, 1, 2, 3), ipv4(10, 1, 2, 3));
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandIp::test_explicit_range() {
|
||||
RANGE_ASSERT("10.1.2.3-10.1.2.9", ipv4(10, 1, 2, 3), ipv4(10, 1, 2, 9));
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandIp::test_cidr() {
|
||||
RANGE_ASSERT("10.0.0.0/8", ipv4(10, 0, 0, 0), ipv4(10, 255, 255, 255));
|
||||
RANGE_ASSERT("10.1.2.0/24", ipv4(10, 1, 2, 0), ipv4(10, 1, 2, 255));
|
||||
RANGE_ASSERT("10.1.2.128/25", ipv4(10, 1, 2, 128), ipv4(10, 1, 2, 255));
|
||||
RANGE_ASSERT("10.1.2.3/31", ipv4(10, 1, 2, 2), ipv4(10, 1, 2, 3));
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandIp::test_cidr_zero_mask() {
|
||||
RANGE_ASSERT("0.0.0.0/0", ipv4(0, 0, 0, 0), ipv4(255, 255, 255, 255));
|
||||
RANGE_ASSERT("10.1.2.3/0", ipv4(0, 0, 0, 0), ipv4(255, 255, 255, 255));
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandIp::test_cidr_full_mask() {
|
||||
RANGE_ASSERT("10.1.2.3/32", ipv4(10, 1, 2, 3), ipv4(10, 1, 2, 3));
|
||||
RANGE_ASSERT("0.0.0.0/32", ipv4(0, 0, 0, 0), ipv4(0, 0, 0, 0));
|
||||
RANGE_ASSERT("255.255.255.255/32", ipv4(255, 255, 255, 255), ipv4(255, 255, 255, 255));
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
// ipv4_range_parse is a pure function, so this does not use test_fixture and
|
||||
// the mock and logging setup that comes with it.
|
||||
class TestCommandIp : public CppUnit::TestFixture {
|
||||
CPPUNIT_TEST_SUITE(TestCommandIp);
|
||||
|
||||
CPPUNIT_TEST(test_single_address);
|
||||
CPPUNIT_TEST(test_explicit_range);
|
||||
|
||||
CPPUNIT_TEST(test_cidr);
|
||||
CPPUNIT_TEST(test_cidr_zero_mask);
|
||||
CPPUNIT_TEST(test_cidr_full_mask);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void test_single_address();
|
||||
void test_explicit_range();
|
||||
|
||||
void test_cidr();
|
||||
void test_cidr_zero_mask();
|
||||
void test_cidr_full_mask();
|
||||
};
|
||||
Reference in New Issue
Block a user