From e64ec358fad04bc57bb9e1077dd07eb746dfd345 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Thu, 9 Apr 2026 20:49:38 +0200 Subject: [PATCH] Removed deprecated rak headers. --- src/command_download.cc | 21 ++++++++++++--------- src/core/download_factory.cc | 3 ++- src/rpc/lua.cc | 22 ++++++++++++---------- src/rpc/rpc_manager.cc | 17 +++++++++-------- src/session/download_storer.cc | 5 ++--- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/command_download.cc b/src/command_download.cc index de80901f..bf970fcc 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -22,6 +21,7 @@ #include #include #include +#include #include "core/download.h" #include "core/manager.h" @@ -276,7 +276,7 @@ retrieve_d_bitfield(core::Download* download) { if (bitField->empty()) return torrent::Object(""); - return torrent::Object(rak::transform_hex(bitField->begin(), bitField->end())); + return torrent::Object(torrent::utils::transform_to_hex_str(*bitField)); } void @@ -326,7 +326,8 @@ d_chunks_seen(core::Download* download) { std::string result; result.resize(size * 2); - rak::transform_hex((const char*)seen, (const char*)seen + size, result.begin()); + torrent::utils::transform_to_hex(seen, seen + size, result.begin(), result.end()); + return result; } @@ -444,9 +445,11 @@ p_call_target(const torrent::Object::list_type& args) { torrent::HashString hash; - if (peer_id.size() != 40 || - torrent::hash_string_from_hex_c_str(peer_id.c_str(), hash) == peer_id.c_str()) - throw torrent::input_error("Not a hash string."); + if (peer_id.size() != 40) + throw torrent::input_error("invalid argument: peer id target is not 40 bytes long"); + + if (torrent::utils::transform_from_hex(peer_id.c_str(), peer_id.c_str() + 40, hash.begin(), hash.end()) != hash.end()) + throw torrent::input_error("invalid argument: peer id target is not a hex string"); torrent::ConnectionList::iterator peerItr = download->connection_list()->find(hash.c_str()); @@ -641,9 +644,9 @@ void cg_d_group_set(core::Download* download, const torrent::Objec void initialize_command_download() { - CMD2_DL("d.hash", std::bind(&rak::transform_hex_str, CMD2_ON_INFO(hash))); - CMD2_DL("d.local_id", std::bind(&rak::transform_hex_str, CMD2_ON_INFO(local_id))); - CMD2_DL("d.local_id_html", std::bind(&rak::copy_escape_html_str, CMD2_ON_INFO(local_id))); + CMD2_DL("d.hash", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(download->info()->hash()); }); + CMD2_DL("d.local_id", [](auto* download, auto) { return torrent::utils::transform_to_hex_str(download->info()->local_id()); }); + CMD2_DL("d.local_id_html", [](auto* download, auto) { return torrent::utils::copy_escape_html(download->info()->local_id()); }); CMD2_DL("d.bitfield", std::bind(&retrieve_d_bitfield, std::placeholders::_1)); CMD2_DL("d.base_path", std::bind(&retrieve_d_base_path, std::placeholders::_1)); CMD2_DL("d.base_filename", std::bind(&retrieve_d_base_filename, std::placeholders::_1)); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 185dda00..ff07bce8 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include "control.h" #include "globals.h" @@ -327,7 +328,7 @@ void DownloadFactory::log_created(Download* download, torrent::Object* rtorrent) { std::stringstream dump; - dump << "info_hash = " << torrent::hash_string_to_hex_str(download->info()->hash()) << std::endl; + dump << "info_hash = " << torrent::utils::transform_to_hex_str(download->info()->hash()) << std::endl; dump << "session = " << (m_session ? "true" : "false") << std::endl; if (download->download()->info()->is_meta_download()) diff --git a/src/rpc/lua.cc b/src/rpc/lua.cc index a69087c8..a6a9d61f 100644 --- a/src/rpc/lua.cc +++ b/src/rpc/lua.cc @@ -7,12 +7,13 @@ #include #include "rpc/lua.h" + #ifdef HAVE_LUA #include #endif -#include #include +#include #include "core/download.h" #include "rpc/command.h" @@ -169,19 +170,18 @@ object_to_target(const torrent::Object& obj, int call_flags, rpc::target_type* t } // Length of SHA1 hash is 40 - if (target_string.size() < 40) { + if (target_string.size() < 40) throw torrent::input_error("invalid parameters: invalid target"); - } char type = 'd'; std::string hash; std::string index; + const auto& delim_pos = target_string.find_first_of(':', 40); if (delim_pos == target_string.npos || delim_pos + 2 >= target_string.size()) { - if (require_index) { + if (require_index) throw torrent::input_error("invalid parameters: no index"); - } hash = target_string; @@ -217,12 +217,14 @@ object_to_target(const torrent::Object& obj, int call_flags, rpc::target_type* t case 'p': { - if (index.size() < 40) { - throw torrent::input_error("Not a hash string."); - } + if (index.size() != 40) + throw torrent::input_error("invalid parameters: target is not 40 bytes long"); torrent::HashString hash; - torrent::hash_string_from_hex_c_str(index.c_str(), hash); + + if (torrent::utils::transform_from_hex(index.c_str(), index.c_str() + 40, hash.begin(), hash.end()) != hash.end()) + throw torrent::input_error("invalid parameters: target is not a hex string"); + *target = rpc::make_target(command_base::target_peer, rpc.slot_find_peer()(download, hash)); } break; @@ -381,7 +383,7 @@ execute_lua(LuaEngine* engine, rpc::target_type target_type, torrent::Object con case (command_base::target_download): core::Download* dl_target = (core::Download*)target_type.second; torrent::HashString infohash = dl_target->info()->hash(); - target_string = rak::transform_hex_str(infohash); + target_string = torrent::utils::transform_to_hex_str(infohash); break; } diff --git a/src/rpc/rpc_manager.cc b/src/rpc/rpc_manager.cc index 4ed8171f..fb583811 100644 --- a/src/rpc/rpc_manager.cc +++ b/src/rpc/rpc_manager.cc @@ -3,6 +3,7 @@ #include #include +#include #include "parse_commands.h" #include "rpc/rpc_manager.h" @@ -47,11 +48,11 @@ RpcManager::object_to_target(const torrent::Object& obj, int call_flags, rpc::ta const auto& delim_pos = target_string.find_first_of(':', 40); - if (delim_pos == target_string.npos || - delim_pos + 2 >= target_string.size()) { + if (delim_pos == target_string.npos || delim_pos + 2 >= target_string.size()) { if (require_index) { throw torrent::input_error("invalid parameters: no index"); } + hash = target_string; } else { @@ -87,15 +88,15 @@ RpcManager::object_to_target(const torrent::Object& obj, int call_flags, rpc::ta break; case 'p': { - if (index.size() < 40) { - throw torrent::input_error("invalid parameters: not a hash string."); - } + if (index.size() != 40) + throw torrent::input_error("invalid parameters: target is not 40 bytes long"); torrent::HashString hash; - torrent::hash_string_from_hex_c_str(index.c_str(), hash); - *target = rpc::make_target(command_base::target_peer, - rpc.slot_find_peer()(download, hash)); + if (torrent::utils::transform_from_hex(index.c_str(), index.c_str() + 40, hash.begin(), hash.end()) != hash.end()) + throw torrent::input_error("invalid parameters: target is not a hex string"); + + *target = rpc::make_target(command_base::target_peer, rpc.slot_find_peer()(download, hash)); break; } diff --git a/src/session/download_storer.cc b/src/session/download_storer.cc index 1fa59d11..1af2f1cd 100644 --- a/src/session/download_storer.cc +++ b/src/session/download_storer.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include "globals.h" #include "core/download.h" @@ -74,15 +75,13 @@ DownloadStorer::build_streams(bool skip_static) { std::string DownloadStorer::build_path(const std::string& session_path) { - auto info_hash = m_download->info()->info_hash(); - if (session_path.empty()) throw torrent::internal_error("DownloadStorer::build_path() called with empty session path."); if (session_path.back() != '/') throw torrent::internal_error("DownloadStorer::build_path() session path missing trailing slash."); - return session_path + torrent::hash_string_to_hex_str(info_hash) + ".torrent"; + return session_path + torrent::utils::transform_to_hex_str(m_download->info()->info_hash()) + ".torrent"; } void