This commit is contained in:
rakshasa
2026-09-01 16:16:30 +02:00
parent 6b60c219fa
commit 83eb4e016a
4 changed files with 35 additions and 28 deletions
+16 -10
View File
@@ -128,27 +128,33 @@ DownloadFactory::load_untrusted(const std::string& uri) {
} }
void void
DownloadFactory::load_raw_data(const std::string& input) { DownloadFactory::load_raw_data_trusted(const std::string& input) {
if (!m_trusted)
throw torrent::internal_error("DownloadFactory::load_raw_data_trusted() called on an untrusted object");
if (m_stream) if (m_stream)
throw torrent::internal_error("DownloadFactory::load_raw_data() called on an object with m_stream != NULL"); throw torrent::internal_error("DownloadFactory::load_raw_data_trusted() called on an object with m_stream != NULL");
m_stream.reset(new std::stringstream(input)); m_stream.reset(new std::stringstream(input));
m_loaded = true; m_loaded = true;
} }
void void
DownloadFactory::commit_trusted() { DownloadFactory::load_raw_data_untrusted(const std::string& input) {
if (!m_trusted) if (m_trusted)
throw torrent::internal_error("DownloadFactory::commit_trusted() called on an untrusted object"); throw torrent::internal_error("DownloadFactory::load_raw_data_untrusted() called on an trusted object");
m_task_commit.slot() = [this]() { receive_commit(); }; if (m_stream)
torrent::this_thread::scheduler()->wait_for(&m_task_commit, 0ms); throw torrent::internal_error("DownloadFactory::load_raw_data_untrusted() called on an object with m_stream != NULL");
m_stream.reset(new std::stringstream(input));
m_loaded = true;
} }
void void
DownloadFactory::commit_untrusted() { DownloadFactory::commit() {
if (m_trusted) if (!m_trusted)
throw torrent::internal_error("DownloadFactory::commit_untrusted() called on a trusted object"); throw torrent::internal_error("DownloadFactory::commit() called on an untrusted object");
m_task_commit.slot() = [this]() { receive_commit(); }; m_task_commit.slot() = [this]() { receive_commit(); };
torrent::this_thread::scheduler()->wait_for(&m_task_commit, 0ms); torrent::this_thread::scheduler()->wait_for(&m_task_commit, 0ms);
+3 -3
View File
@@ -33,10 +33,10 @@ public:
void load_trusted(const std::string& uri); void load_trusted(const std::string& uri);
void load_untrusted(const std::string& uri); void load_untrusted(const std::string& uri);
void load_raw_data(const std::string& input); void load_raw_data_trusted(const std::string& input);
void load_raw_data_untrusted(const std::string& input);
void commit_trusted(); void commit();
void commit_untrusted();
command_list_type& commands() { return m_commands; } command_list_type& commands() { return m_commands; }
torrent::Object::map_type& variables() { return m_variables; } torrent::Object::map_type& variables() { return m_variables; }
+12 -11
View File
@@ -197,7 +197,7 @@ Manager::try_create_download(const std::string& uri, int flags, const command_li
return; return;
// Adding download. // Adding download.
DownloadFactory* f = new DownloadFactory(this); DownloadFactory* f = new DownloadFactory(this, true);
f->variables()["tied_to_file"] = (int64_t)(bool)(flags & create_tied); f->variables()["tied_to_file"] = (int64_t)(bool)(flags & create_tied);
f->commands().insert(f->commands().end(), commands.begin(), commands.end()); f->commands().insert(f->commands().end(), commands.begin(), commands.end());
@@ -207,16 +207,16 @@ Manager::try_create_download(const std::string& uri, int flags, const command_li
f->slot_finished([f]() { delete f; }); f->slot_finished([f]() { delete f; });
if (flags & create_raw_data) { if (flags & create_raw_data) {
f->load_raw_data(uri); f->load_raw_data_trusted(uri);
} else if (is_data_uri(uri)) { } else if (is_data_uri(uri)) {
// Allow the use of data URIs, primarily for JSON-RPC which // Allow the use of data URIs, primarily for JSON-RPC which
// doesn't have a defined mechanism for binary data // doesn't have a defined mechanism for binary data
f->load_raw_data(decode_data_uri(uri)); f->load_raw_data_trusted(decode_data_uri(uri));
f->variables()["tied_to_file"] = (int64_t)false; f->variables()["tied_to_file"] = (int64_t)false;
} else { } else {
f->load(uri); f->load_trusted(uri);
} }
f->commit(); f->commit();
@@ -244,13 +244,14 @@ Manager::try_create_download_expand(const std::string& uri, int flags, command_l
void void
Manager::try_create_download_from_meta_download(torrent::Object* bencode, const std::string& metafile) { Manager::try_create_download_from_meta_download(torrent::Object* bencode, const std::string& metafile) {
DownloadFactory* f = new DownloadFactory(this); DownloadFactory* f = new DownloadFactory(this, true);
f->variables()["tied_to_file"] = (int64_t)true; f->variables()["tied_to_file"] = (int64_t)true;
f->variables()["tied_file"] = metafile; f->variables()["tied_file"] = metafile;
torrent::Object& meta = bencode->get_key("rtorrent_meta_download"); torrent::Object& meta = bencode->get_key("rtorrent_meta_download");
torrent::Object::list_type& commands = meta.get_key_list("commands"); torrent::Object::list_type& commands = meta.get_key_list("commands");
for (const auto& command : commands) for (const auto& command : commands)
f->commands().insert(f->commands().end(), command.as_string()); f->commands().insert(f->commands().end(), command.as_string());
@@ -263,7 +264,8 @@ Manager::try_create_download_from_meta_download(torrent::Object* bencode, const
std::stringstream s; std::stringstream s;
s.imbue(std::locale::classic()); s.imbue(std::locale::classic());
s << *bencode; s << *bencode;
f->load_raw_data(s.str());
f->load_raw_data_trusted(s.str());
f->commit(); f->commit();
} }
@@ -279,8 +281,7 @@ Manager::try_create_download_untrusted(const std::string& uri, int flags, const
return; return;
} }
// Adding download. DownloadFactory* f = new DownloadFactory(this, false);
DownloadFactory* f = new DownloadFactory(this);
f->commands().insert(f->commands().end(), commands.begin(), commands.end()); f->commands().insert(f->commands().end(), commands.begin(), commands.end());
@@ -299,10 +300,10 @@ Manager::try_create_download_untrusted(const std::string& uri, int flags, const
} else { } else {
// f->load_untrusted(uri); // f->load_untrusted(uri);
throw internal_error("Manager::try_create_download_untrusted() unimplemented."); throw torrent::internal_error("Manager::try_create_download_untrusted() unimplemented.");
} }
f->commit_untrusted(); f->commit();
} }
namespace { namespace {
+4 -4
View File
@@ -157,12 +157,12 @@ load_session_torrents(const std::string& path) {
if (!entry.is_file()) if (!entry.is_file())
continue; continue;
auto* f = new core::DownloadFactory(control->core()); auto* f = new core::DownloadFactory(control->core(), true);
f->set_session(true); f->set_session(true);
f->set_init_load(true); f->set_init_load(true);
f->slot_finished([f](){ delete f; }); f->slot_finished([f](){ delete f; });
f->load(entries.path() + entry.s_name); f->load_trusted(entries.path() + entry.s_name);
f->commit(); f->commit();
} }
} }
@@ -170,12 +170,12 @@ load_session_torrents(const std::string& path) {
void void
load_arg_torrents(char** first, char** last) { load_arg_torrents(char** first, char** last) {
for (; first != last; ++first) { for (; first != last; ++first) {
auto* f = new core::DownloadFactory(control->core()); auto* f = new core::DownloadFactory(control->core(), true);
f->set_start(true); f->set_start(true);
f->set_init_load(true); f->set_init_load(true);
f->slot_finished([f](){ delete f; }); f->slot_finished([f](){ delete f; });
f->load(*first); f->load_trusted(*first);
f->commit(); f->commit();
} }
} }