mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-17 15:42:30 +00:00
Added support base64 support for non-UTF8 strings.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <string>
|
||||
#include <torrent/common.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/utils/string_manip.h>
|
||||
|
||||
#include "rpc/rpc_manager.h"
|
||||
#include "rpc/command.h"
|
||||
@@ -66,12 +67,23 @@ object_to_json(const torrent::Object& object) noexcept {
|
||||
switch (object.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
return object.as_value();
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
if (object.flags() & torrent::Object::flag_base64) {
|
||||
std::vector<uint8_t> binary_data;
|
||||
torrent::utils::transform_from_hex(object.as_string(), binary_data);
|
||||
|
||||
return json::binary(binary_data);
|
||||
}
|
||||
|
||||
return object.as_string();
|
||||
|
||||
case torrent::Object::TYPE_LIST: {
|
||||
json result = json::array();
|
||||
|
||||
for (const auto& obj : object.as_list())
|
||||
result.push_back(object_to_json(obj));
|
||||
|
||||
return result;
|
||||
}
|
||||
case torrent::Object::TYPE_MAP: {
|
||||
@@ -135,7 +147,9 @@ jsonrpc_call_command(const std::string& method, const json& params) {
|
||||
|
||||
try {
|
||||
const auto& result = rpc::commands.call_command(itr, params_object, target);
|
||||
|
||||
return object_to_json(result);
|
||||
|
||||
} catch (untrusted_error& e) {
|
||||
throw rpc_error(JSONRPC_METHOD_NOT_FOUND_ERROR, e.what());
|
||||
}
|
||||
|
||||
@@ -278,6 +278,9 @@ object_to_xmlrpc(xmlrpc_env* env, const torrent::Object& object) {
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
{
|
||||
if (object.flags() & torrent::Object::flag_base64)
|
||||
return xmlrpc_base64_new(env, object.as_string().c_str(), object.as_string().size());
|
||||
|
||||
#ifdef XMLRPC_HAVE_I8
|
||||
// The versions that support I8 do implicit utf-8 validation.
|
||||
xmlrpc_value* result = xmlrpc_string_new(env, object.as_string().c_str());
|
||||
|
||||
@@ -152,10 +152,18 @@ void
|
||||
print_object_xml(const torrent::Object& obj, tinyxml2::XMLPrinter* printer) {
|
||||
switch (obj.type()) {
|
||||
case torrent::Object::TYPE_STRING:
|
||||
if (obj.flags() & torrent::Object::flag_base64) {
|
||||
printer->OpenElement("base64", true);
|
||||
printer->PushText(obj.as_string().c_str());
|
||||
printer->CloseElement(true);
|
||||
break;
|
||||
}
|
||||
|
||||
printer->OpenElement("string", true);
|
||||
printer->PushText(obj.as_string().c_str());
|
||||
printer->CloseElement(true);
|
||||
break;
|
||||
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
printer->OpenElement("i8", true);
|
||||
printer->PushText(std::to_string(obj.as_value()).c_str());
|
||||
|
||||
Reference in New Issue
Block a user