* Added xmlrpc calls for peer snubbed, banned and disconnect.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1180 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2010-10-08 08:10:08 +00:00
parent a0f3e95d20
commit 0e69677dbc
9 changed files with 92 additions and 18 deletions
+1 -1
View File
@@ -127,7 +127,7 @@ public:
const mapped_type call(key_type key, target_type target, const mapped_type& args = mapped_type()) { return call_command(key, args, target); }
const mapped_type call_catch(key_type key, target_type target, const mapped_type& args = mapped_type(), const char* err = "Command failed: ");
const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)command_base::target_generic, NULL));
const mapped_type call_command (key_type key, const mapped_type& arg, target_type target = target_type((int)command_base::target_generic, NULL));
const mapped_type call_command (iterator itr, const mapped_type& arg, target_type target = target_type((int)command_base::target_generic, NULL));
const mapped_type call_command_d(key_type key, core::Download* download, const mapped_type& arg) { return call_command(key, arg, target_type((int)command_base::target_download, download)); }
-8
View File
@@ -120,14 +120,6 @@ CommandScheduler::call_item(value_type item) {
void
CommandScheduler::parse(const std::string& key, const std::string& bufAbsolute, const std::string& bufInterval, const std::string& command) {
// char key[21];
// char bufAbsolute[21];
// char bufInterval[21];
// char command[2048];
// if (std::sscanf(arg.c_str(), "%20[^,],%20[^,],%20[^,],%2047[^\n]", key, bufAbsolute, bufInterval, command) != 4)
// throw torrent::input_error("Invalid arguments to command.");
uint32_t absolute = parse_absolute(bufAbsolute.c_str());
uint32_t interval = parse_interval(bufInterval.c_str());
+3
View File
@@ -218,6 +218,9 @@ SCgiTask::event_error() {
bool
SCgiTask::receive_write(const char* buffer, uint32_t length) {
if (buffer == NULL || length > (100 << 20))
throw torrent::internal_error("SCgiTask::receive_write(...) received bad input.");
// Need to cast due to a bug in MacOSX gcc-4.0.1.
if (length + 256 > std::max(m_bufferSize, (unsigned int)default_buffer_size))
realloc_buffer(length + 256, NULL, 0);
+21 -7
View File
@@ -41,6 +41,8 @@
#include <xmlrpc-c/server.h>
#endif
#include <cctype>
#include <rak/string_manip.h>
#include <torrent/object.h>
#include <torrent/exceptions.h>
@@ -175,29 +177,38 @@ xmlrpc_to_target(xmlrpc_env* env, xmlrpc_value* value) {
// Trackers: "<hash>:t<index>"
int index;
const char* end;
const char* end_ptr = str + 42;
switch (str[41]) {
case 'f':
end = str + 42;
index = ::strtol(str + 42, (char**)&end, 0);
index = ::strtol(str + 42, (char**)&end_ptr, 0);
if (*str == '\0' || *end != '\0')
if (*str == '\0' || *end_ptr != '\0')
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Invalid index.");
target = rpc::make_target(XmlRpc::call_file, xmlrpc.get_slot_find_file()(download, index));
break;
case 't':
end = str + 42;
index = ::strtol(str + 42, (char**)&end, 0);
index = ::strtol(str + 42, (char**)&end_ptr, 0);
if (*str == '\0' || *end != '\0')
if (*str == '\0' || *end_ptr != '\0')
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Invalid index.");
target = rpc::make_target(XmlRpc::call_tracker, xmlrpc.get_slot_find_tracker()(download, index));
break;
case 'p':
{
torrent::HashString hash;
const char* hash_end = torrent::hash_string_from_hex_c_str(str + 42, hash);
if (hash_end == end_ptr || *hash_end != '\0')
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Not a hash string.");
target = rpc::make_target(XmlRpc::call_peer, xmlrpc.get_slot_find_peer()(download, hash));
break;
}
default:
::free((void*)str);
throw xmlrpc_error(XMLRPC_TYPE_ERROR, "Unsupported target type found.");
@@ -496,6 +507,9 @@ XmlRpc::process(const char* inBuffer, uint32_t length, slot_write slotWrite) {
xmlrpc_mem_block* memblock = xmlrpc_registry_process_call(&localEnv, (xmlrpc_registry*)m_registry, NULL, inBuffer, length);
if (localEnv.fault_occurred && localEnv.fault_code == XMLRPC_INTERNAL_ERROR)
throw torrent::internal_error("Internal error in XMLRPC.");
bool result = slotWrite((const char*)xmlrpc_mem_block_contents(memblock),
xmlrpc_mem_block_size(memblock));
+6
View File
@@ -38,6 +38,7 @@
#define RTORRENT_RPC_XMLRPC_H
#include <rak/functional_fun.h>
#include <torrent/hash_string.h>
namespace core {
class Download;
@@ -56,6 +57,7 @@ public:
typedef rak::function1<core::Download*, const char*> slot_find_download;
typedef rak::function2<torrent::File*, core::Download*, uint32_t> slot_find_file;
typedef rak::function2<torrent::Tracker*, core::Download*, uint32_t> slot_find_tracker;
typedef rak::function2<torrent::Peer*, core::Download*, const torrent::HashString&> slot_find_peer;
typedef rak::function2<bool, const char*, uint32_t> slot_write;
static const int dialect_generic = 0;
@@ -94,6 +96,9 @@ public:
slot_find_tracker& get_slot_find_tracker() { return m_slotFindTracker; }
void set_slot_find_tracker(slot_find_tracker::base_type* slot) { m_slotFindTracker.set(slot); }
slot_find_peer& get_slot_find_peer() { return m_slotFindPeer; }
void set_slot_find_peer(slot_find_peer::base_type* slot) { m_slotFindPeer.set(slot); }
static int64_t size_limit();
static void set_size_limit(uint64_t size);
@@ -106,6 +111,7 @@ private:
slot_find_download m_slotFindDownload;
slot_find_file m_slotFindFile;
slot_find_tracker m_slotFindTracker;
slot_find_peer m_slotFindPeer;
};
}