Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: handle XML-RPC with JSON-RPC logics #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2

- run: sudo apt update
- run: sudo apt install -y build-essential ninja-build libgtest-dev libcurl4-openssl-dev libncursesw5-dev libssl-dev libxmlrpc-c++8-dev nlohmann-json3-dev zlib1g-dev
- run: sudo apt install -y build-essential ninja-build libgtest-dev libcurl4-openssl-dev libncursesw5-dev libssl-dev nlohmann-json3-dev zlib1g-dev

- name: Checkout libTorrent
uses: actions/checkout@v2
Expand Down
3 changes: 1 addition & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cmake(
filegroup(
name = "included_headers",
srcs = glob(
["include/**/*.h"],
["include/**/*.h", "include/**/*.hpp"],
exclude = ["include/buildinfo.h"],
),
)
Expand Down Expand Up @@ -83,7 +83,6 @@ cc_library(
"//:buildinfo",
"@curl",
"@json",
"@xmlrpc",
"@libtorrent//:torrent",
] + select({
"@platforms//os:macos": [],
Expand Down
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ else()
include_directories(${JSON_INCLUDE_DIR})
endif()

if(USE_XMLRPC)
find_package(XMLRPC REQUIRED c++)
include_directories(${XMLRPC_INCLUDE_DIRS})
endif()

file(GLOB_RECURSE RTORRENT_COMMON_SRCS "${PROJECT_SOURCE_DIR}/src/*.cc")
list(REMOVE_ITEM RTORRENT_COMMON_SRCS "${PROJECT_SOURCE_DIR}/src/main.cc")

Expand All @@ -90,9 +85,6 @@ else()
add_library(rtorrent_common OBJECT ${RTORRENT_COMMON_SRCS})
target_link_libraries(rtorrent_common ${TORRENT_LIBRARY} ${CURL_LIBRARIES}
${CURSES_LIBRARIES})
if(USE_XMLRPC)
target_link_libraries(rtorrent_common ${XMLRPC_LIBRARIES})
endif()

# rtorrent
add_executable(rtorrent "${PROJECT_SOURCE_DIR}/src/main.cc")
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ Dependencies:
- [libtorrent](https://github.com/jesec/libtorrent) with development files (core dependency, matching version required)
- libcurl with development files
- libncurses/libncursesw with development files (for terminal UI)
- libxmlrpc-c with development files (optional if USE_XMLRPC=OFF, for XML-RPC support)
- nlohmann/json with development files (optional if USE_JSONRPC=OFF, for JSON-RPC support)
- nlohmann/json with development files (optional if USE_JSONRPC=OFF, for RPC support)
- googletest with development files (optional, for unit tests)

```sh
Expand Down
9 changes: 0 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ http_archive(
)

# Foreign CC dependencies
http_archive(
name = "xmlrpc",
build_file = "@rtorrent//:third_party/xmlrpc.BUILD",
patches = ["@rtorrent//:third_party/xmlrpc.patch"],
sha256 = "92f8945d7748c48ddaf2a9eb60fb366c642f32136ce68abedc75244f9a0ea492",
strip_prefix = "xmlrpc-c-90978dfa964a57e6a31d76b128d0fa4ee9db574b/trunk",
urls = ["https://github.com/mirror/xmlrpc-c/archive/90978dfa964a57e6a31d76b128d0fa4ee9db574b.zip"],
)

http_archive(
name = "mimalloc",
build_file = "@rtorrent//:third_party/mimalloc.BUILD",
Expand Down
5 changes: 0 additions & 5 deletions cmake/GenerateRTorrentBuildinfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,4 @@ if(USE_JSONRPC)
file(APPEND ${BUILDINFO_H} "#define HAVE_JSON 1\n\n")
endif()

if(USE_XMLRPC)
file(APPEND ${BUILDINFO_H} "/* Support for XMLRPC-C */\n")
file(APPEND ${BUILDINFO_H} "#define HAVE_XMLRPC_C 1\n\n")
endif()

file(APPEND ${BUILDINFO_H} "#endif\n")
7 changes: 7 additions & 0 deletions include/rpc/rpc_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
#include <functional>

#ifdef HAVE_JSON
#include "utils/jsonrpc/common.h"
#include "utils/jsonrpc/server.h"
#include <nlohmann/json.hpp>

using jsonrpccxx::JsonRpcException;
using nlohmann::json;
#endif

#include "rpc/rpc.h"
Expand All @@ -31,6 +36,8 @@ class RpcJson final : public IRpc {

void insert_command(const char*, const char*, const char*) override {}

json jsonrpc_call_command(const std::string& method, const json& params);

private:
jsonrpccxx::JsonRpc2Server* m_jsonrpc;
#endif
Expand Down
19 changes: 9 additions & 10 deletions include/rpc/rpc_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,31 @@
#include <functional>

#include "rpc/rpc.h"
#include "rpc/rpc_json.h"

namespace rpc {

class RpcXml final : public IRpc {
#ifdef HAVE_XMLRPC_C
public:
void initialize() override;
RpcXml(RpcJson* rpcjson)
: m_rpcjson(rpcjson) {}

void cleanup() override;
void initialize() {}

void cleanup() {}

bool is_valid() const override {
return m_env != nullptr;
return m_rpcjson != nullptr && m_rpcjson->is_valid();
}

bool process(const char* inBuffer,
uint32_t length,
res_callback callback) override;

void insert_command(const char* name,
const char* parm,
const char* doc) override;
void insert_command(const char* name, const char* parm, const char* doc) {}

private:
void* m_env{ nullptr };
void* m_registry{ nullptr };
#endif
RpcJson* m_rpcjson;
};

}
Expand Down
52 changes: 52 additions & 0 deletions include/utils/rapidxml/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Use of this software is granted under one of the following two licenses,
to be chosen freely by the user.

1. Boost Software License - Version 1.0 - August 17th, 2003
===============================================================================

Copyright (c) 2006, 2007 Marcin Kalicinski

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

2. The MIT License
===============================================================================

Copyright (c) 2006, 2007 Marcin Kalicinski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
Loading