fix: sonarcloud (#2356)
* refactor: replace #define with constexpr in some utils * fix: use-std-string-instead-of-c-array sonarcloud warning * fix: use init-statement sonarcloud warning * fix: explain-empty-function sonarcloud warning * fix: move #include directive to top sonarcloud warning * fix: replace-void-ptr-arg-with-more-meaningful-type sonarcloud warning * fix: replace-redundant-type-with-auto warning * fix: use-init-statement sonarcloud warning * fix: make type a pointer-to-const sonarcloud warning * fix: cli tyop * fix: replace-redundant-type-with-auto warning * fix: use-init-statement sonarcloud warning * fix: replace-redundant-type-with-auto warning * fix: use-init-statement sonarcloud warning * fix: replace-redundant-type-with-auto warning * fix: make type a pointer-to-const sonarcloud warning * fix: make type a pointer-to-const sonarcloud warning * fix: replace-redundant-type-with-auto warning * refactor: replace #define with constexpr in rpcimpl
This commit is contained in:
parent
88f9704eed
commit
884135d853
43
cli/cli.cc
43
cli/cli.cc
|
@ -39,31 +39,30 @@
|
|||
****
|
||||
***/
|
||||
|
||||
#define MEM_K 1024
|
||||
#define MEM_K_STR "KiB"
|
||||
#define MEM_M_STR "MiB"
|
||||
#define MEM_G_STR "GiB"
|
||||
#define MEM_T_STR "TiB"
|
||||
static auto constexpr MemK = size_t{ 1024 };
|
||||
static char constexpr MemKStr[] = "KiB";
|
||||
static char constexpr MemMStr[] = "MiB";
|
||||
static char constexpr MemGStr[] = "GiB";
|
||||
static char constexpr MemTStr[] = "TiB";
|
||||
|
||||
#define DISK_K 1000
|
||||
#define DISK_B_STR "B"
|
||||
#define DISK_K_STR "kB"
|
||||
#define DISK_M_STR "MB"
|
||||
#define DISK_G_STR "GB"
|
||||
#define DISK_T_STR "TB"
|
||||
static auto constexpr DiskK = size_t{ 1000 };
|
||||
static char constexpr DiskKStr[] = "kB";
|
||||
static char constexpr DiskMStr[] = "MB";
|
||||
static char constexpr DiskGStr[] = "GB";
|
||||
static char constexpr DiskTStr[] = "TB";
|
||||
|
||||
#define SPEED_K 1000
|
||||
#define SPEED_B_STR "B/s"
|
||||
static auto constexpr SpeedK = size_t{ 1000 };
|
||||
#define SPEED_K_STR "kB/s"
|
||||
#define SPEED_M_STR "MB/s"
|
||||
#define SPEED_G_STR "GB/s"
|
||||
#define SPEED_T_STR "TB/s"
|
||||
static char constexpr SpeedKStr[] = SPEED_K_STR;
|
||||
static char constexpr SpeedMStr[] = "MB/s";
|
||||
static char constexpr SpeedGStr[] = "GB/s";
|
||||
static char constexpr SpeedTStr[] = "TB/s";
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
#define LINEWIDTH 80
|
||||
static auto constexpr LineWidth = int{ 80 };
|
||||
|
||||
static char constexpr MyConfigName[] = "transmission";
|
||||
static char constexpr MyReadableName[] = "transmission-cli";
|
||||
|
@ -239,9 +238,9 @@ int tr_main(int argc, char* argv[])
|
|||
tr_variant settings;
|
||||
char const* configDir;
|
||||
|
||||
tr_formatter_mem_init(MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR);
|
||||
tr_formatter_size_init(DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR);
|
||||
tr_formatter_speed_init(SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR);
|
||||
tr_formatter_mem_init(MemK, MemKStr, MemMStr, MemGStr, MemTStr);
|
||||
tr_formatter_size_init(DiskK, DiskKStr, DiskMStr, DiskGStr, DiskTStr);
|
||||
tr_formatter_speed_init(SpeedK, SpeedKStr, SpeedMStr, SpeedGStr, SpeedTStr);
|
||||
|
||||
printf("%s %s\n", MyReadableName, LONG_VERSION_STRING);
|
||||
|
||||
|
@ -349,7 +348,7 @@ int tr_main(int argc, char* argv[])
|
|||
|
||||
for (;;)
|
||||
{
|
||||
char line[LINEWIDTH];
|
||||
char line[LineWidth];
|
||||
tr_stat const* st;
|
||||
char const* messageName[] = {
|
||||
nullptr,
|
||||
|
@ -390,7 +389,7 @@ int tr_main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
getStatusStr(st, line, sizeof(line));
|
||||
printf("\r%-*s", TR_ARG_TUPLE(LINEWIDTH, line));
|
||||
printf("\r%-*s", TR_ARG_TUPLE(LineWidth, line));
|
||||
|
||||
if (messageName[st->error])
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include <libtransmission/version.h>
|
||||
#include <libtransmission/watchdir.h>
|
||||
|
||||
using namespace std::literals;
|
||||
#include "daemon.h"
|
||||
|
||||
#ifdef USE_SYSTEMD
|
||||
|
||||
|
@ -45,15 +45,17 @@ using namespace std::literals;
|
|||
|
||||
static void sd_notify(int /*status*/, char const* /*str*/)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
static void sd_notifyf(int /*status*/, char const* /*fmt*/, ...)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include "daemon.h"
|
||||
using namespace std::literals;
|
||||
|
||||
static char constexpr MyName[] = "transmission-daemon";
|
||||
static char constexpr Usage[] = "Transmission " LONG_VERSION_STRING
|
||||
|
@ -65,27 +67,23 @@ static char constexpr Usage[] = "Transmission " LONG_VERSION_STRING
|
|||
"\n"
|
||||
"Usage: transmission-daemon [options]";
|
||||
|
||||
#define MY_NAME "transmission-daemon"
|
||||
static auto constexpr MemK = size_t{ 1024 };
|
||||
static char constexpr MemKStr[] = "KiB";
|
||||
static char constexpr MemMStr[] = "MiB";
|
||||
static char constexpr MemGStr[] = "GiB";
|
||||
static char constexpr MemTStr[] = "TiB";
|
||||
|
||||
#define MEM_K 1024
|
||||
#define MEM_K_STR "KiB"
|
||||
#define MEM_M_STR "MiB"
|
||||
#define MEM_G_STR "GiB"
|
||||
#define MEM_T_STR "TiB"
|
||||
static auto constexpr DiskK = size_t{ 1000 };
|
||||
static char constexpr DiskKStr[] = "kB";
|
||||
static char constexpr DiskMStr[] = "MB";
|
||||
static char constexpr DiskGStr[] = "GB";
|
||||
static char constexpr DiskTStr[] = "TB";
|
||||
|
||||
#define DISK_K 1000
|
||||
#define DISK_B_STR "B"
|
||||
#define DISK_K_STR "kB"
|
||||
#define DISK_M_STR "MB"
|
||||
#define DISK_G_STR "GB"
|
||||
#define DISK_T_STR "TB"
|
||||
|
||||
#define SPEED_K 1000
|
||||
#define SPEED_B_STR "B/s"
|
||||
#define SPEED_K_STR "kB/s"
|
||||
#define SPEED_M_STR "MB/s"
|
||||
#define SPEED_G_STR "GB/s"
|
||||
#define SPEED_T_STR "TB/s"
|
||||
static auto constexpr SpeedK = size_t{ 1000 };
|
||||
static char constexpr SpeedKStr[] = "kB/s";
|
||||
static char constexpr SpeedMStr[] = "MB/s";
|
||||
static char constexpr SpeedGStr[] = "GB/s";
|
||||
static char constexpr SpeedTStr[] = "TB/s";
|
||||
|
||||
static bool seenHUP = false;
|
||||
static char const* logfileName = nullptr;
|
||||
|
@ -272,20 +270,19 @@ static auto onFileAdded(tr_watchdir_t dir, char const* name, void* vsession)
|
|||
static void printMessage(
|
||||
tr_sys_file_t file,
|
||||
[[maybe_unused]] int level,
|
||||
char const* name,
|
||||
char const* message,
|
||||
char const* filename,
|
||||
std::string_view name,
|
||||
std::string_view message,
|
||||
std::string_view filename,
|
||||
int line)
|
||||
{
|
||||
auto const out = std::empty(name) ? tr_strvJoin(message, " ("sv, filename, ":"sv, std::to_string(line), ")"sv) :
|
||||
tr_strvJoin(name, " "sv, message, " ("sv, filename, ":"sv, std::to_string(line), ")"sv);
|
||||
|
||||
if (file != TR_BAD_SYS_FILE)
|
||||
{
|
||||
char timestr[64];
|
||||
tr_logGetTimeStr(timestr, sizeof(timestr));
|
||||
|
||||
auto const out = name != nullptr ?
|
||||
tr_strvJoin("["sv, timestr, "] "sv, name, " "sv, message, " ("sv, filename, ":"sv, std::to_string(line), ")"sv) :
|
||||
tr_strvJoin("["sv, timestr, "] "sv, message, " ("sv, filename, ":"sv, std::to_string(line), ")"sv);
|
||||
tr_sys_file_write_line(file, out, nullptr);
|
||||
auto timestr = std::array<char, 64>{};
|
||||
tr_logGetTimeStr(std::data(timestr), std::size(timestr));
|
||||
tr_sys_file_write_line(file, tr_strvJoin("["sv, std::data(timestr), "] "sv, out), nullptr);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
|
@ -310,14 +307,7 @@ static void printMessage(
|
|||
break;
|
||||
}
|
||||
|
||||
if (name != nullptr)
|
||||
{
|
||||
syslog(priority, "%s %s (%s:%d)", name, message, filename, line);
|
||||
}
|
||||
else
|
||||
{
|
||||
syslog(priority, "%s (%s:%d)", message, filename, line);
|
||||
}
|
||||
syslog(priority, "%s", out.c_str());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -329,7 +319,8 @@ static void pumpLogMessages(tr_sys_file_t file)
|
|||
|
||||
for (tr_log_message const* l = list; l != nullptr; l = l->next)
|
||||
{
|
||||
printMessage(file, l->level, l->name, l->message, l->file, l->line);
|
||||
auto const name = std::string_view{ l->name != nullptr ? l->name : "" };
|
||||
printMessage(file, l->level, name, l->message, l->file, l->line);
|
||||
}
|
||||
|
||||
if (file != TR_BAD_SYS_FILE)
|
||||
|
@ -653,9 +644,9 @@ static int daemon_start(void* varg, [[maybe_unused]] bool foreground)
|
|||
}
|
||||
|
||||
/* start the session */
|
||||
tr_formatter_mem_init(MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR);
|
||||
tr_formatter_size_init(DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR);
|
||||
tr_formatter_speed_init(SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR);
|
||||
tr_formatter_mem_init(MemK, MemKStr, MemMStr, MemGStr, MemTStr);
|
||||
tr_formatter_size_init(DiskK, DiskKStr, DiskMStr, DiskGStr, DiskTStr);
|
||||
tr_formatter_speed_init(SpeedK, SpeedKStr, SpeedMStr, SpeedGStr, SpeedTStr);
|
||||
session = tr_sessionInit(configDir, true, settings);
|
||||
tr_sessionSetRPCCallback(session, on_rpc_callback, nullptr);
|
||||
tr_logAddNamedInfo(nullptr, "Using settings from \"%s\"", configDir);
|
||||
|
@ -878,13 +869,9 @@ int tr_main(int argc, char* argv[])
|
|||
&daemon_reconfigure,
|
||||
};
|
||||
|
||||
tr_error* error = nullptr;
|
||||
|
||||
if (!dtr_daemon(&cb, &data, foreground, &ret, &error))
|
||||
if (tr_error* error = nullptr; !dtr_daemon(&cb, &data, foreground, &ret, &error))
|
||||
{
|
||||
char buf[256];
|
||||
tr_snprintf(buf, sizeof(buf), "Failed to daemonize: %s", error->message);
|
||||
printMessage(logfile, TR_LOG_ERROR, MyName, buf, __FILE__, __LINE__);
|
||||
printMessage(logfile, TR_LOG_ERROR, MyName, tr_strvJoin("Failed to daemonize: ", error->message), __FILE__, __LINE__);
|
||||
tr_error_free(error);
|
||||
}
|
||||
|
||||
|
|
|
@ -326,9 +326,8 @@ static bool peerIsInUse(tr_swarm const* cs, struct peer_atom const* atom)
|
|||
getExistingHandshake(&s->manager->incomingHandshakes, &atom->addr) != nullptr;
|
||||
}
|
||||
|
||||
static void swarmFree(void* vs)
|
||||
static void swarmFree(tr_swarm* s)
|
||||
{
|
||||
auto* s = static_cast<tr_swarm*>(vs);
|
||||
TR_ASSERT(s != nullptr);
|
||||
auto const lock = s->manager->unique_lock();
|
||||
|
||||
|
@ -375,7 +374,7 @@ static void ensureMgrTimersExist(struct tr_peerMgr* m);
|
|||
|
||||
tr_peerMgr* tr_peerMgrNew(tr_session* session)
|
||||
{
|
||||
tr_peerMgr* m = tr_new0(tr_peerMgr, 1);
|
||||
auto* const m = tr_new0(tr_peerMgr, 1);
|
||||
m->session = session;
|
||||
m->incomingHandshakes = {};
|
||||
ensureMgrTimersExist(m);
|
||||
|
@ -466,10 +465,8 @@ static void atomSetSeed(tr_swarm* s, struct peer_atom* atom)
|
|||
bool tr_peerMgrPeerIsSeed(tr_torrent const* tor, tr_address const* addr)
|
||||
{
|
||||
bool isSeed = false;
|
||||
tr_swarm const* s = tor->swarm;
|
||||
struct peer_atom const* atom = getExistingAtom(s, addr);
|
||||
|
||||
if (atom != nullptr)
|
||||
if (auto const* atom = getExistingAtom(tor->swarm, addr); atom != nullptr)
|
||||
{
|
||||
isSeed = atomIsSeed(atom);
|
||||
}
|
||||
|
@ -1116,7 +1113,7 @@ static void close_peer_socket(struct tr_peer_socket const socket, tr_session* se
|
|||
}
|
||||
}
|
||||
|
||||
void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_address* addr, tr_port port, struct tr_peer_socket const socket)
|
||||
void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_address const* addr, tr_port port, struct tr_peer_socket const socket)
|
||||
{
|
||||
TR_ASSERT(tr_isSession(manager->session));
|
||||
auto const lock = manager->unique_lock();
|
||||
|
@ -1147,7 +1144,7 @@ void tr_peerMgrSetSwarmIsAllSeeds(tr_torrent* tor)
|
|||
{
|
||||
auto const lock = tor->unique_lock();
|
||||
|
||||
tr_swarm* const swarm = tor->swarm;
|
||||
auto* const swarm = tor->swarm;
|
||||
auto atomCount = int{};
|
||||
struct peer_atom** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &atomCount);
|
||||
for (int i = 0; i < atomCount; ++i)
|
||||
|
@ -1188,7 +1185,7 @@ tr_pex* tr_peerMgrCompactToPex(
|
|||
{
|
||||
size_t n = compactLen / 6;
|
||||
auto const* walk = static_cast<uint8_t const*>(compact);
|
||||
tr_pex* pex = tr_new0(tr_pex, n);
|
||||
auto* const pex = tr_new0(tr_pex, n);
|
||||
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
|
@ -1217,7 +1214,7 @@ tr_pex* tr_peerMgrCompact6ToPex(
|
|||
{
|
||||
size_t n = compactLen / 18;
|
||||
auto const* walk = static_cast<uint8_t const*>(compact);
|
||||
tr_pex* pex = tr_new0(tr_pex, n);
|
||||
auto* const pex = tr_new0(tr_pex, n);
|
||||
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
|
@ -1273,9 +1270,7 @@ int tr_pexCompare(void const* va, void const* vb)
|
|||
TR_ASSERT(tr_isPex(a));
|
||||
TR_ASSERT(tr_isPex(b));
|
||||
|
||||
auto i = int{};
|
||||
|
||||
if ((i = tr_address_compare(&a->addr, &b->addr)) != 0)
|
||||
if (auto const i = tr_address_compare(&a->addr, &b->addr); i != 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
@ -1360,7 +1355,7 @@ int tr_peerMgrGetPeers(tr_torrent const* tor, tr_pex** setme_pex, uint8_t af, ui
|
|||
struct peer_atom** atoms = nullptr;
|
||||
if (list_mode == TR_PEERS_CONNECTED) /* connected peers only */
|
||||
{
|
||||
tr_peer const** peers = (tr_peer const**)tr_ptrArrayBase(&s->peers);
|
||||
auto const** peers = (tr_peer const**)tr_ptrArrayBase(&s->peers);
|
||||
atomCount = tr_ptrArraySize(&s->peers);
|
||||
atoms = tr_new(struct peer_atom*, atomCount);
|
||||
|
||||
|
@ -1397,7 +1392,7 @@ int tr_peerMgrGetPeers(tr_torrent const* tor, tr_pex** setme_pex, uint8_t af, ui
|
|||
auto count = int{};
|
||||
for (int i = 0; i < atomCount && count < n; ++i)
|
||||
{
|
||||
struct peer_atom const* atom = atoms[i];
|
||||
auto const* const atom = atoms[i];
|
||||
|
||||
if (atom->addr.type == af)
|
||||
{
|
||||
|
@ -1516,9 +1511,7 @@ void tr_peerMgrRemoveTorrent(tr_torrent* tor)
|
|||
|
||||
void tr_peerUpdateProgress(tr_torrent* tor, tr_peer* peer)
|
||||
{
|
||||
auto const* have = &peer->have;
|
||||
|
||||
if (have->hasAll())
|
||||
if (auto const* have = &peer->have; have->hasAll())
|
||||
{
|
||||
peer->progress = 1.0;
|
||||
}
|
||||
|
@ -1556,7 +1549,7 @@ void tr_peerMgrOnTorrentGotMetainfo(tr_torrent* tor)
|
|||
/* some peer_msgs' progress fields may not be accurate if we
|
||||
didn't have the metadata before now... so refresh them all... */
|
||||
int const peerCount = tr_ptrArraySize(&tor->swarm->peers);
|
||||
tr_peer** const peers = (tr_peer**)tr_ptrArrayBase(&tor->swarm->peers);
|
||||
auto** const peers = (tr_peer**)tr_ptrArrayBase(&tor->swarm->peers);
|
||||
|
||||
for (int i = 0; i < peerCount; ++i)
|
||||
{
|
||||
|
@ -1583,7 +1576,7 @@ void tr_peerMgrTorrentAvailability(tr_torrent const* tor, int8_t* tab, unsigned
|
|||
if (tor->hasMetadata())
|
||||
{
|
||||
int const peerCount = tr_ptrArraySize(&tor->swarm->peers);
|
||||
tr_peer const** peers = (tr_peer const**)tr_ptrArrayBase(&tor->swarm->peers);
|
||||
auto const** peers = (tr_peer const**)tr_ptrArrayBase(&tor->swarm->peers);
|
||||
float const interval = tor->pieceCount() / (float)tabCount;
|
||||
auto const isSeed = tor->isSeed();
|
||||
|
||||
|
@ -1991,7 +1984,7 @@ static void rechokeDownloads(tr_swarm* s)
|
|||
int const n = tor->pieceCount();
|
||||
|
||||
/* build a bitfield of interesting pieces... */
|
||||
bool* const piece_is_interesting = tr_new(bool, n);
|
||||
auto* const piece_is_interesting = tr_new(bool, n);
|
||||
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
|
@ -2111,7 +2104,7 @@ static bool isNew(tr_peerMsgs const* msgs)
|
|||
}
|
||||
|
||||
/* get a rate for deciding which peers to choke and unchoke. */
|
||||
static int getRate(tr_torrent const* tor, struct peer_atom* atom, uint64_t now)
|
||||
static int getRate(tr_torrent const* tor, struct peer_atom const* atom, uint64_t now)
|
||||
{
|
||||
auto Bps = unsigned{};
|
||||
|
||||
|
@ -2536,7 +2529,7 @@ static void enforceSessionPeerLimit(tr_session* session)
|
|||
std::begin(session->torrents),
|
||||
std::end(session->torrents),
|
||||
size_t{},
|
||||
[](size_t sum, tr_torrent* tor) { return sum + tr_ptrArraySize(&tor->swarm->peers); });
|
||||
[](size_t sum, tr_torrent const* tor) { return sum + tr_ptrArraySize(&tor->swarm->peers); });
|
||||
size_t const max = tr_sessionGetPeerLimit(session);
|
||||
if (n_peers <= max)
|
||||
{
|
||||
|
@ -2591,8 +2584,8 @@ static void reconnectPulse(evutil_socket_t /*fd*/, short /*what*/, void* vmgr)
|
|||
enforceSessionPeerLimit(mgr->session);
|
||||
|
||||
// try to make new peer connections
|
||||
int const MaxConnectionsPerPulse = (int)(MaxConnectionsPerSecond * (ReconnectPeriodMsec / 1000.0));
|
||||
makeNewPeerConnections(mgr, MaxConnectionsPerPulse);
|
||||
auto const max_connections_per_pulse = (int)(MaxConnectionsPerSecond * (ReconnectPeriodMsec / 1000.0));
|
||||
makeNewPeerConnections(mgr, max_connections_per_pulse);
|
||||
}
|
||||
|
||||
/****
|
||||
|
|
|
@ -89,7 +89,7 @@ void tr_peerMgrClientSentRequests(tr_torrent* torrent, tr_peer* peer, tr_block_s
|
|||
|
||||
size_t tr_peerMgrCountActiveRequestsToPeer(tr_torrent const* torrent, tr_peer const* peer);
|
||||
|
||||
void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_address* addr, tr_port port, struct tr_peer_socket const socket);
|
||||
void tr_peerMgrAddIncoming(tr_peerMgr* manager, tr_address const* addr, tr_port port, struct tr_peer_socket const socket);
|
||||
|
||||
tr_pex* tr_peerMgrCompactToPex(
|
||||
void const* compact,
|
||||
|
|
|
@ -41,11 +41,11 @@
|
|||
#include "web.h"
|
||||
#include "web-utils.h"
|
||||
|
||||
#define RPC_VERSION 17
|
||||
#define RPC_VERSION_MIN 14
|
||||
#define RPC_VERSION_SEMVER "5.3.0"
|
||||
static auto constexpr RpcVersion = int64_t{ 17 };
|
||||
static auto constexpr RpcVersionMin = int64_t{ 14 };
|
||||
static char constexpr RpcVersionSemver[] = "5.3.0";
|
||||
|
||||
#define RECENTLY_ACTIVE_SECONDS 60
|
||||
static auto constexpr RecentlyActiveSeconds = time_t{ 60 };
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
|
@ -156,7 +156,7 @@ static auto getTorrents(tr_session* session, tr_variant* args)
|
|||
{
|
||||
if (sv == "recently-active"sv)
|
||||
{
|
||||
time_t const cutoff = tr_time() - RECENTLY_ACTIVE_SECONDS;
|
||||
time_t const cutoff = tr_time() - RecentlyActiveSeconds;
|
||||
|
||||
torrents.reserve(std::size(session->torrents));
|
||||
std::copy_if(
|
||||
|
@ -878,7 +878,7 @@ static char const* torrentGet(tr_session* session, tr_variant* args_in, tr_varia
|
|||
if (tr_variantDictFindStrView(args_in, TR_KEY_ids, &sv) && sv == "recently-active"sv)
|
||||
{
|
||||
time_t const now = tr_time();
|
||||
int const interval = RECENTLY_ACTIVE_SECONDS;
|
||||
auto const interval = RecentlyActiveSeconds;
|
||||
|
||||
auto const& removed = session->removed_torrents;
|
||||
tr_variant* removed_out = tr_variantDictAddList(args_out, TR_KEY_removed, std::size(removed));
|
||||
|
@ -902,7 +902,7 @@ static char const* torrentGet(tr_session* session, tr_variant* args_in, tr_varia
|
|||
/* make an array of property name quarks */
|
||||
size_t keyCount = 0;
|
||||
size_t const n = tr_variantListSize(fields);
|
||||
tr_quark* keys = tr_new(tr_quark, n);
|
||||
auto* const keys = tr_new(tr_quark, n);
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
if (!tr_variantGetStrView(tr_variantListChild(fields, i), &sv))
|
||||
|
@ -2179,15 +2179,15 @@ static void addSessionField(tr_session* s, tr_variant* d, tr_quark key)
|
|||
break;
|
||||
|
||||
case TR_KEY_rpc_version:
|
||||
tr_variantDictAddInt(d, key, RPC_VERSION);
|
||||
tr_variantDictAddInt(d, key, RpcVersion);
|
||||
break;
|
||||
|
||||
case TR_KEY_rpc_version_semver:
|
||||
tr_variantDictAddStrView(d, key, RPC_VERSION_SEMVER);
|
||||
tr_variantDictAddStrView(d, key, RpcVersionSemver);
|
||||
break;
|
||||
|
||||
case TR_KEY_rpc_version_minimum:
|
||||
tr_variantDictAddInt(d, key, RPC_VERSION_MIN);
|
||||
tr_variantDictAddInt(d, key, RpcVersionMin);
|
||||
break;
|
||||
|
||||
case TR_KEY_seedRatioLimit:
|
||||
|
|
|
@ -133,9 +133,9 @@ int tr_main(int argc, char* argv[])
|
|||
tr_metainfo_builder* b = nullptr;
|
||||
|
||||
tr_logSetLevel(TR_LOG_ERROR);
|
||||
tr_formatter_mem_init(MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR);
|
||||
tr_formatter_size_init(DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR);
|
||||
tr_formatter_speed_init(SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR);
|
||||
tr_formatter_mem_init(MemK, MemKStr, MemMStr, MemGStr, MemTStr);
|
||||
tr_formatter_size_init(DiskK, DiskKStr, DiskMStr, DiskGStr, DiskTStr);
|
||||
tr_formatter_speed_init(SpeedK, SpeedKStr, SpeedMStr, SpeedGStr, SpeedTStr);
|
||||
|
||||
auto options = app_options{};
|
||||
if (parseCommandLine(options, argc, (char const* const*)argv) != 0)
|
||||
|
|
|
@ -106,12 +106,7 @@ static void etaToString(char* buf, size_t buflen, int64_t eta)
|
|||
|
||||
static char* tr_strltime(char* buf, int seconds, size_t buflen)
|
||||
{
|
||||
int days;
|
||||
int hours;
|
||||
int minutes;
|
||||
int total_seconds;
|
||||
char b[128];
|
||||
char d[128];
|
||||
char h[128];
|
||||
char m[128];
|
||||
char s[128];
|
||||
|
@ -122,13 +117,12 @@ static char* tr_strltime(char* buf, int seconds, size_t buflen)
|
|||
seconds = 0;
|
||||
}
|
||||
|
||||
total_seconds = seconds;
|
||||
days = seconds / 86400;
|
||||
hours = (seconds % 86400) / 3600;
|
||||
minutes = (seconds % 3600) / 60;
|
||||
auto const total_seconds = seconds;
|
||||
auto const days = seconds / 86400;
|
||||
auto const hours = (seconds % 86400) / 3600;
|
||||
auto const minutes = (seconds % 3600) / 60;
|
||||
seconds = (seconds % 3600) % 60;
|
||||
|
||||
tr_snprintf(d, sizeof(d), "%d %s", days, days == 1 ? "day" : "days");
|
||||
tr_snprintf(h, sizeof(h), "%d %s", hours, hours == 1 ? "hour" : "hours");
|
||||
tr_snprintf(m, sizeof(m), "%d %s", minutes, minutes == 1 ? "minute" : "minutes");
|
||||
tr_snprintf(s, sizeof(s), "%d %s", seconds, seconds == 1 ? "second" : "seconds");
|
||||
|
@ -136,6 +130,9 @@ static char* tr_strltime(char* buf, int seconds, size_t buflen)
|
|||
|
||||
if (days != 0)
|
||||
{
|
||||
char d[128];
|
||||
tr_snprintf(d, sizeof(d), "%d %s", days, days == 1 ? "day" : "days");
|
||||
|
||||
if (days >= 4 || hours == 0)
|
||||
{
|
||||
tr_strlcpy(b, d, sizeof(b));
|
||||
|
|
|
@ -315,9 +315,9 @@ void doScrape(tr_torrent_metainfo const& metainfo)
|
|||
int tr_main(int argc, char* argv[])
|
||||
{
|
||||
tr_logSetLevel(TR_LOG_ERROR);
|
||||
tr_formatter_mem_init(MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR);
|
||||
tr_formatter_size_init(DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR);
|
||||
tr_formatter_speed_init(SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR);
|
||||
tr_formatter_mem_init(MemK, MemKStr, MemMStr, MemGStr, MemTStr);
|
||||
tr_formatter_size_init(DiskK, DiskKStr, DiskMStr, DiskGStr, DiskTStr);
|
||||
tr_formatter_speed_init(SpeedK, SpeedKStr, SpeedMStr, SpeedGStr, SpeedTStr);
|
||||
|
||||
auto opts = app_opts{};
|
||||
if (parseCommandLine(opts, argc, (char const* const*)argv) != 0)
|
||||
|
|
|
@ -8,22 +8,22 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#define MEM_K 1024
|
||||
#define MEM_K_STR "KiB"
|
||||
#define MEM_M_STR "MiB"
|
||||
#define MEM_G_STR "GiB"
|
||||
#define MEM_T_STR "TiB"
|
||||
#include <cstddef>
|
||||
|
||||
#define DISK_K 1000
|
||||
#define DISK_B_STR "B"
|
||||
#define DISK_K_STR "kB"
|
||||
#define DISK_M_STR "MB"
|
||||
#define DISK_G_STR "GB"
|
||||
#define DISK_T_STR "TB"
|
||||
static auto constexpr MemK = size_t{ 1024 };
|
||||
static char constexpr MemKStr[] = "KiB";
|
||||
static char constexpr MemMStr[] = "MiB";
|
||||
static char constexpr MemGStr[] = "GiB";
|
||||
static char constexpr MemTStr[] = "TiB";
|
||||
|
||||
#define SPEED_K 1000
|
||||
#define SPEED_B_STR "B/s"
|
||||
#define SPEED_K_STR "kB/s"
|
||||
#define SPEED_M_STR "MB/s"
|
||||
#define SPEED_G_STR "GB/s"
|
||||
#define SPEED_T_STR "TB/s"
|
||||
static auto constexpr DiskK = size_t{ 1000 };
|
||||
static char constexpr DiskKStr[] = "kB";
|
||||
static char constexpr DiskMStr[] = "MB";
|
||||
static char constexpr DiskGStr[] = "GB";
|
||||
static char constexpr DiskTStr[] = "TB";
|
||||
|
||||
static auto constexpr SpeedK = size_t{ 1000 };
|
||||
static char constexpr SpeedKStr[] = "kB/s";
|
||||
static char constexpr SpeedMStr[] = "MB/s";
|
||||
static char constexpr SpeedGStr[] = "GB/s";
|
||||
static char constexpr SpeedTStr[] = "TB/s";
|
||||
|
|
Loading…
Reference in New Issue