mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-17 23:52:30 +00:00
Backport changes from feature-bind.
This commit is contained in:
@@ -140,7 +140,7 @@ apply_d_change_link(core::Download* download, const torrent::Object::list_type&
|
||||
case 0:
|
||||
if (symlink(target.c_str(), link.c_str()) == -1){
|
||||
lt_log_print(torrent::LOG_TORRENT_WARN, "create_link failed: %s",
|
||||
rak::error_number::current().c_str());
|
||||
rak::error_number::current().c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -324,7 +324,7 @@ struct call_add_d_peer_t {
|
||||
|
||||
void operator() (const sockaddr* sa, int err) {
|
||||
if (sa == NULL) {
|
||||
lt_log_print(torrent::LOG_CONNECTION_WARN, "Could not resolve hostname for added peer.");
|
||||
lt_log_print(torrent::LOG_TORRENT_WARN, "could not resolve hostname for added peer");
|
||||
} else {
|
||||
m_download->download()->add_peer(sa, m_port);
|
||||
}
|
||||
@@ -872,8 +872,10 @@ initialize_command_download() {
|
||||
|
||||
CMD2_DL ("d.wanted_chunks", CMD2_ON_DATA(wanted_chunks));
|
||||
|
||||
CMD2_DL_V ("d.tracker_announce", std::bind(&torrent::Download::manual_request, CMD2_BIND_DL, false));
|
||||
CMD2_DL_V ("d.tracker_announce.force", std::bind(&torrent::Download::manual_request, CMD2_BIND_DL, true));
|
||||
// Do not exposre d.tracker_announce.force to regular users.
|
||||
CMD2_DL_V ("d.tracker_announce", std::bind(&torrent::Download::manual_request, CMD2_BIND_DL, false));
|
||||
CMD2_DL_V ("d.tracker_announce.force", std::bind(&torrent::Download::manual_request, CMD2_BIND_DL, true));
|
||||
|
||||
CMD2_DL ("d.tracker_numwant", std::bind(&torrent::TrackerList::numwant, CMD2_BIND_TL));
|
||||
CMD2_DL_VALUE_V ("d.tracker_numwant.set", std::bind(&torrent::TrackerList::set_numwant, CMD2_BIND_TL, std::placeholders::_2));
|
||||
// TODO: Deprecate 'd.tracker_focus'.
|
||||
|
||||
+40
-70
@@ -44,6 +44,30 @@
|
||||
#include "control.h"
|
||||
#include "command_helpers.h"
|
||||
#include "rpc/parse.h"
|
||||
#include "rpc/parse_options.h"
|
||||
|
||||
static std::vector<std::pair<const char*, int>> object_storage_flags = {
|
||||
{ "multi", rpc::object_storage::flag_multi_type },
|
||||
{ "simple", rpc::object_storage::flag_function_type },
|
||||
{ "value", rpc::object_storage::flag_value_type },
|
||||
{ "bool", rpc::object_storage::flag_bool_type },
|
||||
{ "string", rpc::object_storage::flag_string_type },
|
||||
{ "list", rpc::object_storage::flag_list_type },
|
||||
|
||||
{ "static", rpc::object_storage::flag_static },
|
||||
{ "private", rpc::object_storage::flag_private },
|
||||
{ "const", rpc::object_storage::flag_constant },
|
||||
{ "rlookup", rpc::object_storage::flag_rlookup }
|
||||
};
|
||||
|
||||
static int
|
||||
object_storage_parse_flag(const std::string& flag) {
|
||||
for (auto f : object_storage_flags)
|
||||
if (f.first == flag)
|
||||
return f.second;
|
||||
|
||||
throw torrent::input_error("unknown flag");
|
||||
}
|
||||
|
||||
std::string
|
||||
system_method_generate_command(torrent::Object::list_const_iterator first, torrent::Object::list_const_iterator last) {
|
||||
@@ -263,87 +287,33 @@ system_method_insert(const torrent::Object::list_type& args) {
|
||||
throw torrent::input_error("Invalid key.");
|
||||
|
||||
int flags = rpc::CommandMap::flag_delete_key | rpc::CommandMap::flag_modifiable | rpc::CommandMap::flag_public_xmlrpc;
|
||||
int new_flags = rpc::parse_option_flags(itrArgs->as_string(), std::bind(&object_storage_parse_flag, std::placeholders::_1));
|
||||
|
||||
const std::string& options = itrArgs->as_string();
|
||||
|
||||
// TODO: Replace find with a method that does '|' separated search
|
||||
// for all valid options, and then cross-checks that unmixable ones
|
||||
// aren't in there. Use a bitfield.
|
||||
|
||||
if (options.find("private") != std::string::npos)
|
||||
if ((new_flags & rpc::object_storage::flag_private))
|
||||
flags &= ~rpc::CommandMap::flag_public_xmlrpc;
|
||||
if (options.find("const") != std::string::npos)
|
||||
|
||||
if ((new_flags & rpc::object_storage::flag_constant))
|
||||
flags &= ~rpc::CommandMap::flag_modifiable;
|
||||
|
||||
if (options.find("multi") != std::string::npos) {
|
||||
torrent::Object::list_type new_args;
|
||||
new_args.push_back(rawKey);
|
||||
torrent::Object::list_type new_args;
|
||||
new_args.push_back(rawKey);
|
||||
|
||||
if ((new_flags & rpc::object_storage::flag_function_type) ||
|
||||
(new_flags & rpc::object_storage::flag_multi_type)) {
|
||||
new_args.push_back(system_method_generate_command(++itrArgs, args.end()));
|
||||
|
||||
int new_flags = rpc::object_storage::flag_multi_type;
|
||||
|
||||
if (options.find("static") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_static;
|
||||
if (options.find("private") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_private;
|
||||
if (options.find("const") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_constant;
|
||||
if (options.find("rlookup") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_rlookup;
|
||||
|
||||
return system_method_insert_object(new_args, new_flags);
|
||||
|
||||
} else if (options.find("simple") != std::string::npos) {
|
||||
torrent::Object::list_type new_args;
|
||||
new_args.push_back(rawKey);
|
||||
new_args.push_back(system_method_generate_command(++itrArgs, args.end()));
|
||||
|
||||
int new_flags = rpc::object_storage::flag_function_type;
|
||||
|
||||
if (options.find("static") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_static;
|
||||
if (options.find("private") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_private;
|
||||
if (options.find("const") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_constant;
|
||||
|
||||
return system_method_insert_object(new_args, new_flags);
|
||||
|
||||
} else if (options.find("value") != std::string::npos ||
|
||||
options.find("bool") != std::string::npos ||
|
||||
options.find("string") != std::string::npos ||
|
||||
options.find("list") != std::string::npos) {
|
||||
torrent::Object::list_type new_args;
|
||||
new_args.push_back(rawKey);
|
||||
|
||||
} else if ((new_flags & rpc::object_storage::flag_value_type) ||
|
||||
(new_flags & rpc::object_storage::flag_bool_type) ||
|
||||
(new_flags & rpc::object_storage::flag_string_type) ||
|
||||
(new_flags & rpc::object_storage::flag_list_type)) {
|
||||
if (++itrArgs != args.end())
|
||||
new_args.insert(new_args.end(), itrArgs, args.end());
|
||||
|
||||
int new_flags;
|
||||
|
||||
if (options.find("value") != std::string::npos)
|
||||
new_flags = rpc::object_storage::flag_value_type;
|
||||
else if (options.find("bool") != std::string::npos)
|
||||
new_flags = rpc::object_storage::flag_bool_type;
|
||||
else if (options.find("string") != std::string::npos)
|
||||
new_flags = rpc::object_storage::flag_string_type;
|
||||
else if (options.find("list") != std::string::npos)
|
||||
new_flags = rpc::object_storage::flag_list_type;
|
||||
|
||||
if (options.find("static") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_static;
|
||||
if (options.find("private") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_private;
|
||||
if (options.find("const") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_constant;
|
||||
|
||||
return system_method_insert_object(new_args, new_flags);
|
||||
|
||||
} else {
|
||||
// THROW.
|
||||
throw torrent::input_error("No object type specified.");
|
||||
}
|
||||
|
||||
return torrent::Object();
|
||||
return system_method_insert_object(new_args, new_flags);
|
||||
}
|
||||
|
||||
// method.erase <> {name}
|
||||
@@ -457,7 +427,7 @@ cmd_catch(rpc::target_type target, const torrent::Object& args) {
|
||||
|
||||
void
|
||||
initialize_command_dynamic() {
|
||||
CMD2_VAR_BOOL ("method.use_deprecated", false);
|
||||
CMD2_VAR_BOOL ("method.use_deprecated", true);
|
||||
CMD2_VAR_VALUE ("method.use_intermediate", 1);
|
||||
|
||||
CMD2_ANY_LIST ("method.insert", std::bind(&system_method_insert, std::placeholders::_2));
|
||||
|
||||
+2
-2
@@ -286,7 +286,7 @@ ipv4_filter_parse(const char* address, int value) {
|
||||
inet_ntop(AF_INET, &net_start, start_str, INET_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET, &net_end, end_str, INET_ADDRSTRLEN);
|
||||
|
||||
lt_log_print(torrent::LOG_CONNECTION_DEBUG, "Adding ip filter for %s-%s.", start_str, end_str);
|
||||
lt_log_print(torrent::LOG_CONNECTION_FILTER, "Adding ip filter for %s-%s.", start_str, end_str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ apply_ipv4_filter_load(const torrent::Object::list_type& args) {
|
||||
throw torrent::input_error(buffer);
|
||||
}
|
||||
|
||||
lt_log_print(torrent::LOG_CONNECTION_INFO, "Loaded %u %s address blocks (%u kb in-memory) from '%s'.",
|
||||
lt_log_print(torrent::LOG_CONNECTION_FILTER, "loaded %u %s address blocks (%u kb in-memory) from '%s'",
|
||||
lineNumber,
|
||||
value_name.c_str(),
|
||||
torrent::PeerList::ipv4_filter()->sizeof_data() / 1024,
|
||||
|
||||
@@ -195,7 +195,7 @@ file_print_list(torrent::Object::list_const_iterator first, torrent::Object::lis
|
||||
fprintf(output, (const char*)" %s" + !(flags & file_print_use_space), first->as_string().c_str());
|
||||
break;
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
fprintf(output, (const char*)" %lli" + !(flags & file_print_use_space), first->as_value());
|
||||
fprintf(output, (const char*)" %" PRIi64 + !(flags & file_print_use_space), first->as_value());
|
||||
break;
|
||||
case torrent::Object::TYPE_LIST:
|
||||
file_print_list(first->as_list().begin(), first->as_list().end(), output, 0);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@
|
||||
#ifndef RTORRENT_CONTROL_H
|
||||
#define RTORRENT_CONTROL_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <cinttypes>
|
||||
#include <sys/types.h>
|
||||
#include <rak/timer.h>
|
||||
#include <rak/priority_queue_default.h>
|
||||
|
||||
@@ -38,10 +38,11 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <rak/path.h>
|
||||
#include lt_tr1_functional
|
||||
#include <torrent/utils/log.h>
|
||||
#include <torrent/utils/resume.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
@@ -41,10 +41,11 @@
|
||||
#ifndef RTORRENT_CORE_DOWNLOAD_FACTORY_H
|
||||
#define RTORRENT_CORE_DOWNLOAD_FACTORY_H
|
||||
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
|
||||
#include <rak/priority_queue_default.h>
|
||||
#include <torrent/object.h>
|
||||
#include lt_tr1_functional
|
||||
|
||||
#include "http_queue.h"
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@
|
||||
#ifndef RTORRENT_CORE_DOWNLOAD_SLOT_MAP_H
|
||||
#define RTORRENT_CORE_DOWNLOAD_SLOT_MAP_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include lt_tr1_functional
|
||||
|
||||
#include "download.h"
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@
|
||||
#ifndef RTORRENT_CORE_HTTP_QUEUE_H
|
||||
#define RTORRENT_CORE_HTTP_QUEUE_H
|
||||
|
||||
#include <list>
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
#include lt_tr1_functional
|
||||
#include <list>
|
||||
|
||||
namespace core {
|
||||
|
||||
|
||||
+5
-40
@@ -1,43 +1,8 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_CORE_MANAGER_H
|
||||
#define RTORRENT_CORE_MANAGER_H
|
||||
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <torrent/utils/log_buffer.h>
|
||||
@@ -86,8 +51,8 @@ public:
|
||||
View* hashing_view() { return m_hashingView; }
|
||||
void set_hashing_view(View* v);
|
||||
|
||||
torrent::log_buffer* log_important() { return m_log_important; }
|
||||
torrent::log_buffer* log_complete() { return m_log_complete; }
|
||||
torrent::log_buffer* log_important() { return m_log_important.get(); }
|
||||
torrent::log_buffer* log_complete() { return m_log_complete.get(); }
|
||||
|
||||
ThrottleMap& throttles() { return m_throttles; }
|
||||
torrent::ThrottlePair get_throttle(const std::string& name);
|
||||
@@ -155,8 +120,8 @@ private:
|
||||
ThrottleMap m_throttles;
|
||||
AddressThrottleMap m_addressThrottles;
|
||||
|
||||
torrent::log_buffer* m_log_important;
|
||||
torrent::log_buffer* m_log_complete;
|
||||
torrent::log_buffer_ptr m_log_important;
|
||||
torrent::log_buffer_ptr m_log_complete;
|
||||
};
|
||||
|
||||
// Meh, cleanup.
|
||||
|
||||
+2
-1
@@ -49,11 +49,12 @@
|
||||
#ifndef RTORRENT_CORE_VIEW_DOWNLOADS_H
|
||||
#define RTORRENT_CORE_VIEW_DOWNLOADS_H
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <rak/timer.h>
|
||||
#include <torrent/object.h>
|
||||
#include lt_tr1_functional
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include lt_tr1_functional
|
||||
|
||||
#include <rak/algorithm.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@
|
||||
#ifndef RTORRENT_DISPLAY_FRAME_H
|
||||
#define RTORRENT_DISPLAY_FRAME_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <cinttypes>
|
||||
|
||||
namespace display {
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
#ifndef RTORRENT_DISPLAY_TEXT_ELEMENT_H
|
||||
#define RTORRENT_DISPLAY_TEXT_ELEMENT_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "display/canvas.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#define RTORRENT_DISPLAY_TEXT_ELEMENT_VALUE_H
|
||||
|
||||
#include <cstring>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "text_element.h"
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#ifndef RTORRENT_DISPLAY_WINDOW_HTTP_QUEUE_H
|
||||
#define RTORRENT_DISPLAY_WINDOW_HTTP_QUEUE_H
|
||||
|
||||
#include lt_tr1_functional
|
||||
#include <functional>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#ifndef RTORRENT_DISPLAY_WINDOW_STATUSBAR_H
|
||||
#define RTORRENT_DISPLAY_WINDOW_STATUSBAR_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <cstdint>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
#ifndef RTORRENT_INPUT_BINDINGS_H
|
||||
#define RTORRENT_INPUT_BINDINGS_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include lt_tr1_functional
|
||||
|
||||
#include "display/attributes.h"
|
||||
|
||||
|
||||
@@ -37,9 +37,10 @@
|
||||
#ifndef RTORRENT_INPUT_INPUT_EVENT_H
|
||||
#define RTORRENT_INPUT_INPUT_EVENT_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <torrent/event.h>
|
||||
#include <torrent/poll.h>
|
||||
#include lt_tr1_functional
|
||||
|
||||
namespace input {
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
#ifndef RTORRENT_INPUT_PATH_INPUT_H
|
||||
#define RTORRENT_INPUT_PATH_INPUT_H
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include lt_tr1_functional
|
||||
|
||||
#include "utils/directory.h"
|
||||
#include "text_input.h"
|
||||
|
||||
+6
-1
@@ -81,6 +81,9 @@
|
||||
|
||||
#include "thread_worker.h"
|
||||
|
||||
#define LT_LOG(log_fmt, ...) \
|
||||
lt_log_print(torrent::LOG_SYSTEM, "system: " log_fmt, __VA_ARGS__);
|
||||
|
||||
void handle_sigbus(int signum, siginfo_t* sa, void* ptr);
|
||||
void do_panic(int signum);
|
||||
void print_help();
|
||||
@@ -466,6 +469,8 @@ main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
LT_LOG("seeded srandom and srand48 (seed:%u)", random_seed);
|
||||
|
||||
control->initialize();
|
||||
control->ui()->load_input_history();
|
||||
|
||||
@@ -668,7 +673,7 @@ print_help() {
|
||||
std::cout << " o View trackers" << std::endl;
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Report bugs to <sundell.software@gmail.com>." << std::endl;
|
||||
std::cout << "Report bugs to <github.com/rakshasa/rtorrent>." << std::endl;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,9 +37,9 @@
|
||||
#ifndef RTORRENT_OPTION_PARSER_H
|
||||
#define RTORRENT_OPTION_PARSER_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include lt_tr1_functional
|
||||
|
||||
// Throws std::runtime_error upon receiving bad input.
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ libsub_rpc_a_SOURCES = \
|
||||
parse.h \
|
||||
parse_commands.cc \
|
||||
parse_commands.h \
|
||||
parse_options.cc \
|
||||
parse_options.h \
|
||||
scgi.cc \
|
||||
scgi.h \
|
||||
scgi_task.cc \
|
||||
|
||||
@@ -39,9 +39,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <torrent/object.h>
|
||||
#include lt_tr1_functional
|
||||
|
||||
#include <torrent/object.h>
|
||||
#include <torrent/data/file_list_iterator.h>
|
||||
|
||||
@@ -37,9 +37,9 @@
|
||||
#ifndef RTORRENT_COMMAND_SCHEDULER_H
|
||||
#define RTORRENT_COMMAND_SCHEDULER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <inttypes.h>
|
||||
#include <rak/functional_fun.h>
|
||||
|
||||
namespace torrent {
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
#include lt_tr1_functional
|
||||
#include <functional>
|
||||
|
||||
#include <torrent/object.h>
|
||||
|
||||
namespace rpc {
|
||||
|
||||
+11
-11
@@ -42,7 +42,7 @@
|
||||
#define RTORRENT_RPC_OBJECT_STORAGE_H
|
||||
|
||||
#include <cstring>
|
||||
#include lt_tr1_unordered_map
|
||||
#include <unordered_map>
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "rak/unordered_vector.h"
|
||||
@@ -92,18 +92,18 @@ public:
|
||||
|
||||
static const unsigned int flag_generic_type = 0x1;
|
||||
static const unsigned int flag_bool_type = 0x2;
|
||||
static const unsigned int flag_value_type = 0x3;
|
||||
static const unsigned int flag_string_type = 0x4;
|
||||
static const unsigned int flag_list_type = 0x5;
|
||||
static const unsigned int flag_function_type = 0x6;
|
||||
static const unsigned int flag_multi_type = 0x7;
|
||||
static const unsigned int flag_value_type = 0x4;
|
||||
static const unsigned int flag_string_type = 0x8;
|
||||
static const unsigned int flag_list_type = 0x10;
|
||||
static const unsigned int flag_function_type = 0x20;
|
||||
static const unsigned int flag_multi_type = 0x40;
|
||||
|
||||
static const unsigned int mask_type = 0xf;
|
||||
static const unsigned int mask_type = 0xff;
|
||||
|
||||
static const unsigned int flag_constant = 0x10;
|
||||
static const unsigned int flag_static = 0x20;
|
||||
static const unsigned int flag_private = 0x40;
|
||||
static const unsigned int flag_rlookup = 0x80;
|
||||
static const unsigned int flag_constant = 0x100;
|
||||
static const unsigned int flag_static = 0x200;
|
||||
static const unsigned int flag_private = 0x400;
|
||||
static const unsigned int flag_rlookup = 0x800;
|
||||
|
||||
static const size_t key_size = key_type::max_size;
|
||||
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "parse_options.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
namespace rpc {
|
||||
|
||||
int
|
||||
parse_option_flag(const std::string& option, parse_option_flag_type ftor) {
|
||||
auto first = option.begin();
|
||||
auto last = option.end();
|
||||
|
||||
first = std::find_if(first, last, [](char c) { return !std::isspace(c, std::locale::classic()); });
|
||||
|
||||
if (first == last)
|
||||
throw torrent::input_error(option);
|
||||
|
||||
auto next = std::find_if(first, last, [](char c) { return !std::isalnum(c, std::locale::classic()) && c != '_'; });
|
||||
|
||||
if (first == next)
|
||||
throw torrent::input_error(option);
|
||||
|
||||
if (std::find_if(next, last, [](char c) { return !std::isspace(c, std::locale::classic()); }) != last)
|
||||
throw torrent::input_error(option);
|
||||
|
||||
return ftor(std::string(first, next));
|
||||
}
|
||||
|
||||
int
|
||||
parse_option_flags(const std::string& option, parse_option_flag_type ftor, int flags) {
|
||||
auto first = option.begin();
|
||||
auto last = option.end();
|
||||
|
||||
while (first != last) {
|
||||
first = std::find_if(first, last, [](char c) { return !std::isspace(c, std::locale::classic()); });
|
||||
|
||||
if (first == last)
|
||||
break;
|
||||
|
||||
auto next = std::find_if(first, last, [](char c) { return !std::isalnum(c, std::locale::classic()) && c != '_'; });
|
||||
|
||||
if (first == next)
|
||||
throw torrent::input_error(option);
|
||||
|
||||
int f = ftor(std::string(first, next));
|
||||
|
||||
if (f < 0)
|
||||
flags &= f;
|
||||
else
|
||||
flags |= f;
|
||||
|
||||
first = std::find_if(next, last, [](char c) { return !std::isspace(c, std::locale::classic()); });
|
||||
|
||||
if (first == last)
|
||||
break;
|
||||
|
||||
if (*first++ != '|' || first == last)
|
||||
throw torrent::input_error(option);
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
void
|
||||
parse_option_for_each(const std::string& option, parse_option_flag_type ftor) {
|
||||
auto first = option.begin();
|
||||
auto last = option.end();
|
||||
|
||||
while (first != last) {
|
||||
first = std::find_if(first, last, [](char c) { return !std::isspace(c, std::locale::classic()); });
|
||||
|
||||
if (first == last)
|
||||
break;
|
||||
|
||||
auto next = std::find_if(first, last, [](char c) { return !std::isalnum(c, std::locale::classic()) && c != '_'; });
|
||||
|
||||
if (first == next)
|
||||
throw torrent::input_error(option);
|
||||
|
||||
ftor(std::string(first, next));
|
||||
|
||||
first = std::find_if(next, last, [](char c) { return !std::isspace(c, std::locale::classic()); });
|
||||
|
||||
if (first == last)
|
||||
break;
|
||||
|
||||
if (*first++ != '|' || first == last)
|
||||
throw torrent::input_error(option);
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
parse_option_print_vector(int flags, const std::vector<std::pair<const char*, int>>& flag_list) {
|
||||
std::string result;
|
||||
|
||||
for (auto f : flag_list) {
|
||||
if (f.second < 0) {
|
||||
if ((flags & f.second) != flags)
|
||||
continue;
|
||||
} else {
|
||||
if ((flags & f.second) != f.second)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!result.empty())
|
||||
result += '|';
|
||||
|
||||
result += f.first;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string
|
||||
parse_option_print_flags(unsigned int flags, parse_option_rflag_type ftor) {
|
||||
std::string result;
|
||||
|
||||
for (int i = 1; flags != 0; i <<= 1) {
|
||||
if (!(flags & i))
|
||||
continue;
|
||||
|
||||
if (!result.empty())
|
||||
result += '|';
|
||||
|
||||
result += ftor(i);
|
||||
flags &= ~i;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2011, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_RPC_PARSE_OPTIONS_H
|
||||
#define RTORRENT_RPC_PARSE_OPTIONS_H
|
||||
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace rpc {
|
||||
|
||||
// If a flag returned by the functor is negative it is treated as a
|
||||
// negation of the flag.
|
||||
|
||||
typedef std::function<int (const std::string&)> parse_option_flag_type;
|
||||
typedef std::function<const char* (unsigned int)> parse_option_rflag_type;
|
||||
|
||||
int parse_option_flag(const std::string& option, parse_option_flag_type ftor);
|
||||
int parse_option_flags(const std::string& option, parse_option_flag_type ftor, int flags = int());
|
||||
|
||||
void parse_option_for_each(const std::string& option, parse_option_flag_type ftor);
|
||||
|
||||
std::string parse_option_print_vector(int flags, const std::vector<std::pair<const char*, int>>& flag_list);
|
||||
std::string parse_option_print_flags(unsigned int flags, parse_option_rflag_type ftor);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+2
-1
@@ -37,7 +37,8 @@
|
||||
#ifndef RTORRENT_RPC_XMLRPC_H
|
||||
#define RTORRENT_RPC_XMLRPC_H
|
||||
|
||||
#include lt_tr1_functional
|
||||
#include <functional>
|
||||
|
||||
#include <torrent/hash_string.h>
|
||||
|
||||
namespace core {
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
#ifndef RTORRENT_SIGNAL_HANDLER_H
|
||||
#define RTORRENT_SIGNAL_HANDLER_H
|
||||
|
||||
#include <functional>
|
||||
#include <signal.h>
|
||||
#include lt_tr1_functional
|
||||
|
||||
class SignalHandler {
|
||||
public:
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@
|
||||
#ifndef RTORRENT_UI_ROOT_H
|
||||
#define RTORRENT_UI_ROOT_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <cstdint>
|
||||
#include "input/bindings.h"
|
||||
#include "download_list.h"
|
||||
|
||||
|
||||
@@ -37,9 +37,9 @@
|
||||
#ifndef RTORRENT_UTILS_DIRECTORY_H
|
||||
#define RTORRENT_UTILS_DIRECTORY_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <inttypes.h>
|
||||
|
||||
namespace utils {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#ifndef RTORRENT_UTILS_LIST_FOCUS_H
|
||||
#define RTORRENT_UTILS_LIST_FOCUS_H
|
||||
|
||||
#include lt_tr1_functional
|
||||
#include <functional>
|
||||
|
||||
namespace utils {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user