mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-11 04:32:30 +00:00
* Set SO_REUSEADDR for the listening socket.
* Moved several settings to use the new variables and made the parser better. * Use "-O2" rather than "-O3". git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@623 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -40,17 +40,17 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
// VariableString::~VariableString() {
|
||||
// }
|
||||
VariableValue::~VariableValue() {
|
||||
}
|
||||
|
||||
// std::string
|
||||
// VariableString::get() {
|
||||
// return m_variable;
|
||||
// }
|
||||
const torrent::Bencode&
|
||||
VariableValue::get() {
|
||||
return m_variable;
|
||||
}
|
||||
|
||||
// void
|
||||
// VariableString::set(const std::string& arg) {
|
||||
// m_variable = arg;
|
||||
// }
|
||||
void
|
||||
VariableValue::set(const torrent::Bencode& arg) {
|
||||
m_variable = arg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <rak/functional_fun.h>
|
||||
#include <torrent/bencode.h>
|
||||
@@ -48,19 +49,18 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
// class VariableS : public Variable {
|
||||
// public:
|
||||
// VariableString(const std::string& v = "") : m_variable(v) {}
|
||||
// virtual ~VariableString();
|
||||
class VariableValue : public Variable {
|
||||
public:
|
||||
VariableValue(const torrent::Bencode& v = torrent::Bencode()) : m_variable(v) {}
|
||||
virtual ~VariableValue();
|
||||
|
||||
// virtual const torrent::Bencode& get();
|
||||
// virtual void set(const torrent::Bencode& arg);
|
||||
virtual const torrent::Bencode& get();
|
||||
virtual void set(const torrent::Bencode& arg);
|
||||
|
||||
// private:
|
||||
// std::string m_variable;
|
||||
// };
|
||||
private:
|
||||
torrent::Bencode m_variable;
|
||||
};
|
||||
|
||||
// VariableSlot?
|
||||
template <typename Get = std::string, typename Set = const std::string&>
|
||||
class VariableSlotString : public Variable {
|
||||
public:
|
||||
@@ -84,10 +84,16 @@ public:
|
||||
}
|
||||
|
||||
virtual void set(const torrent::Bencode& arg) {
|
||||
if (!arg.is_string())
|
||||
switch (arg.get_type()) {
|
||||
case torrent::Bencode::TYPE_STRING:
|
||||
m_slotSet(arg.as_string());
|
||||
break;
|
||||
case torrent::Bencode::TYPE_NONE:
|
||||
m_slotSet("");
|
||||
break;
|
||||
default:
|
||||
throw torrent::internal_error("VariableSlotString::set(...) got wrong type.");
|
||||
|
||||
m_slotSet(arg.as_string());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -103,15 +109,19 @@ private:
|
||||
template <typename Get, typename Set>
|
||||
class VariableSlotValue : public Variable {
|
||||
public:
|
||||
typedef rak::function0<Get> SlotGet;
|
||||
typedef rak::function1<void, Set> SlotSet;
|
||||
typedef rak::function0<Get> SlotGet;
|
||||
typedef rak::function1<void, Set> SlotSet;
|
||||
typedef std::pair<int64_t, int64_t> Range;
|
||||
|
||||
VariableSlotValue(typename SlotGet::base_type* slotGet,
|
||||
typename SlotSet::base_type* slotSet,
|
||||
const char* pattern) {
|
||||
const char* pattern,
|
||||
Range range = Range(std::numeric_limits<int64_t>::min(),
|
||||
std::numeric_limits<int64_t>::max())) {
|
||||
m_slotGet.set(slotGet);
|
||||
m_slotSet.set(slotSet);
|
||||
m_pattern = pattern;
|
||||
m_range = range;
|
||||
}
|
||||
|
||||
virtual ~VariableSlotValue() {}
|
||||
@@ -148,6 +158,7 @@ private:
|
||||
SlotSet m_slotSet;
|
||||
|
||||
const char* m_pattern;
|
||||
Range m_range;
|
||||
|
||||
// Store the cache here to avoid unnessesary copying and such. This
|
||||
// should not result in any unresonable memory usage since few
|
||||
|
||||
@@ -82,16 +82,83 @@ VariableMap::set(const std::string& key, const torrent::Bencode& arg) {
|
||||
itr->second->set(arg);
|
||||
}
|
||||
|
||||
std::string::const_iterator
|
||||
parse_name(std::string::const_iterator first, std::string::const_iterator last, std::string* dest) {
|
||||
if (first == last || !std::isalpha(*first))
|
||||
throw torrent::input_error("Invalid start of name.");
|
||||
|
||||
for ( ; first != last && (std::isalnum(*first) || *first == '_'); ++first)
|
||||
dest->push_back(*first);
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
std::string::const_iterator
|
||||
parse_unknown(std::string::const_iterator first, std::string::const_iterator last, torrent::Bencode* dest) {
|
||||
if (*first == '"') {
|
||||
std::string::const_iterator next = std::find_if(++first, last, std::bind2nd(std::equal_to<char>(), '"'));
|
||||
|
||||
if (first == last ||
|
||||
first == next ||
|
||||
next == last)
|
||||
throw torrent::input_error("Could not find closing '\"'.");
|
||||
|
||||
*dest = std::string(first, next);
|
||||
return ++next;
|
||||
|
||||
} else {
|
||||
// Add rak::or and check for ','.
|
||||
std::string::const_iterator next = std::find_if(first, last, std::ptr_fun(&std::isspace));
|
||||
|
||||
*dest = std::string(first, next);
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
||||
std::string::const_iterator
|
||||
parse_args(std::string::const_iterator first, std::string::const_iterator last, torrent::Bencode::List* dest) {
|
||||
first = std::find_if(first, last, std::not1(std::ptr_fun(&std::isspace)));
|
||||
|
||||
while (first != last) {
|
||||
dest->push_back(torrent::Bencode());
|
||||
|
||||
first = parse_unknown(first, last, &dest->back());
|
||||
first = std::find_if(first, last, std::not1(std::ptr_fun(&std::isspace)));
|
||||
|
||||
if (first != last && *first != ',')
|
||||
throw torrent::input_error("A string with blanks must be quoted.");
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
void
|
||||
VariableMap::process_command(const std::string& command) {
|
||||
std::string::size_type pos = command.find('=');
|
||||
std::string::const_iterator pos = command.begin();
|
||||
pos = std::find_if(pos, command.end(), std::not1(std::ptr_fun(&std::isspace)));
|
||||
|
||||
if (pos == std::string::npos)
|
||||
throw torrent::input_error("Option handler could not find '=' in command.");
|
||||
if (pos == command.end() || *pos == '#')
|
||||
return;
|
||||
|
||||
// Do sscanf, check for integer. Later move and make it smarter.
|
||||
// Replace with parse_unknown?
|
||||
std::string key;
|
||||
pos = parse_name(pos, command.end(), &key);
|
||||
pos = std::find_if(pos, command.end(), std::not1(std::ptr_fun(&std::isspace)));
|
||||
|
||||
if (pos == command.end() || *pos != '=')
|
||||
throw torrent::input_error("Could not find '='.");
|
||||
|
||||
set(command.substr(0, pos), torrent::Bencode(command.substr(pos + 1, std::string::npos)));
|
||||
torrent::Bencode args(torrent::Bencode::TYPE_LIST);
|
||||
parse_args(pos + 1, command.end(), &args.as_list());
|
||||
|
||||
if (args.as_list().empty())
|
||||
set(key, torrent::Bencode());
|
||||
|
||||
else if (++args.as_list().begin() == args.as_list().end())
|
||||
set(key, *args.as_list().begin());
|
||||
|
||||
else
|
||||
set(key, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user