mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-12 21:22:31 +00:00
Added support base64 support for non-UTF8 strings.
This commit is contained in:
+41
-13
@@ -24,24 +24,46 @@ apply_f_path(torrent::File* file) {
|
||||
if (file->path()->empty())
|
||||
return std::string();
|
||||
|
||||
torrent::Object resultRaw(*file->path()->begin());
|
||||
torrent::Object::string_type& result = resultRaw.as_string();
|
||||
torrent::Object result_raw(file->path()->begin()->str());
|
||||
auto& result = result_raw.as_string();
|
||||
|
||||
for (torrent::Path::const_iterator itr = ++file->path()->begin(), last = file->path()->end(); itr != last; itr++)
|
||||
result += '/' + *itr;
|
||||
result += '/' + itr->str();
|
||||
|
||||
return resultRaw;
|
||||
return result_raw;
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
apply_f_path_components(torrent::File* file) {
|
||||
torrent::Object resultRaw = torrent::Object::create_list();
|
||||
torrent::Object::list_type& result = resultRaw.as_list();
|
||||
auto result_raw = torrent::Object::create_list();
|
||||
auto& result = result_raw.as_list();
|
||||
|
||||
for (const auto& itr : *file->path())
|
||||
result.push_back(itr);
|
||||
result.push_back(itr.str());
|
||||
|
||||
return resultRaw;
|
||||
return result_raw;
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
apply_f_path_components_base64(torrent::File* file) {
|
||||
auto result_raw = torrent::Object::create_list();
|
||||
auto& result = result_raw.as_list();
|
||||
|
||||
for (const auto& itr : *file->path())
|
||||
result.push_back(itr.object_base64());
|
||||
|
||||
return result_raw;
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
apply_f_path_components_or_base64(torrent::File* file) {
|
||||
auto result_raw = torrent::Object::create_list();
|
||||
auto& result = result_raw.as_list();
|
||||
|
||||
for (const auto& itr : *file->path())
|
||||
result.push_back(itr.object_utf8_or_base64());
|
||||
|
||||
return result_raw;
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
@@ -57,7 +79,7 @@ apply_fi_filename_last(torrent::FileListIterator* itr) {
|
||||
if (itr->depth() >= itr->file()->path()->size())
|
||||
return "ERROR";
|
||||
|
||||
return itr->file()->path()->at(itr->depth());
|
||||
return itr->file()->path()->at(itr->depth()).str();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -91,10 +113,14 @@ initialize_command_file() {
|
||||
CMD2_FILE("f.priority", std::bind(&torrent::File::priority, std::placeholders::_1));
|
||||
CMD2_FILE_VALUE_V("f.priority.set", std::bind(&apply_f_set_priority, std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
CMD2_FILE("f.path", std::bind(&apply_f_path, std::placeholders::_1));
|
||||
CMD2_FILE("f.path_components", std::bind(&apply_f_path_components, std::placeholders::_1));
|
||||
CMD2_FILE("f.path_depth", std::bind(&apply_f_path_depth, std::placeholders::_1));
|
||||
CMD2_FILE("f.frozen_path", std::bind(&torrent::File::frozen_path, std::placeholders::_1));
|
||||
CMD2_FILE("f.path", [](auto* file, auto) { return apply_f_path(file); });
|
||||
CMD2_FILE("f.path_components", [](auto* file, auto) { return apply_f_path_components(file); });
|
||||
CMD2_FILE("f.path_components.base64", [](auto* file, auto) { return apply_f_path_components_base64(file); });
|
||||
CMD2_FILE("f.path_components.or_base64", [](auto* file, auto) { return apply_f_path_components_or_base64(file); });
|
||||
CMD2_FILE("f.path_depth", [](auto* file, auto) { return apply_f_path_depth(file); });
|
||||
CMD2_FILE("f.frozen_path", [](auto* file, auto) { return file->frozen_path().str(); });
|
||||
CMD2_FILE("f.frozen_path.base64", [](auto* file, auto) { return file->frozen_path().object_base64(); });
|
||||
CMD2_FILE("f.frozen_path.or_base64", [](auto* file, auto) { return file->frozen_path().object_utf8_or_base64(); });
|
||||
|
||||
CMD2_FILE("f.match_depth_prev", std::bind(&torrent::File::match_depth_prev, std::placeholders::_1));
|
||||
CMD2_FILE("f.match_depth_next", std::bind(&torrent::File::match_depth_next, std::placeholders::_1));
|
||||
@@ -108,6 +134,8 @@ initialize_command_file() {
|
||||
rpc::rpc.mark_safe("f.path_components");
|
||||
rpc::rpc.mark_safe("f.path_depth");
|
||||
rpc::rpc.mark_safe("f.frozen_path");
|
||||
rpc::rpc.mark_safe("f.frozen_path.base64");
|
||||
rpc::rpc.mark_safe("f.frozen_path.or_base64");
|
||||
rpc::rpc.mark_safe("f.offset");
|
||||
rpc::rpc.mark_safe("f.size_bytes");
|
||||
rpc::rpc.mark_safe("f.size_chunks");
|
||||
|
||||
Reference in New Issue
Block a user