Browse Source

Backport changes from feature-bind.

pull/905/head
Jari Sundell 3 years ago committed by GitHub
parent
commit
7659cd0ec0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      .dir-locals.el
  2. 1
      .travis.yml
  3. 2
      rak/file_stat.h
  4. 2
      rak/fs_stat.h
  5. 3
      rak/functional_fun.h
  6. 2
      rak/partial_queue.h
  7. 2
      rak/priority_queue_default.h
  8. 79
      rak/socket_address.h
  9. 2
      rak/timer.h
  10. 47
      scripts/rak_cxx.m4
  11. 10
      src/command_download.cc
  12. 108
      src/command_dynamic.cc
  13. 4
      src/command_ip.cc
  14. 2
      src/command_local.cc
  15. 2
      src/control.h
  16. 3
      src/core/download_factory.cc
  17. 3
      src/core/download_factory.h
  18. 2
      src/core/download_slot_map.h
  19. 4
      src/core/http_queue.h
  20. 45
      src/core/manager.h
  21. 3
      src/core/view.h
  22. 2
      src/display/frame.cc
  23. 2
      src/display/frame.h
  24. 2
      src/display/text_element.h
  25. 1
      src/display/text_element_value.h
  26. 2
      src/display/window_http_queue.h
  27. 2
      src/display/window_statusbar.h
  28. 2
      src/input/bindings.h
  29. 3
      src/input/input_event.h
  30. 2
      src/input/path_input.h
  31. 7
      src/main.cc
  32. 2
      src/option_parser.h
  33. 2
      src/rpc/Makefile.am
  34. 2
      src/rpc/command.h
  35. 2
      src/rpc/command_scheduler.h
  36. 3
      src/rpc/command_scheduler_item.h
  37. 26
      src/rpc/object_storage.h
  38. 169
      src/rpc/parse_options.cc
  39. 63
      src/rpc/parse_options.h
  40. 3
      src/rpc/xmlrpc.h
  41. 2
      src/signal_handler.h
  42. 2
      src/ui/root.h
  43. 2
      src/utils/directory.h
  44. 2
      src/utils/list_focus.h
  45. 2
      test/Makefile.am
  46. 7
      test/helpers/assert.h
  47. 4
      test/rpc/object_storage_test.cc
  48. 189
      test/rpc/test_parse_options.cc
  49. 35
      test/rpc/test_parse_options.h
  50. 5
      test/src/command_dynamic_test.cc

7
.dir-locals.el

@ -0,0 +1,7 @@
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((c++-mode
(flycheck-clang-language-standard . "c++11")
(flycheck-gcc-language-standard . "c++11")))

1
.travis.yml

@ -73,6 +73,7 @@ before_install:
- git clone https://github.com/rakshasa/libtorrent.git
- |
pushd libtorrent \
&& (git checkout ${TRAVIS_BRANCH} || true) \
&& ./autogen.sh \
&& CXX="$COMPILER" ./configure --prefix=/usr \
&& make \

2
rak/file_stat.h

@ -38,7 +38,7 @@
#define RAK_FILE_STAT_H
#include <string>
#include <inttypes.h>
#include <cinttypes>
#include <sys/stat.h>
namespace rak {

2
rak/fs_stat.h

@ -38,7 +38,7 @@
#define RAK_FS_STAT_H
#include <string>
#include <inttypes.h>
#include <cinttypes>
#include <rak/error_number.h>

3
rak/functional_fun.h

@ -53,8 +53,7 @@
#include <memory>
#include <functional>
#include lt_tr1_functional
#include lt_tr1_memory
#include <memory>
namespace rak {

2
rak/partial_queue.h

@ -39,7 +39,7 @@
#include <cstring>
#include <stdexcept>
#include <inttypes.h>
#include <cinttypes>
namespace rak {

2
rak/priority_queue_default.h

@ -37,7 +37,7 @@
#ifndef RAK_PRIORITY_QUEUE_DEFAULT_H
#define RAK_PRIORITY_QUEUE_DEFAULT_H
#include lt_tr1_functional
#include <functional>
#include <rak/allocators.h>
#include <rak/priority_queue.h>
#include <rak/timer.h>

79
rak/socket_address.h

@ -47,9 +47,12 @@
#ifndef RAK_SOCKET_ADDRESS_H
#define RAK_SOCKET_ADDRESS_H
#include <cinttypes>
#include <cstdint>
#include <cstring>
#include <string>
#include <stdexcept>
#include <string>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
@ -77,11 +80,13 @@ public:
static const int pf_local = PF_UNIX;
#endif
bool is_any() const;
bool is_valid() const;
bool is_bindable() const;
bool is_address_any() const;
// Should we need to set AF_UNSPEC?
bool is_valid_inet_class() const { return family() == af_inet || family() == af_inet6; }
void clear() { std::memset(this, 0, sizeof(socket_address)); set_family(); }
sa_family_t family() const { return m_sockaddr.sa_family; }
@ -93,6 +98,8 @@ public:
std::string address_str() const;
bool address_c_str(char* buf, socklen_t size) const;
std::string pretty_address_str() const;
// Attemts to set it as an inet, then an inet6 address. It will
// never set anything but net addresses, no local/unix.
bool set_address_str(const std::string& a) { return set_address_c_str(a.c_str()); }
@ -119,6 +126,7 @@ public:
// extranous bytes and ensure it does not go beyond the size of this
// struct.
void copy(const socket_address& src, size_t length);
void copy_sockaddr(const sockaddr* src);
static socket_address* cast_from(sockaddr* sa) { return reinterpret_cast<socket_address*>(sa); }
static const socket_address* cast_from(const sockaddr* sa) { return reinterpret_cast<const socket_address*>(sa); }
@ -215,6 +223,8 @@ public:
void set_address_any() { set_port(0); set_address(in6addr_any); }
std::string pretty_address_str() const;
sa_family_t family() const { return m_sockaddr.sin6_family; }
void set_family() { m_sockaddr.sin6_family = AF_INET6; }
@ -233,6 +243,18 @@ private:
struct sockaddr_in6 m_sockaddr;
};
inline bool
socket_address::is_any() const {
switch (family()) {
case af_inet:
return sa_inet()->is_any();
case af_inet6:
return sa_inet6()->is_any();
default:
return false;
}
}
inline bool
socket_address::is_valid() const {
switch (family()) {
@ -317,6 +339,21 @@ socket_address::address_c_str(char* buf, socklen_t size) const {
}
}
inline std::string
socket_address::pretty_address_str() const {
switch (family()) {
case af_inet:
return sa_inet()->address_str();
case af_inet6:
return sa_inet6()->pretty_address_str();
case af_unspec:
return std::string("unspec");
default:
return std::string("invalid");
}
}
inline bool
socket_address::set_address_c_str(const char* a) {
if (sa_inet()->set_address_c_str(a)) {
@ -348,13 +385,16 @@ socket_address::length() const {
inline void
socket_address::copy(const socket_address& src, size_t length) {
length = std::min(length, sizeof(socket_address));
// Does this get properly optimized?
std::memset(this, 0, sizeof(socket_address));
std::memcpy(this, &src, length);
}
// Should we be able to compare af_unspec?
inline void
socket_address::copy_sockaddr(const sockaddr* src) {
std::memset(this, 0, sizeof(socket_address));
std::memcpy(this, src, socket_address::cast_from(src)->length());
}
inline bool
socket_address::operator == (const socket_address& rhs) const {
@ -456,6 +496,35 @@ socket_address_inet6::set_address_c_str(const char* a) {
return inet_pton(AF_INET6, a, &m_sockaddr.sin6_addr);
}
inline std::string
socket_address_inet6::pretty_address_str() const {
char buf[INET6_ADDRSTRLEN + 2 + 6];
if (inet_ntop(family(), &m_sockaddr.sin6_addr, buf + 1, INET6_ADDRSTRLEN) == NULL)
return std::string();
buf[0] = '[';
char* last_char = (char*)std::memchr(buf + 1, 0, INET6_ADDRSTRLEN);
// TODO: Throw exception here.
if (last_char == NULL || last_char >= buf + 1 + INET6_ADDRSTRLEN)
throw std::logic_error("inet_ntop for inet6 returned bad buffer");
*(last_char++) = ']';
if (!is_port_any()) {
if (snprintf(last_char, 7, ":%" PRIu16, port()) == -1)
return std::string("error"); // TODO: Throw here.
} else {
*last_char = '\0';
}
return std::string(buf);
}
inline socket_address
socket_address_inet6::normalize_address() const {
const uint32_t *addr32 = reinterpret_cast<const uint32_t *>(m_sockaddr.sin6_addr.s6_addr);

2
rak/timer.h

@ -38,7 +38,7 @@
#define RAK_TIMER_H
#include <limits>
#include <inttypes.h>
#include <cinttypes>
#include <sys/time.h>
namespace rak {

47
scripts/rak_cxx.m4

@ -12,50 +12,3 @@ AC_DEFUN([RAK_CHECK_CXX11], [
]
)
])
AC_DEFUN([RAK_CHECK_TR1_LIB], [
AC_LANG_PUSH(C++)
AC_MSG_CHECKING(should use TR1 headers)
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <unordered_map>
class Foo; typedef std::unordered_map<Foo*, int> Bar;
Bar b1;
])
], [
AC_MSG_RESULT(no)
AC_DEFINE(USE_TR1_LIB, 0, Define to 1 if you need to use TR1 containers.)
AC_DEFINE([lt_tr1_array], [<array>], [TR1 array])
AC_DEFINE([lt_tr1_functional], [<functional>], [TR1 functional])
AC_DEFINE([lt_tr1_memory], [<memory>], [TR1 memory])
AC_DEFINE([lt_tr1_unordered_map], [<unordered_map>], [TR1 unordered_map])
], [
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
#include <tr1/unordered_map>
class Foo; typedef std::tr1::unordered_map<Foo*, int> Bar;
Bar b1;
])
], [
AC_MSG_RESULT([yes])
AC_DEFINE(USE_TR1_LIB, 1, Define to 1 if you need to use TR1 containers.)
AC_DEFINE([lt_tr1_array], [<tr1/array>], [TR1 array])
AC_DEFINE([lt_tr1_functional], [<tr1/functional>], [TR1 functional])
AC_DEFINE([lt_tr1_memory], [<tr1/memory>], [TR1 memory])
AC_DEFINE([lt_tr1_unordered_map], [<tr1/unordered_map>], [TR1 unordered_map])
], [
AC_MSG_ERROR([No support for C++11 standard library nor TR1 extensions found.])
])
])
AH_VERBATIM(lt_tr1_zzz, [
#if USE_TR1_LIB == 1
namespace std { namespace tr1 {} using namespace tr1; }
#endif
])
AC_LANG_POP(C++)
])

10
src/command_download.cc

@ -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'.

108
src/command_dynamic.cc

@ -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)
flags &= ~rpc::CommandMap::flag_modifiable;
if (options.find("multi") != 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_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;
if ((new_flags & rpc::object_storage::flag_constant))
flags &= ~rpc::CommandMap::flag_modifiable;
return system_method_insert_object(new_args, new_flags);
torrent::Object::list_type new_args;
new_args.push_back(rawKey);
} else if (options.find("simple") != std::string::npos) {
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_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));

4
src/command_ip.cc

@ -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,

2
src/command_local.cc

@ -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);

2
src/control.h

@ -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>

3
src/core/download_factory.cc

@ -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>

3
src/core/download_factory.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"

2
src/core/download_slot_map.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"

4
src/core/http_queue.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 {

45
src/core/manager.h

@ -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.

3
src/core/view.h

@ -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"

2
src/display/frame.cc

@ -38,7 +38,7 @@
#include <algorithm>
#include <functional>
#include lt_tr1_functional
#include <rak/algorithm.h>
#include <torrent/exceptions.h>

2
src/display/frame.h

@ -37,7 +37,7 @@
#ifndef RTORRENT_DISPLAY_FRAME_H
#define RTORRENT_DISPLAY_FRAME_H
#include <inttypes.h>
#include <cinttypes>
namespace display {

2
src/display/text_element.h

@ -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"

1
src/display/text_element_value.h

@ -38,7 +38,6 @@
#define RTORRENT_DISPLAY_TEXT_ELEMENT_VALUE_H
#include <cstring>
#include <inttypes.h>
#include "text_element.h"

2
src/display/window_http_queue.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"

2
src/display/window_statusbar.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"

2
src/input/bindings.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"

3
src/input/input_event.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 {

2
src/input/path_input.h

@ -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"

7
src/main.cc

@ -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);
}

2
src/option_parser.h

@ -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.

2
src/rpc/Makefile.am

@ -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
src/rpc/command.h

@ -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>

2
src/rpc/command_scheduler.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 {

3
src/rpc/command_scheduler_item.h

@ -39,7 +39,8 @@
#include "globals.h"
#include lt_tr1_functional
#include <functional>
#include <torrent/object.h>
namespace rpc {

26
src/rpc/object_storage.h

@ -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 mask_type = 0xf;
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_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 = 0xff;
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
src/rpc/parse_options.cc

@ -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
src/rpc/parse_options.h

@ -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

3
src/rpc/xmlrpc.h

@ -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 {

2
src/signal_handler.h

@ -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:

2
src/ui/root.h

@ -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"

2
src/utils/directory.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 {

2
src/utils/list_focus.h

@ -37,7 +37,7 @@
#ifndef RTORRENT_UTILS_LIST_FOCUS_H
#define RTORRENT_UTILS_LIST_FOCUS_H
#include lt_tr1_functional
#include <functional>
namespace utils {

2
test/Makefile.am

@ -20,6 +20,8 @@ rtorrentTest_SOURCES = \
rpc/command_slot_test.h \
rpc/object_storage_test.cc \
rpc/object_storage_test.h \
rpc/test_parse_options.cc \
rpc/test_parse_options.h \
src/command_dynamic_test.cc \
src/command_dynamic_test.h \
main.cc

7
test/helpers/assert.h

@ -0,0 +1,7 @@
#ifndef HELPERS_ASSERT_H
#define HELPERS_ASSERT_H
#define ASSERT_CATCH_INPUT_ERROR(some_code)