mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-15 14:42:30 +00:00
* Automatically add variables to XMLRPC unless added as private.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@898 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -97,6 +97,7 @@ CommandSlot::call_value_base(Variable* rawVariable, const torrent::Object& rawAr
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
// Should shift this one too, so it gives the right unit.
|
||||
return command->m_slot(arg);
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
|
||||
@@ -62,13 +62,14 @@ VariableMap::~VariableMap() {
|
||||
}
|
||||
|
||||
void
|
||||
VariableMap::insert(key_type key, Variable* variable, generic_slot genericSlot, int flags) {
|
||||
VariableMap::insert(key_type key, Variable* variable, generic_slot genericSlot, 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.");
|
||||
|
||||
base_type::insert(itr, value_type(key, variable_map_data_type(variable, genericSlot, NULL, flags)));
|
||||
base_type::insert(itr, value_type(key, variable_map_data_type(variable, genericSlot, NULL, flags, parm, doc)));
|
||||
}
|
||||
|
||||
const VariableMap::mapped_type
|
||||
@@ -279,32 +280,4 @@ 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_get(key_type key, const mapped_type& arg) {
|
||||
const_iterator itr = base_type::find(key);
|
||||
|
||||
if (itr == base_type::end())
|
||||
throw torrent::input_error("Variable \"" + std::string(key) + "\" does not exist.");
|
||||
|
||||
if (itr->second.m_genericSlot != NULL)
|
||||
return itr->second.m_genericSlot(itr->second.m_variable, arg);
|
||||
|
||||
return get(key);
|
||||
}
|
||||
|
||||
const VariableMap::mapped_type
|
||||
VariableMap::call_command_set(key_type key, const mapped_type& arg) {
|
||||
const_iterator itr = base_type::find(key);
|
||||
|
||||
if (itr == base_type::end())
|
||||
throw torrent::input_error("Variable \"" + std::string(key) + "\" does not exist.");
|
||||
|
||||
if (itr->second.m_genericSlot != NULL)
|
||||
return itr->second.m_genericSlot(itr->second.m_variable, arg);
|
||||
|
||||
set(key, arg);
|
||||
|
||||
return Variable::m_emptyObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-11
@@ -66,14 +66,18 @@ struct variable_map_data_type {
|
||||
typedef const torrent::Object (*generic_slot)(Variable*, const torrent::Object&);
|
||||
typedef const torrent::Object (*download_slot)(Variable*, core::Download*, const torrent::Object&);
|
||||
|
||||
variable_map_data_type(Variable* variable, generic_slot genericSlot, download_slot downloadSlot, int flags) :
|
||||
m_variable(variable), m_genericSlot(genericSlot), m_downloadSlot(downloadSlot), m_flags(flags) {}
|
||||
variable_map_data_type(Variable* 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) {}
|
||||
|
||||
Variable* m_variable;
|
||||
generic_slot m_genericSlot;
|
||||
download_slot m_downloadSlot;
|
||||
|
||||
int m_flags;
|
||||
|
||||
const char* m_parm;
|
||||
const char* m_doc;
|
||||
};
|
||||
|
||||
class VariableMap : public std::map<const char*, variable_map_data_type, variable_map_comp> {
|
||||
@@ -90,11 +94,15 @@ public:
|
||||
using base_type::key_type;
|
||||
using base_type::value_type;
|
||||
|
||||
using base_type::begin;
|
||||
using base_type::end;
|
||||
|
||||
static const int max_size_key = 128;
|
||||
static const int max_size_opt = 1024;
|
||||
static const int max_size_line = max_size_key + max_size_opt + 64;
|
||||
|
||||
static const int flag_dont_delete = 0x1;
|
||||
static const int flag_dont_delete = 0x1;
|
||||
static const int flag_public_xmlrpc = 0x2;
|
||||
|
||||
VariableMap() {}
|
||||
~VariableMap();
|
||||
@@ -104,15 +112,16 @@ public:
|
||||
|
||||
// Allow NULL slot as a temporary compatibility hack.
|
||||
|
||||
void insert(key_type key, Variable* variable, generic_slot genericSlot = NULL, int flags = 0);
|
||||
void insert(key_type key, Variable* variable, generic_slot genericSlot = NULL, int flags = 0,
|
||||
const char* parm = "", const char* doc = "");
|
||||
|
||||
// Consider uninlining the helper functions.
|
||||
|
||||
const mapped_type get(key_type key) const;
|
||||
const mapped_type get_d(core::Download* download, key_type key) const;
|
||||
const mapped_type get(key_type key) const;
|
||||
const mapped_type get_d(core::Download* download, key_type key) const;
|
||||
|
||||
const std::string get_string(key_type key) const { return get(key).as_string(); }
|
||||
const std::string get_d_string(core::Download* download, key_type key) const { return get_d(download, key).as_string(); }
|
||||
const std::string get_string(key_type key) const { return get(key).as_string(); }
|
||||
const std::string get_d_string(core::Download* download, key_type key) const { return get_d(download, key).as_string(); }
|
||||
|
||||
mapped_value_type get_value(key_type key) const { return get(key).as_value(); }
|
||||
mapped_value_type get_d_value(core::Download* download, key_type key) const { return get_d(download, key).as_value(); }
|
||||
@@ -145,9 +154,6 @@ public:
|
||||
// requires seperate calls to get and set. These will be merged.
|
||||
const mapped_type call_command(key_type key, const mapped_type& arg);
|
||||
|
||||
const mapped_type call_command_get(key_type key, const mapped_type& arg);
|
||||
const mapped_type call_command_set(key_type key, const mapped_type& arg);
|
||||
|
||||
private:
|
||||
VariableMap(const VariableMap&);
|
||||
void operator = (const VariableMap&);
|
||||
|
||||
Reference in New Issue
Block a user