Backport changes from feature-bind.

This commit is contained in:
Jari Sundell
2019-08-23 23:25:24 +09:00
committed by GitHub
parent f43f9e430d
commit 7659cd0ec0
50 changed files with 658 additions and 220 deletions
+2
View File
@@ -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 \
-2
View File
@@ -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>
+1 -1
View File
@@ -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 {
+2 -1
View File
@@ -39,7 +39,8 @@
#include "globals.h"
#include lt_tr1_functional
#include <functional>
#include <torrent/object.h>
namespace rpc {
+11 -11
View File
@@ -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;
+169
View File
@@ -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;
}
}
+63
View File
@@ -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
View File
@@ -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 {