mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-06 06:09:22 +00:00
* Added 'f.multicall' and 't.multicall', and renamed 'call_download'
to 'd.multicall'. * Cleanup of 'rpc/parse_commands.h'. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@961 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -60,6 +60,7 @@ CommandDownloadSlot::call_list(Command* rawCommand, core::Download* download, co
|
||||
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
case torrent::Object::TYPE_STRING:
|
||||
// case torrent::Object::TYPE_NONE:
|
||||
{
|
||||
torrent::Object tmpList(torrent::Object::TYPE_LIST);
|
||||
tmpList.as_list().push_back(rawArgs);
|
||||
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
|
||||
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 (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)); }
|
||||
|
||||
@@ -59,6 +59,7 @@ CommandSlot::call_list(Command* rawCommand, const torrent::Object& rawArgs) {
|
||||
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
case torrent::Object::TYPE_STRING:
|
||||
case torrent::Object::TYPE_NONE:
|
||||
{
|
||||
torrent::Object tmpList(torrent::Object::TYPE_LIST);
|
||||
tmpList.as_list().push_back(rawArgs);
|
||||
|
||||
+10
-20
@@ -82,22 +82,22 @@ parse_count_escaped(const char* first, const char* last) {
|
||||
//
|
||||
// Find a better name.
|
||||
void
|
||||
parse_command_execute(core::Download* download, torrent::Object* object) {
|
||||
parse_command_execute(CommandMap::target_type target, torrent::Object* object) {
|
||||
if (object->is_list()) {
|
||||
for (torrent::Object::list_type::iterator itr = object->as_list().begin(), last = object->as_list().end(); itr != last; itr++)
|
||||
parse_command_execute(download, &*itr);
|
||||
parse_command_execute(target, &*itr);
|
||||
|
||||
} else if (*object->as_string().c_str() == '$') {
|
||||
const std::string& str = object->as_string();
|
||||
|
||||
*object = parse_command_d_single(download, str.c_str() + 1, str.c_str() + str.size());
|
||||
*object = parse_command(target, str.c_str() + 1, str.c_str() + str.size()).first;
|
||||
}
|
||||
}
|
||||
|
||||
// Set 'download' to NULL to call the generic functions, thus reusing
|
||||
// the code below for both cases.
|
||||
std::pair<torrent::Object, const char*>
|
||||
parse_command(core::Download* download, const char* first, const char* last) {
|
||||
parse_command_type
|
||||
parse_command(CommandMap::target_type target, const char* first, const char* last) {
|
||||
first = std::find_if(first, last, std::not1(command_map_is_space()));
|
||||
|
||||
if (first == last || *first == '#')
|
||||
@@ -127,32 +127,22 @@ parse_command(core::Download* download, const char* first, const char* last) {
|
||||
|
||||
// Replace any strings starting with '$' with the result of the
|
||||
// following command.
|
||||
parse_command_execute(download, &args);
|
||||
parse_command_execute(target, &args);
|
||||
|
||||
return std::make_pair(commands.call_command_d(key.c_str(), download, args), first);
|
||||
return std::make_pair(commands.call_command(key.c_str(), args, target), first);
|
||||
}
|
||||
|
||||
void
|
||||
parse_command_single(const char* first) {
|
||||
parse_command(NULL, first, first + std::strlen(first));
|
||||
}
|
||||
|
||||
void
|
||||
parse_command_multiple(core::Download* download, const char* first, const char* last) {
|
||||
parse_command_multiple(CommandMap::target_type target, const char* first, const char* last) {
|
||||
while (first != last) {
|
||||
// Should we check the return value? Probably not necessary as
|
||||
// parse_args throws on unquoted multi-word input.
|
||||
std::pair<torrent::Object, const char*> result = parse_command(download, first, last);
|
||||
parse_command_type result = parse_command(target, first, last);
|
||||
|
||||
first = result.second;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
parse_command_d_multiple(core::Download* download, const char* first) {
|
||||
parse_command_multiple(download, first, first + std::strlen(first));
|
||||
}
|
||||
|
||||
bool
|
||||
parse_command_file(const std::string& path) {
|
||||
std::fstream file(rak::path_expand(path).c_str(), std::ios::in);
|
||||
@@ -185,7 +175,7 @@ parse_command_file(const std::string& path) {
|
||||
}
|
||||
|
||||
// Would be nice to make this zero-copy.
|
||||
parse_command(NULL, buffer, buffer + getCount);
|
||||
parse_command(make_target(), buffer, buffer + getCount);
|
||||
getCount = 0;
|
||||
}
|
||||
|
||||
|
||||
+21
-13
@@ -38,6 +38,7 @@
|
||||
#define RTORRENT_RPC_PARSE_COMMANDS_H
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
#include "command_map.h"
|
||||
#include "exec_file.h"
|
||||
@@ -54,36 +55,43 @@ extern CommandMap commands;
|
||||
extern XmlRpc xmlrpc;
|
||||
extern ExecFile execFile;
|
||||
|
||||
inline CommandMap::target_type make_target() { return CommandMap::target_type((int)CommandMap::target_generic, NULL); }
|
||||
inline CommandMap::target_type make_target(core::Download* target) { return CommandMap::target_type((int)CommandMap::target_download, target); }
|
||||
inline CommandMap::target_type make_target(torrent::File* target) { return CommandMap::target_type((int)CommandMap::target_file, target); }
|
||||
inline CommandMap::target_type make_target(torrent::Peer* target) { return CommandMap::target_type((int)CommandMap::target_peer, target); }
|
||||
inline CommandMap::target_type make_target(torrent::Tracker* target) { return CommandMap::target_type((int)CommandMap::target_tracker, target); }
|
||||
|
||||
typedef std::pair<torrent::Object, const char*> parse_command_type;
|
||||
|
||||
// The generic parse command function, used by the rest. At some point
|
||||
// the 'download' parameter should be replaced by a more generic one.
|
||||
std::pair<torrent::Object, const char*> parse_command(core::Download* download, const char* first, const char* last);
|
||||
parse_command_type parse_command(CommandMap::target_type target, const char* first, const char* last);
|
||||
void parse_command_multiple(CommandMap::target_type target, const char* first, const char* last);
|
||||
|
||||
void parse_command_single(const char* first);
|
||||
inline torrent::Object parse_command_single(const char* first, const char* last) { return parse_command(NULL, first, last).first; }
|
||||
inline torrent::Object parse_command_d_single(core::Download* download, const char* first, const char* last) { return parse_command(download, first, last).first; }
|
||||
|
||||
void parse_command_multiple(core::Download* download, const char* first, const char* last);
|
||||
|
||||
void parse_command_d_multiple(core::Download* download, const char* first);
|
||||
inline void parse_command_d_multiple_std(core::Download* download, const std::string& cmd) { parse_command_multiple(download, cmd.c_str(), cmd.c_str() + cmd.size()); }
|
||||
inline void parse_command_multiple(const char* first) { parse_command_d_multiple(NULL, first); }
|
||||
inline void parse_command_single(CommandMap::target_type target, const char* first) { parse_command(target, first, first + std::strlen(first)); }
|
||||
inline void parse_command_multiple(CommandMap::target_type target, const char* first) { parse_command_multiple(target, first, first + std::strlen(first)); }
|
||||
|
||||
bool parse_command_file(const std::string& path);
|
||||
const char* parse_command_name(const char* first, const char* last, std::string* dest);
|
||||
|
||||
inline void
|
||||
parse_command_single_std(const std::string& cmd) {
|
||||
parse_command_single(cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
parse_command(make_target(), cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
}
|
||||
|
||||
inline void
|
||||
parse_command_d_single_std(core::Download* download, const std::string& cmd) {
|
||||
parse_command_d_single(download, cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
parse_command(make_target(download), cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
}
|
||||
|
||||
inline void
|
||||
parse_command_multiple_std(const std::string& cmd) {
|
||||
parse_command_multiple(NULL, cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
parse_command_multiple(make_target(), cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
}
|
||||
|
||||
inline void
|
||||
parse_command_d_multiple_std(core::Download* download, const std::string& cmd) {
|
||||
parse_command_multiple(make_target(download), cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
}
|
||||
|
||||
inline torrent::Object call_command(const char* key, const torrent::Object& obj) { return commands.call_command(key, obj); }
|
||||
|
||||
+1
-1
@@ -275,7 +275,7 @@ xmlrpc_to_object_target(xmlrpc_env* env, xmlrpc_value* value, int callType, void
|
||||
|
||||
torrent::Object result;
|
||||
|
||||
if (current + 1 > last) {
|
||||
if (current + 1 < last) {
|
||||
result = torrent::Object(torrent::Object::TYPE_LIST);
|
||||
torrent::Object::list_type& listRef = result.as_list();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user