mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-08 15:19:20 +00:00
* Renamed VariableMap to CommandMap.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@913 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -175,7 +175,7 @@ apply_d_delete_link(core::Download* download, const torrent::Object& rawArgs) {
|
||||
|
||||
#define ADD_COMMAND_DOWNLOAD_SLOT(key, function, slot, parm, doc) \
|
||||
commandDownloadSlotsItr->set_slot(slot); \
|
||||
variables->insert(key, commandDownloadSlotsItr++, NULL, &utils::CommandDownloadSlot::function, utils::VariableMap::flag_dont_delete | utils::VariableMap::flag_public_xmlrpc, parm, doc);
|
||||
variables->insert(key, commandDownloadSlotsItr++, NULL, &utils::CommandDownloadSlot::function, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, parm, doc);
|
||||
|
||||
#define ADD_COMMAND_DOWNLOAD_VOID(key, slot) \
|
||||
ADD_COMMAND_DOWNLOAD_SLOT(key, call_unknown, utils::object_d_fn(slot), "i:", "")
|
||||
@@ -207,7 +207,7 @@ apply_d_delete_link(core::Download* download, const torrent::Object& rawArgs) {
|
||||
|
||||
void
|
||||
add_copy_to_download(const char* key) {
|
||||
utils::VariableMap::iterator itr = control->variable()->find(key);
|
||||
utils::CommandMap::iterator itr = control->variable()->find(key);
|
||||
|
||||
if (itr == control->variable()->end())
|
||||
throw torrent::internal_error("add_copy_to_download(...) key not found.");
|
||||
@@ -217,7 +217,7 @@ add_copy_to_download(const char* key) {
|
||||
|
||||
void
|
||||
initialize_command_download() {
|
||||
utils::VariableMap* variables = control->download_variables();
|
||||
utils::CommandMap* variables = control->download_variables();
|
||||
|
||||
ADD_COMMAND_DOWNLOAD_VOID("base_path", &retrieve_d_base_path);
|
||||
ADD_COMMAND_DOWNLOAD_VOID("base_filename", &retrieve_d_base_filename);
|
||||
|
||||
@@ -216,7 +216,7 @@ apply_close_low_diskspace(int64_t arg) {
|
||||
|
||||
void
|
||||
initialize_command_events() {
|
||||
utils::VariableMap* variables = control->variable();
|
||||
utils::CommandMap* variables = control->variable();
|
||||
core::DownloadList* downloadList = control->core()->download_list();
|
||||
|
||||
ADD_VARIABLE_BOOL("check_hash", true);
|
||||
|
||||
@@ -79,14 +79,14 @@ initialize_commands() {
|
||||
|
||||
void
|
||||
add_variable(const char* getKey, const char* setKey, const char* defaultSetKey,
|
||||
utils::VariableMap::generic_slot getSlot, utils::VariableMap::generic_slot setSlot,
|
||||
utils::CommandMap::generic_slot getSlot, utils::CommandMap::generic_slot setSlot,
|
||||
const torrent::Object& defaultObject) {
|
||||
utils::CommandVariable* variable = commandVariablesItr++;
|
||||
variable->set_variable(defaultObject);
|
||||
|
||||
control->variable()->insert(getKey, variable, getSlot, NULL, utils::VariableMap::flag_dont_delete | utils::VariableMap::flag_public_xmlrpc, "i:", "");
|
||||
control->variable()->insert(setKey, variable, setSlot, NULL, utils::VariableMap::flag_dont_delete | utils::VariableMap::flag_public_xmlrpc, "i:", "");
|
||||
control->variable()->insert(getKey, variable, getSlot, NULL, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, "i:", "");
|
||||
control->variable()->insert(setKey, variable, setSlot, NULL, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, "i:", "");
|
||||
|
||||
if (defaultSetKey)
|
||||
control->variable()->insert(defaultSetKey, variable, setSlot, NULL, utils::VariableMap::flag_dont_delete, "i:", "");
|
||||
control->variable()->insert(defaultSetKey, variable, setSlot, NULL, utils::CommandMap::flag_dont_delete, "i:", "");
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#ifndef RTORRENT_UTILS_COMMAND_HELPERS_H
|
||||
#define RTORRENT_UTILS_COMMAND_HELPERS_H
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
namespace utils {
|
||||
class CommandSlot;
|
||||
@@ -64,7 +64,7 @@ void initialize_commands();
|
||||
|
||||
void
|
||||
add_variable(const char* getKey, const char* setKey, const char* defaultSetKey,
|
||||
utils::VariableMap::generic_slot getSlot, utils::VariableMap::generic_slot setSlot,
|
||||
utils::CommandMap::generic_slot getSlot, utils::CommandMap::generic_slot setSlot,
|
||||
const torrent::Object& defaultObject);
|
||||
|
||||
#define ADD_VARIABLE_BOOL(key, defaultValue) \
|
||||
@@ -78,17 +78,17 @@ add_variable("get_" key, "set_" key, key, &utils::CommandVariable::get_string, &
|
||||
|
||||
#define ADD_COMMAND_SLOT(key, function, slot, parm, doc) \
|
||||
commandSlotsItr->set_slot(slot); \
|
||||
variables->insert(key, commandSlotsItr++, &utils::CommandSlot::function, NULL, utils::VariableMap::flag_dont_delete | utils::VariableMap::flag_public_xmlrpc, parm, doc);
|
||||
variables->insert(key, commandSlotsItr++, &utils::CommandSlot::function, NULL, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, parm, doc);
|
||||
|
||||
#define ADD_COMMAND_SLOT_PRIVATE(key, function, slot) \
|
||||
commandSlotsItr->set_slot(slot); \
|
||||
variables->insert(key, commandSlotsItr++, &utils::CommandSlot::function, NULL, utils::VariableMap::flag_dont_delete, NULL, NULL);
|
||||
variables->insert(key, commandSlotsItr++, &utils::CommandSlot::function, NULL, utils::CommandMap::flag_dont_delete, NULL, NULL);
|
||||
|
||||
#define ADD_COMMAND_COPY(key, function, parm, doc) \
|
||||
variables->insert(key, (commandSlotsItr - 1), &utils::CommandSlot::function, NULL, utils::VariableMap::flag_dont_delete | utils::VariableMap::flag_public_xmlrpc, parm, doc);
|
||||
variables->insert(key, (commandSlotsItr - 1), &utils::CommandSlot::function, NULL, utils::CommandMap::flag_dont_delete | utils::CommandMap::flag_public_xmlrpc, parm, doc);
|
||||
|
||||
#define ADD_COMMAND_COPY_PRIVATE(key, function) \
|
||||
variables->insert(key, (commandSlotsItr - 1), &utils::CommandSlot::function, NULL, utils::VariableMap::flag_dont_delete, NULL, NULL);
|
||||
variables->insert(key, (commandSlotsItr - 1), &utils::CommandSlot::function, NULL, utils::CommandMap::flag_dont_delete, NULL, NULL);
|
||||
|
||||
#define ADD_COMMAND_VALUE_TRI(key, set, get) \
|
||||
ADD_COMMAND_SLOT_PRIVATE(key, call_value, utils::object_value_fn(set)) \
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "core/manager.h"
|
||||
#include "rpc/command_slot.h"
|
||||
#include "rpc/command_variable.h"
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "control.h"
|
||||
@@ -56,7 +56,7 @@ typedef torrent::ChunkManager CM_t;
|
||||
|
||||
void
|
||||
initialize_command_local() {
|
||||
utils::VariableMap* variables = control->variable();
|
||||
utils::CommandMap* variables = control->variable();
|
||||
// core::DownloadList* downloadList = control->core()->download_list();
|
||||
torrent::ChunkManager* chunkManager = torrent::chunk_manager();
|
||||
core::DownloadList* dList = control->core()->download_list();
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
#include "rpc/command_slot.h"
|
||||
#include "rpc/command_variable.h"
|
||||
#include "rpc/parse.h"
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "control.h"
|
||||
@@ -146,12 +146,12 @@ apply_enable_trackers(int64_t arg) {
|
||||
void
|
||||
initialize_xmlrpc() {
|
||||
control->set_xmlrpc(new rpc::XmlRpc);
|
||||
control->xmlrpc()->set_slot_call_command(rak::mem_fn(control->variable(), &utils::VariableMap::call_command));
|
||||
control->xmlrpc()->set_slot_call_command(rak::mem_fn(control->variable(), &utils::CommandMap::call_command));
|
||||
|
||||
unsigned int count = 0;
|
||||
|
||||
for (utils::VariableMap::const_iterator itr = control->variable()->begin(), last = control->variable()->end(); itr != last; itr++)
|
||||
if (itr->second.m_flags & utils::VariableMap::flag_public_xmlrpc) {
|
||||
for (utils::CommandMap::const_iterator itr = control->variable()->begin(), last = control->variable()->end(); itr != last; itr++)
|
||||
if (itr->second.m_flags & utils::CommandMap::flag_public_xmlrpc) {
|
||||
control->xmlrpc()->insert_command(itr->first, itr->second.m_parm, itr->second.m_doc);
|
||||
|
||||
count++;
|
||||
@@ -238,7 +238,7 @@ apply_scgi(const std::string& arg, int type) {
|
||||
|
||||
void
|
||||
initialize_command_network() {
|
||||
utils::VariableMap* variables = control->variable();
|
||||
utils::CommandMap* variables = control->variable();
|
||||
// core::DownloadList* downloadList = control->core()->download_list();
|
||||
torrent::ConnectionManager* cm = torrent::connection_manager();
|
||||
core::CurlStack* httpStack = control->core()->get_poll_manager()->get_http_stack();
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ apply_view_sort(const torrent::Object& rawArgs) {
|
||||
|
||||
void
|
||||
initialize_command_ui() {
|
||||
utils::VariableMap* variables = control->variable();
|
||||
utils::CommandMap* variables = control->variable();
|
||||
// core::DownloadList* downloadList = control->core()->download_list();
|
||||
|
||||
ADD_VARIABLE_STRING("key_layout", "qwerty");
|
||||
|
||||
+3
-3
@@ -55,7 +55,7 @@
|
||||
#include "rpc/scgi.h"
|
||||
#include "rpc/xmlrpc.h"
|
||||
#include "ui/root.h"
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "command_scheduler.h"
|
||||
|
||||
@@ -71,8 +71,8 @@ Control::Control() :
|
||||
m_inputStdin(new input::InputEvent(STDIN_FILENO)),
|
||||
|
||||
m_commandScheduler(new CommandScheduler()),
|
||||
m_variables(new utils::VariableMap()),
|
||||
m_downloadVariables(new utils::VariableMap()),
|
||||
m_variables(new utils::CommandMap()),
|
||||
m_downloadVariables(new utils::CommandMap()),
|
||||
|
||||
m_fastCgi(NULL),
|
||||
m_scgi(NULL),
|
||||
|
||||
+5
-5
@@ -69,7 +69,7 @@ namespace rpc {
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
class VariableMap;
|
||||
class CommandMap;
|
||||
}
|
||||
|
||||
class CommandScheduler;
|
||||
@@ -104,8 +104,8 @@ public:
|
||||
|
||||
CommandScheduler* command_scheduler() { return m_commandScheduler; }
|
||||
|
||||
utils::VariableMap* variable() { return m_variables; }
|
||||
utils::VariableMap* download_variables() { return m_downloadVariables; }
|
||||
utils::CommandMap* variable() { return m_variables; }
|
||||
utils::CommandMap* download_variables() { return m_downloadVariables; }
|
||||
|
||||
rpc::FastCgi* fast_cgi() { return m_fastCgi; }
|
||||
void set_fast_cgi(rpc::FastCgi* f) { m_fastCgi = f; }
|
||||
@@ -142,8 +142,8 @@ private:
|
||||
input::InputEvent* m_inputStdin;
|
||||
|
||||
CommandScheduler* m_commandScheduler;
|
||||
utils::VariableMap* m_variables;
|
||||
utils::VariableMap* m_downloadVariables;
|
||||
utils::CommandMap* m_variables;
|
||||
utils::CommandMap* m_downloadVariables;
|
||||
|
||||
rpc::FastCgi* m_fastCgi;
|
||||
rpc::SCgi* m_scgi;
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#include <torrent/tracker_list.h>
|
||||
#include <torrent/data/file_list.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "control.h"
|
||||
#include "download.h"
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/data/file_utils.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "curl_get.h"
|
||||
#include "control.h"
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "control.h"
|
||||
#include "globals.h"
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@
|
||||
#include <torrent/resume.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "curl_get.h"
|
||||
|
||||
+7
-7
@@ -60,7 +60,7 @@
|
||||
|
||||
#include "rpc/parse_commands.h"
|
||||
#include "utils/directory.h"
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "control.h"
|
||||
#include "globals.h"
|
||||
@@ -82,14 +82,14 @@ parse_options(Control* c, int argc, char** argv) {
|
||||
optionParser.insert_flag('h', sigc::ptr_fun(&print_help));
|
||||
optionParser.insert_flag('n', OptionParser::Slot());
|
||||
|
||||
optionParser.insert_option('b', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "bind"));
|
||||
optionParser.insert_option('d', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "directory"));
|
||||
optionParser.insert_option('i', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "ip"));
|
||||
optionParser.insert_option('p', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "port_range"));
|
||||
optionParser.insert_option('s', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "session"));
|
||||
optionParser.insert_option('b', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "bind"));
|
||||
optionParser.insert_option('d', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "directory"));
|
||||
optionParser.insert_option('i', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "ip"));
|
||||
optionParser.insert_option('p', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "port_range"));
|
||||
optionParser.insert_option('s', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_string), "session"));
|
||||
|
||||
optionParser.insert_option('O', sigc::bind<0>(&utils::parse_command_single_std, c->variable()));
|
||||
optionParser.insert_option_list('o', sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_std_string));
|
||||
optionParser.insert_option_list('o', sigc::mem_fun(c->variable(), &utils::CommandMap::call_command_set_std_string));
|
||||
|
||||
return optionParser.process(argc, argv);
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ noinst_LIBRARIES = libsub_rpc.a
|
||||
|
||||
libsub_rpc_a_SOURCES = \
|
||||
command.h \
|
||||
command_map.cc \
|
||||
command_map.h \
|
||||
command_slot.cc \
|
||||
command_slot.h \
|
||||
command_variable.cc \
|
||||
|
||||
@@ -45,45 +45,45 @@
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "rpc/command.h"
|
||||
#include "variable_map.h"
|
||||
#include "command.h"
|
||||
#include "command_map.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
struct variable_map_get_ptr : std::unary_function<VariableMap::value_type&, Command*> {
|
||||
Command* operator () (VariableMap::value_type& value) { return value.second.m_variable; }
|
||||
struct command_map_get_ptr : std::unary_function<CommandMap::value_type&, Command*> {
|
||||
Command* operator () (CommandMap::value_type& value) { return value.second.m_variable; }
|
||||
};
|
||||
|
||||
VariableMap::~VariableMap() {
|
||||
CommandMap::~CommandMap() {
|
||||
for (iterator itr = base_type::begin(), last = base_type::end(); itr != last; itr++)
|
||||
if (!(itr->second.m_flags & flag_dont_delete))
|
||||
delete itr->second.m_variable;
|
||||
}
|
||||
|
||||
void
|
||||
VariableMap::insert(key_type key, Command* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
CommandMap::insert(key_type key, Command* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
const char* parm, const char* doc) {
|
||||
iterator itr = base_type::find(key);
|
||||
|
||||
if (itr != base_type::end())
|
||||
throw torrent::internal_error("VariableMap::insert(...) tried to insert an already existing key.");
|
||||
throw torrent::internal_error("CommandMap::insert(...) tried to insert an already existing key.");
|
||||
|
||||
base_type::insert(itr, value_type(key, variable_map_data_type(variable, genericSlot, downloadSlot, flags, parm, doc)));
|
||||
base_type::insert(itr, value_type(key, command_map_data_type(variable, genericSlot, downloadSlot, flags, parm, doc)));
|
||||
}
|
||||
|
||||
void
|
||||
VariableMap::insert(key_type key, const variable_map_data_type src) {
|
||||
CommandMap::insert(key_type key, const command_map_data_type src) {
|
||||
iterator itr = base_type::find(key);
|
||||
|
||||
if (itr != base_type::end())
|
||||
throw torrent::internal_error("VariableMap::insert(...) tried to insert an already existing key.");
|
||||
throw torrent::internal_error("CommandMap::insert(...) tried to insert an already existing key.");
|
||||
|
||||
base_type::insert(itr, value_type(key, variable_map_data_type(src.m_variable, src.m_genericSlot, src.m_downloadSlot,
|
||||
base_type::insert(itr, value_type(key, command_map_data_type(src.m_variable, src.m_genericSlot, src.m_downloadSlot,
|
||||
src.m_flags | flag_dont_delete, src.m_parm, src.m_doc)));
|
||||
}
|
||||
|
||||
const VariableMap::mapped_type
|
||||
VariableMap::call_command(key_type key, const mapped_type& arg) {
|
||||
const CommandMap::mapped_type
|
||||
CommandMap::call_command(key_type key, const mapped_type& arg) {
|
||||
const_iterator itr = base_type::find(key);
|
||||
|
||||
if (itr == base_type::end())
|
||||
@@ -95,8 +95,8 @@ VariableMap::call_command(key_type key, const mapped_type& arg) {
|
||||
return itr->second.m_genericSlot(itr->second.m_variable, arg);
|
||||
}
|
||||
|
||||
const VariableMap::mapped_type
|
||||
VariableMap::call_command_d(key_type key, core::Download* download, const mapped_type& arg) {
|
||||
const CommandMap::mapped_type
|
||||
CommandMap::call_command_d(key_type key, core::Download* download, const mapped_type& arg) {
|
||||
const_iterator itr = base_type::find(key);
|
||||
|
||||
if (itr == base_type::end())
|
||||
@@ -34,39 +34,34 @@
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_UTILS_VARIABLE_MAP_H
|
||||
#define RTORRENT_UTILS_VARIABLE_MAP_H
|
||||
#ifndef RTORRENT_UTILS_COMMAND_MAP_H
|
||||
#define RTORRENT_UTILS_COMMAND_MAP_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <iosfwd>
|
||||
#include <torrent/object.h>
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
}
|
||||
|
||||
namespace torrent {
|
||||
class Object;
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
|
||||
struct variable_map_comp : public std::binary_function<const char*, const char*, bool> {
|
||||
bool operator () (const char* arg1, const char* arg2) const { return std::strcmp(arg1, arg2) < 0; }
|
||||
};
|
||||
|
||||
class Command;
|
||||
|
||||
struct variable_map_data_type {
|
||||
struct command_map_comp : public std::binary_function<const char*, const char*, bool> {
|
||||
bool operator () (const char* arg1, const char* arg2) const { return std::strcmp(arg1, arg2) < 0; }
|
||||
};
|
||||
|
||||
struct command_map_data_type {
|
||||
// Some commands will need to share data, like get/set a variable. So
|
||||
// instead of using a single virtual member function, each command
|
||||
// will register a member function pointer to be used instead.
|
||||
typedef const torrent::Object (*generic_slot)(Command*, const torrent::Object&);
|
||||
typedef const torrent::Object (*download_slot)(Command*, core::Download*, const torrent::Object&);
|
||||
|
||||
variable_map_data_type(Command* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
command_map_data_type(Command* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
const char* parm, const char* doc) :
|
||||
m_variable(variable), m_genericSlot(genericSlot), m_downloadSlot(downloadSlot), m_flags(flags), m_parm(parm), m_doc(doc) {}
|
||||
|
||||
@@ -80,12 +75,12 @@ struct variable_map_data_type {
|
||||
const char* m_doc;
|
||||
};
|
||||
|
||||
class VariableMap : public std::map<const char*, variable_map_data_type, variable_map_comp> {
|
||||
class CommandMap : public std::map<const char*, command_map_data_type, command_map_comp> {
|
||||
public:
|
||||
typedef std::map<const char*, variable_map_data_type, variable_map_comp> base_type;
|
||||
typedef std::map<const char*, command_map_data_type, command_map_comp> base_type;
|
||||
|
||||
typedef variable_map_data_type::generic_slot generic_slot;
|
||||
typedef variable_map_data_type::download_slot download_slot;
|
||||
typedef command_map_data_type::generic_slot generic_slot;
|
||||
typedef command_map_data_type::download_slot download_slot;
|
||||
|
||||
typedef torrent::Object mapped_type;
|
||||
typedef mapped_type::value_type mapped_value_type;
|
||||
@@ -105,8 +100,8 @@ public:
|
||||
static const int flag_dont_delete = 0x1;
|
||||
static const int flag_public_xmlrpc = 0x2;
|
||||
|
||||
VariableMap() {}
|
||||
~VariableMap();
|
||||
CommandMap() {}
|
||||
~CommandMap();
|
||||
|
||||
bool has(const char* key) const { return base_type::find(key) != base_type::end(); }
|
||||
bool has(const std::string& key) const { return has(key.c_str()); }
|
||||
@@ -114,7 +109,7 @@ public:
|
||||
void insert(key_type key, Command* variable, generic_slot genericSlot, download_slot downloadSlot, int flags,
|
||||
const char* parm, const char* doc);
|
||||
|
||||
void insert(key_type key, const variable_map_data_type src);
|
||||
void insert(key_type key, const command_map_data_type src);
|
||||
|
||||
const mapped_type call_command(key_type key, const mapped_type& arg);
|
||||
const mapped_type call_command_void(key_type key) { return call_command(key, torrent::Object()); }
|
||||
@@ -134,8 +129,8 @@ public:
|
||||
void call_command_d_set_std_string(const std::string& key, core::Download* download, const std::string& arg) { call_command_d(key.c_str(), download, mapped_type(arg)); }
|
||||
|
||||
private:
|
||||
VariableMap(const VariableMap&);
|
||||
void operator = (const VariableMap&);
|
||||
CommandMap(const CommandMap&);
|
||||
void operator = (const CommandMap&);
|
||||
};
|
||||
|
||||
}
|
||||
+12
-12
@@ -45,17 +45,17 @@
|
||||
|
||||
#include "parse.h"
|
||||
#include "parse_commands.h"
|
||||
#include "utils/variable_map.h"
|
||||
#include "command_map.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
struct variable_map_is_space : std::unary_function<char, bool> {
|
||||
struct command_map_is_space : std::unary_function<char, bool> {
|
||||
bool operator () (char c) const {
|
||||
return std::isspace(c);
|
||||
}
|
||||
};
|
||||
|
||||
struct variable_map_is_newline : std::unary_function<char, bool> {
|
||||
struct command_map_is_newline : std::unary_function<char, bool> {
|
||||
bool operator () (char c) const {
|
||||
return c == '\n' || c == '\0';
|
||||
}
|
||||
@@ -74,13 +74,13 @@ parse_command_name(const char* first, const char* last, std::string* dest) {
|
||||
}
|
||||
|
||||
const char*
|
||||
parse_command_single(VariableMap* varMap, const char* first) {
|
||||
parse_command_single(CommandMap* varMap, const char* first) {
|
||||
return parse_command_single(varMap, first, first + std::strlen(first));
|
||||
}
|
||||
|
||||
const char*
|
||||
parse_command_single(VariableMap* varMap, const char* first, const char* last) {
|
||||
first = std::find_if(first, last, std::not1(variable_map_is_space()));
|
||||
parse_command_single(CommandMap* varMap, const char* first, const char* last) {
|
||||
first = std::find_if(first, last, std::not1(command_map_is_space()));
|
||||
|
||||
if (first == last || *first == '#')
|
||||
return last;
|
||||
@@ -88,7 +88,7 @@ parse_command_single(VariableMap* varMap, const char* first, const char* last) {
|
||||
// Avoid using a string here?
|
||||
std::string key;
|
||||
first = parse_command_name(first, last, &key);
|
||||
first = std::find_if(first, last, std::not1(variable_map_is_space()));
|
||||
first = std::find_if(first, last, std::not1(command_map_is_space()));
|
||||
|
||||
if (first == last || *first != '=')
|
||||
throw torrent::input_error("Could not find '='.");
|
||||
@@ -102,15 +102,15 @@ parse_command_single(VariableMap* varMap, const char* first, const char* last) {
|
||||
}
|
||||
|
||||
const char*
|
||||
parse_command_d_single(VariableMap* varMap, core::Download* download, const char* first, const char* last) {
|
||||
first = std::find_if(first, last, std::not1(variable_map_is_space()));
|
||||
parse_command_d_single(CommandMap* varMap, core::Download* download, const char* first, const char* last) {
|
||||
first = std::find_if(first, last, std::not1(command_map_is_space()));
|
||||
|
||||
if (first == last || *first == '#')
|
||||
return last;
|
||||
|
||||
std::string key;
|
||||
first = parse_command_name(first, last, &key);
|
||||
first = std::find_if(first, last, std::not1(variable_map_is_space()));
|
||||
first = std::find_if(first, last, std::not1(command_map_is_space()));
|
||||
|
||||
if (first == last || *first != '=')
|
||||
throw torrent::input_error("Could not find '='.");
|
||||
@@ -124,7 +124,7 @@ parse_command_d_single(VariableMap* varMap, core::Download* download, const char
|
||||
}
|
||||
|
||||
void
|
||||
parse_command_multiple(VariableMap* varMap, const char* first) {
|
||||
parse_command_multiple(CommandMap* varMap, const char* first) {
|
||||
try {
|
||||
while (first != '\0') {
|
||||
const char* last = first;
|
||||
@@ -147,7 +147,7 @@ parse_command_multiple(VariableMap* varMap, const char* first) {
|
||||
}
|
||||
|
||||
bool
|
||||
parse_command_file(VariableMap* varMap, const std::string& path) {
|
||||
parse_command_file(CommandMap* varMap, const std::string& path) {
|
||||
std::fstream file(rak::path_expand(path).c_str(), std::ios::in);
|
||||
|
||||
if (!file.is_open())
|
||||
|
||||
@@ -45,25 +45,25 @@ namespace core {
|
||||
|
||||
namespace utils {
|
||||
|
||||
class VariableMap;
|
||||
class CommandMap;
|
||||
|
||||
const char* parse_command_name(const char* first, const char* last, std::string* dest);
|
||||
|
||||
const char* parse_command_single(VariableMap* varMap, const char* first);
|
||||
const char* parse_command_single(VariableMap* varMap, const char* first, const char* last);
|
||||
const char* parse_command_single(CommandMap* varMap, const char* first);
|
||||
const char* parse_command_single(CommandMap* varMap, const char* first, const char* last);
|
||||
|
||||
const char* parse_command_d_single(VariableMap* varMap, core::Download* download, const char* first, const char* last);
|
||||
const char* parse_command_d_single(CommandMap* varMap, core::Download* download, const char* first, const char* last);
|
||||
|
||||
void parse_command_multiple(VariableMap* varMap, const char* first);
|
||||
bool parse_command_file(VariableMap* varMap, const std::string& path);
|
||||
void parse_command_multiple(CommandMap* varMap, const char* first);
|
||||
bool parse_command_file(CommandMap* varMap, const std::string& path);
|
||||
|
||||
inline void
|
||||
parse_command_single_std(VariableMap* varMap, const std::string& cmd) {
|
||||
parse_command_single_std(CommandMap* varMap, const std::string& cmd) {
|
||||
parse_command_single(varMap, cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
}
|
||||
|
||||
inline void
|
||||
parse_command_d_single_std(VariableMap* varMap, core::Download* download, const std::string& cmd) {
|
||||
parse_command_d_single_std(CommandMap* varMap, core::Download* download, const std::string& cmd) {
|
||||
parse_command_d_single(varMap, download, cmd.c_str(), cmd.c_str() + cmd.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
#include "display/window_log.h"
|
||||
#include "display/window_title.h"
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
#include "rpc/parse_commands.h"
|
||||
|
||||
#include "control.h"
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@
|
||||
#include "display/window_statusbar.h"
|
||||
#include "input/manager.h"
|
||||
#include "input/text_input.h"
|
||||
#include "utils/variable_map.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "control.h"
|
||||
#include "download_list.h"
|
||||
|
||||
@@ -7,8 +7,6 @@ libsub_utils_a_SOURCES = \
|
||||
lockfile.cc \
|
||||
lockfile.h \
|
||||
socket_fd.cc \
|
||||
socket_fd.h \
|
||||
variable_map.cc \
|
||||
variable_map.h
|
||||
socket_fd.h
|
||||
|
||||
INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir)
|
||||
|
||||
Reference in New Issue
Block a user