mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-07 14:49:21 +00:00
* Last of the commands converted, cleanup remaining.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1154 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+13
-3
@@ -38,6 +38,7 @@
|
||||
#define RTORRENT_RPC_VARIABLE_H
|
||||
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/data/file_list_iterator.h>
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
@@ -132,6 +133,9 @@ public:
|
||||
|
||||
static torrent::Object* argument(unsigned int index) { return m_arguments + index; }
|
||||
|
||||
static const unsigned int max_arguments = 10;
|
||||
static torrent::Object m_arguments[max_arguments];
|
||||
|
||||
protected:
|
||||
Command(const Command&);
|
||||
void operator = (const Command&);
|
||||
@@ -139,9 +143,6 @@ protected:
|
||||
// For use by functions that need to use placeholders to arguments
|
||||
// within commands. E.d. callable command strings where one of the
|
||||
// arguments within the command needs to be supplied by the caller.
|
||||
static const unsigned int max_arguments = 10;
|
||||
|
||||
static torrent::Object m_arguments[max_arguments];
|
||||
};
|
||||
|
||||
template <typename T1 = void, typename T2 = void>
|
||||
@@ -175,6 +176,8 @@ is_target_compatible(const target_type& target) { return target.first == target_
|
||||
|
||||
template <> inline bool
|
||||
is_target_compatible<target_type>(const target_type& target) { return true; }
|
||||
template <> inline bool
|
||||
is_target_compatible<torrent::File*>(const target_type& target) { return target.first == Command::target_file || Command::target_file_itr; }
|
||||
|
||||
// Splitting pairs into separate targets.
|
||||
inline bool is_target_pair(const target_type& target) { return target.first >= Command::target_download_pair; }
|
||||
@@ -184,6 +187,13 @@ get_target_cast(target_type target, int type = target_type_id<T>::value) { retur
|
||||
template <> inline target_type
|
||||
get_target_cast<target_type>(target_type target, int type) { return target; }
|
||||
|
||||
template <> inline torrent::File*
|
||||
get_target_cast<torrent::File*>(target_type target, int type) {
|
||||
if (target.first == Command::target_file_itr)
|
||||
return static_cast<torrent::FileListIterator*>(target.second)->file();
|
||||
else
|
||||
return static_cast<torrent::File*>(target.second);
|
||||
}
|
||||
|
||||
inline target_type get_target_left(const target_type& target) { return target_type(target.first - 5, target.second); }
|
||||
inline target_type get_target_right(const target_type& target) { return target_type(target.first - 5, target.third); }
|
||||
|
||||
@@ -46,6 +46,47 @@
|
||||
|
||||
namespace rpc {
|
||||
|
||||
// Temp until it can be moved somewhere better...
|
||||
const torrent::Object
|
||||
command_function_call(const torrent::raw_string& cmd, target_type target, const torrent::Object& args) {
|
||||
char* buffer[sizeof(torrent::Object) * Command::max_arguments];
|
||||
torrent::Object* stack = (torrent::Object*)buffer;
|
||||
torrent::Object* first = (torrent::Object*)buffer;
|
||||
|
||||
if (args.is_list()) {
|
||||
// Do nothing for now.
|
||||
for (torrent::Object::list_const_iterator itr = args.as_list().begin(), last = args.as_list().end();
|
||||
itr != last && first != stack + Command::max_arguments;
|
||||
itr++, first++) {
|
||||
new (first) torrent::Object(*itr);
|
||||
first->swap(*Command::argument(std::distance(stack, first)));
|
||||
}
|
||||
|
||||
} else if (args.type() != torrent::Object::TYPE_NONE) {
|
||||
new (first) torrent::Object(args);
|
||||
(first++)->swap(*Command::argument(0));
|
||||
}
|
||||
|
||||
try {
|
||||
torrent::Object result = parse_command_multiple(target, cmd.begin(), cmd.end());
|
||||
|
||||
while (first-- != stack) {
|
||||
first->swap(*Command::argument(std::distance(stack, first)));
|
||||
first->~Object();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
while (first-- != stack) {
|
||||
first->swap(*Command::argument(std::distance(stack, first)));
|
||||
first->~Object();
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandFunction::call(Command* rawCommand, target_type target, const torrent::Object& args) {
|
||||
char* buffer[sizeof(torrent::Object) * Command::max_arguments];
|
||||
@@ -68,14 +109,24 @@ CommandFunction::call(Command* rawCommand, target_type target, const torrent::Ob
|
||||
|
||||
CommandFunction* command = reinterpret_cast<CommandFunction*>(rawCommand);
|
||||
|
||||
torrent::Object result = parse_command_multiple(target, command->m_command.c_str(), command->m_command.c_str() + command->m_command.size());
|
||||
try {
|
||||
torrent::Object result = parse_command_multiple(target, command->m_command.c_str(), command->m_command.c_str() + command->m_command.size());
|
||||
|
||||
while (first-- != stack) {
|
||||
first->swap(*argument(std::distance(stack, first)));
|
||||
first->~Object();
|
||||
while (first-- != stack) {
|
||||
first->swap(*argument(std::distance(stack, first)));
|
||||
first->~Object();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
while (first-- != stack) {
|
||||
first->swap(*Command::argument(std::distance(stack, first)));
|
||||
first->~Object();
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
@@ -107,8 +158,18 @@ CommandFunctionList::call(Command* rawCommand, target_type target, const torrent
|
||||
|
||||
CommandFunctionList* command = reinterpret_cast<CommandFunctionList*>(rawCommand);
|
||||
|
||||
for (base_type::const_iterator itr = command->begin(), last = command->end(); itr != last; itr++)
|
||||
parse_command_multiple(target, itr->second.c_str(), itr->second.c_str() + itr->second.size());
|
||||
try {
|
||||
for (base_type::const_iterator itr = command->begin(), last = command->end(); itr != last; itr++)
|
||||
parse_command_multiple(target, itr->second.c_str(), itr->second.c_str() + itr->second.size());
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
while (first-- != stack) {
|
||||
first->swap(*Command::argument(std::distance(stack, first)));
|
||||
first->~Object();
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
|
||||
while (first-- != stack) {
|
||||
first->swap(*argument(std::distance(stack, first)));
|
||||
|
||||
@@ -83,6 +83,10 @@ public:
|
||||
static const torrent::Object call(Command* rawCommand, target_type target, const torrent::Object& args);
|
||||
};
|
||||
|
||||
// Temp until it can be moved somewhere better...
|
||||
const torrent::Object
|
||||
command_function_call(const torrent::raw_string& cmd, target_type target, const torrent::Object& args);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user