* 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:
rakshasa
2010-03-27 16:35:15 +00:00
parent bc96dbfa2d
commit 10f665e9c6
24 changed files with 640 additions and 455 deletions
+69 -8
View File
@@ -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)));