mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-06 14:19:21 +00:00
* Allow loading torrents from https and ftp uri's.
* Added framework for commands on peers, but due to deficiencies in the libtorrent API it won't be enabled yet. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@955 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -6,6 +6,8 @@ libsub_rpc_a_SOURCES = \
|
||||
command_download_slot.h \
|
||||
command_file_slot.cc \
|
||||
command_file_slot.h \
|
||||
command_peer_slot.cc \
|
||||
command_peer_slot.h \
|
||||
command_tracker_slot.cc \
|
||||
command_tracker_slot.h \
|
||||
command_map.cc \
|
||||
|
||||
@@ -84,6 +84,14 @@ CommandMap::insert_file(key_type key, Command* variable, file_slot targetSlot, i
|
||||
itr->second.m_fileSlot = targetSlot;
|
||||
}
|
||||
|
||||
void
|
||||
CommandMap::insert_peer(key_type key, Command* variable, peer_slot targetSlot, int flags, const char* parm, const char* doc) {
|
||||
iterator itr = insert(key, variable, flags, parm, doc);
|
||||
|
||||
itr->second.m_target = target_peer;
|
||||
itr->second.m_peerSlot = targetSlot;
|
||||
}
|
||||
|
||||
void
|
||||
CommandMap::insert_tracker(key_type key, Command* variable, tracker_slot targetSlot, int flags, const char* parm, const char* doc) {
|
||||
iterator itr = insert(key, variable, flags, parm, doc);
|
||||
@@ -103,10 +111,12 @@ CommandMap::insert(key_type key, const command_map_data_type src) {
|
||||
|
||||
itr->second.m_target = src.m_target;
|
||||
|
||||
// This _should_ be optimized int just one assignment.
|
||||
switch (itr->second.m_target) {
|
||||
case target_generic: itr->second.m_genericSlot = src.m_genericSlot; break;
|
||||
case target_download: itr->second.m_downloadSlot = src.m_downloadSlot; break;
|
||||
case target_file: itr->second.m_fileSlot = src.m_fileSlot; break;
|
||||
case target_peer: itr->second.m_peerSlot = src.m_peerSlot; break;
|
||||
case target_tracker: itr->second.m_trackerSlot = src.m_trackerSlot; break;
|
||||
default: throw torrent::internal_error("CommandMap::insert(...) Invalid target.");
|
||||
}
|
||||
@@ -123,10 +133,12 @@ CommandMap::call_command(key_type key, const mapped_type& arg, target_type targe
|
||||
(itr->second.m_target != target_generic && target.second == NULL))
|
||||
throw torrent::input_error("Command type mis-match.");
|
||||
|
||||
// This _should_ be optimized int just two calls.
|
||||
switch (itr->second.m_target) {
|
||||
case target_generic: return itr->second.m_genericSlot(itr->second.m_variable, arg);
|
||||
case target_download: return itr->second.m_downloadSlot(itr->second.m_variable, (core::Download*)target.second, arg);
|
||||
case target_file: return itr->second.m_fileSlot(itr->second.m_variable, (torrent::File*)target.second, arg);
|
||||
case target_peer: return itr->second.m_peerSlot(itr->second.m_variable, (torrent::Peer*)target.second, arg);
|
||||
case target_tracker: return itr->second.m_trackerSlot(itr->second.m_variable, (torrent::Tracker*)target.second, arg);
|
||||
default: throw torrent::internal_error("CommandMap::call_command(...) Invalid target.");
|
||||
}
|
||||
|
||||
+11
-4
@@ -48,6 +48,7 @@ namespace core {
|
||||
|
||||
namespace torrent {
|
||||
class File;
|
||||
class Peer;
|
||||
class Tracker;
|
||||
}
|
||||
|
||||
@@ -66,6 +67,7 @@ struct command_map_data_type {
|
||||
typedef const torrent::Object (*generic_slot) (Command*, const torrent::Object&);
|
||||
typedef const torrent::Object (*download_slot)(Command*, core::Download*, const torrent::Object&);
|
||||
typedef const torrent::Object (*file_slot) (Command*, torrent::File*, const torrent::Object&);
|
||||
typedef const torrent::Object (*peer_slot) (Command*, torrent::Peer*, const torrent::Object&);
|
||||
typedef const torrent::Object (*tracker_slot) (Command*, torrent::Tracker*, const torrent::Object&);
|
||||
|
||||
command_map_data_type(Command* variable, int flags, const char* parm, const char* doc) :
|
||||
@@ -77,6 +79,7 @@ struct command_map_data_type {
|
||||
generic_slot m_genericSlot;
|
||||
download_slot m_downloadSlot;
|
||||
file_slot m_fileSlot;
|
||||
peer_slot m_peerSlot;
|
||||
tracker_slot m_trackerSlot;
|
||||
};
|
||||
|
||||
@@ -94,6 +97,7 @@ public:
|
||||
typedef command_map_data_type::generic_slot generic_slot;
|
||||
typedef command_map_data_type::download_slot download_slot;
|
||||
typedef command_map_data_type::file_slot file_slot;
|
||||
typedef command_map_data_type::peer_slot peer_slot;
|
||||
typedef command_map_data_type::tracker_slot tracker_slot;
|
||||
|
||||
typedef torrent::Object mapped_type;
|
||||
@@ -112,7 +116,8 @@ public:
|
||||
static const int target_generic = 0;
|
||||
static const int target_download = 1;
|
||||
static const int target_file = 2;
|
||||
static const int target_tracker = 3;
|
||||
static const int target_peer = 3;
|
||||
static const int target_tracker = 4;
|
||||
|
||||
static const int flag_dont_delete = 0x1;
|
||||
static const int flag_public_xmlrpc = 0x2;
|
||||
@@ -125,16 +130,18 @@ public:
|
||||
|
||||
iterator insert(key_type key, Command* variable, int flags, const char* parm, const char* doc);
|
||||
|
||||
void insert_generic(key_type key, Command* variable, generic_slot targetSlot, int flags, const char* parm, const char* doc);
|
||||
void insert_generic (key_type key, Command* variable, generic_slot targetSlot, int flags, const char* parm, const char* doc);
|
||||
void insert_download(key_type key, Command* variable, download_slot targetSlot, int flags, const char* parm, const char* doc);
|
||||
void insert_file(key_type key, Command* variable, file_slot targetSlot, int flags, const char* parm, const char* doc);
|
||||
void insert_tracker(key_type key, Command* variable, tracker_slot targetSlot, int flags, const char* parm, const char* doc);
|
||||
void insert_file (key_type key, Command* variable, file_slot targetSlot, int flags, const char* parm, const char* doc);
|
||||
void insert_peer (key_type key, Command* variable, peer_slot targetSlot, int flags, const char* parm, const char* doc);
|
||||
void insert_tracker (key_type key, Command* variable, tracker_slot targetSlot, int flags, const char* parm, const char* doc);
|
||||
|
||||
void insert(key_type key, const command_map_data_type src);
|
||||
|
||||
const mapped_type call_command(key_type key, const mapped_type& arg, target_type target = target_type((int)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)target_download, download)); }
|
||||
const mapped_type call_command_f(key_type key, torrent::File* file, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_file, file)); }
|
||||
const mapped_type call_command_p(key_type key, torrent::Peer* peer, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_peer, peer)); }
|
||||
const mapped_type call_command_t(key_type key, torrent::Tracker* tracker, const mapped_type& arg) { return call_command(key, arg, target_type((int)target_tracker, tracker)); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2007, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <torrent/peer/peer.h>
|
||||
|
||||
#include "parse.h"
|
||||
#include "command_peer_slot.h"
|
||||
|
||||
namespace rpc {
|
||||
|
||||
const torrent::Object
|
||||
CommandPeerSlot::call_unknown(Command* rawCommand, torrent::Peer* peer, const torrent::Object& rawArgs) {
|
||||
CommandPeerSlot* command = static_cast<CommandPeerSlot*>(rawCommand);
|
||||
|
||||
return command->m_slot(peer, rawArgs);
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandPeerSlot::call_list(Command* rawCommand, torrent::Peer* peer, const torrent::Object& rawArgs) {
|
||||
CommandPeerSlot* command = static_cast<CommandPeerSlot*>(rawCommand);
|
||||
|
||||
switch (rawArgs.type()) {
|
||||
case torrent::Object::TYPE_LIST:
|
||||
return command->m_slot(peer, rawArgs);
|
||||
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
case torrent::Object::TYPE_STRING:
|
||||
{
|
||||
torrent::Object tmpList(torrent::Object::TYPE_LIST);
|
||||
tmpList.as_list().push_back(rawArgs);
|
||||
|
||||
return command->m_slot(peer, tmpList);
|
||||
}
|
||||
default:
|
||||
throw torrent::input_error("Not a list.");
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandPeerSlot::call_value_base(Command* rawCommand, torrent::Peer* peer, const torrent::Object& rawArgs, int base, int unit) {
|
||||
CommandPeerSlot* command = static_cast<CommandPeerSlot*>(rawCommand);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
// Should shift this one too, so it gives the right unit.
|
||||
return command->m_slot(peer, arg);
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
{
|
||||
torrent::Object argValue(torrent::Object::TYPE_VALUE);
|
||||
|
||||
if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit))
|
||||
throw torrent::input_error("Not a value.");
|
||||
|
||||
return command->m_slot(peer, argValue);
|
||||
}
|
||||
default:
|
||||
throw torrent::input_error("Not a value.");
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandPeerSlot::call_string(Command* rawCommand, torrent::Peer* peer, const torrent::Object& rawArgs) {
|
||||
CommandPeerSlot* command = static_cast<CommandPeerSlot*>(rawCommand);
|
||||
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_STRING:
|
||||
return command->m_slot(peer, arg);
|
||||
|
||||
// case torrent::Object::TYPE_NONE:
|
||||
// throw torrent::input_error("CDS: void.");
|
||||
|
||||
// case torrent::Object::TYPE_VALUE:
|
||||
// throw torrent::input_error("CDS: value.");
|
||||
|
||||
// case torrent::Object::TYPE_LIST:
|
||||
// throw torrent::input_error("CDS: list.");
|
||||
|
||||
default:
|
||||
throw torrent::input_error("Not a string.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2007, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_RPC_COMMAND_PEER_SLOT_H
|
||||
#define RTORRENT_RPC_COMMAND_PEER_SLOT_H
|
||||
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <torrent/object.h>
|
||||
#include <rak/functional_fun.h>
|
||||
|
||||
#include "command.h"
|
||||
|
||||
namespace torrent {
|
||||
class Peer;
|
||||
}
|
||||
|
||||
namespace rpc {
|
||||
|
||||
class CommandPeerSlot : public Command {
|
||||
public:
|
||||
typedef rak::function2<torrent::Object, torrent::Peer*, const torrent::Object&> slot_type;
|
||||
|
||||
CommandPeerSlot() {}
|
||||
|
||||
CommandPeerSlot(slot_type::base_type* s) {
|
||||
m_slot.set(s);
|
||||
}
|
||||
|
||||
void set_slot(slot_type::base_type* s) { m_slot.set(s); }
|
||||
|
||||
static const torrent::Object call_unknown(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args);
|
||||
|
||||
static const torrent::Object call_list(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args);
|
||||
static const torrent::Object call_string(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args);
|
||||
|
||||
static const torrent::Object call_value_base(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args, int base, int unit);
|
||||
|
||||
static const torrent::Object call_value(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args) { return call_value_base(rawCommand, peer, args, 0, 1); }
|
||||
static const torrent::Object call_value_kb(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args) { return call_value_base(rawCommand, peer, args, 0, 1 << 10); }
|
||||
|
||||
template <int base, int unit>
|
||||
static const torrent::Object call_value(Command* rawCommand, torrent::Peer* peer, const torrent::Object& args) { return call_value_base(rawCommand, peer, args, base, unit); }
|
||||
|
||||
// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args);
|
||||
|
||||
private:
|
||||
slot_type m_slot;
|
||||
};
|
||||
|
||||
// Some slots that convert torrent::Object arguments to proper
|
||||
// function calls.
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_void_p_fn_t : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
|
||||
public:
|
||||
object_void_p_fn_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) { return torrent::Object(m_func(peer)); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_void_p_fn_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
|
||||
public:
|
||||
object_void_p_fn_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) {
|
||||
m_func(peer);
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_value_p_fn1_t : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
|
||||
public:
|
||||
object_value_p_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) {
|
||||
return torrent::Object((int64_t)m_func(peer, arg1.as_value()));
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_value_p_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
|
||||
public:
|
||||
object_value_p_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) {
|
||||
m_func(peer, arg1.as_value());
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func, typename Result = typename Func::result_type>
|
||||
class object_string_p_fn1_t : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
|
||||
public:
|
||||
object_string_p_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) { return torrent::Object(m_func(peer, arg1.as_string())); }
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
class object_string_p_fn1_t<Func, void> : public rak::function_base2<torrent::Object, torrent::Peer*, const torrent::Object&> {
|
||||
public:
|
||||
object_string_p_fn1_t(Func func) : m_func(func) {}
|
||||
|
||||
virtual torrent::Object operator () (torrent::Peer* peer, const torrent::Object& arg1) {
|
||||
m_func(peer, arg1.as_string());
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
private:
|
||||
Func m_func;
|
||||
};
|
||||
|
||||
template <typename Return> object_void_p_fn_t<Return (*)(torrent::Peer*), Return>*
|
||||
object_p_fn(Return (*func)(torrent::Peer*)) {
|
||||
return new object_void_p_fn_t<Return (*)(torrent::Peer*), Return>(func);
|
||||
}
|
||||
|
||||
template <typename Func> object_void_p_fn_t<Func>* object_void_p_fn(Func func) { return new object_void_p_fn_t<Func>(func); }
|
||||
template <typename Func> object_value_p_fn1_t<Func>* object_value_p_fn(Func func) { return new object_value_p_fn1_t<Func>(func); }
|
||||
template <typename Func> object_string_p_fn1_t<Func>* object_string_p_fn(Func func) { return new object_string_p_fn1_t<Func>(func); }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -105,9 +105,6 @@ inline void call_command_d_set_value(const char* key, core::Download*
|
||||
inline void call_command_d_set_string(const char* key, core::Download* download, const std::string& arg) { commands.call_command_d(key, download, torrent::Object(arg)); }
|
||||
inline void call_command_d_set_std_string(const std::string& key, core::Download* download, const std::string& arg) { commands.call_command_d(key.c_str(), download, torrent::Object(arg)); }
|
||||
|
||||
inline torrent::Object call_command_f(const char* key, torrent::File* file, const torrent::Object& obj) { return commands.call_command_f(key, file, obj); }
|
||||
inline torrent::Object call_command_t(const char* key, torrent::Tracker* tracker, const torrent::Object& obj) { return commands.call_command_t(key, tracker, obj); }
|
||||
|
||||
inline torrent::Object
|
||||
call_command_d_range(const char* key, core::Download* download, torrent::Object::list_type::const_iterator first, torrent::Object::list_type::const_iterator last) {
|
||||
// Change to using range ctor.
|
||||
|
||||
+2
-2
@@ -397,7 +397,7 @@ xmlrpc_call_command_f(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo)
|
||||
return NULL;
|
||||
|
||||
try {
|
||||
return object_to_xmlrpc(env, rpc::call_command_f((const char*)voidServerInfo, file, object));
|
||||
return object_to_xmlrpc(env, rpc::commands.call_command_f((const char*)voidServerInfo, file, object));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
xmlrpc_env_set_fault(env, XMLRPC_PARSE_ERROR, e.what());
|
||||
@@ -414,7 +414,7 @@ xmlrpc_call_command_t(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo)
|
||||
return NULL;
|
||||
|
||||
try {
|
||||
return object_to_xmlrpc(env, rpc::call_command_t((const char*)voidServerInfo, tracker, object));
|
||||
return object_to_xmlrpc(env, rpc::commands.call_command_t((const char*)voidServerInfo, tracker, object));
|
||||
|
||||
} catch (torrent::local_error& e) {
|
||||
xmlrpc_env_set_fault(env, XMLRPC_PARSE_ERROR, e.what());
|
||||
|
||||
Reference in New Issue
Block a user