fix: sonarcloud code smells (#2421)
This commit is contained in:
parent
19ede2b8cd
commit
3036a76beb
|
@ -246,7 +246,7 @@ void Application::Impl::show_details_dialog_for_selected_torrents()
|
|||
auto dialog = DetailsDialog::create(*wind_, core_);
|
||||
dialog->set_torrents(ids);
|
||||
dialog->signal_hide().connect([this, key]() { details_.erase(key); });
|
||||
dialog_it = details_.emplace(key, std::move(dialog)).first;
|
||||
dialog_it = details_.try_emplace(key, std::move(dialog)).first;
|
||||
dialog_it->second->show();
|
||||
}
|
||||
|
||||
|
|
|
@ -1362,7 +1362,7 @@ void DetailsDialog::Impl::refreshPeerList(std::vector<tr_torrent*> const& torren
|
|||
{
|
||||
auto const iter = store->append();
|
||||
initPeerRow(iter, key, tr_torrentName(tor), s);
|
||||
hash.emplace(key, Gtk::TreeRowReference(store, store->get_path(iter)));
|
||||
hash.try_emplace(key, Gtk::TreeRowReference(store, store->get_path(iter)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1432,7 +1432,7 @@ void DetailsDialog::Impl::refreshWebseedList(std::vector<tr_torrent*> const& tor
|
|||
auto const iter = store->append();
|
||||
(*iter)[webseed_cols.url] = url;
|
||||
(*iter)[webseed_cols.key] = key;
|
||||
hash.emplace(key, Gtk::TreeRowReference(store, store->get_path(iter)));
|
||||
hash.try_emplace(key, Gtk::TreeRowReference(store, store->get_path(iter)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2133,7 +2133,7 @@ void DetailsDialog::Impl::refreshTracker(std::vector<tr_torrent*> const& torrent
|
|||
(*iter)[tracker_cols.key] = gstr.str();
|
||||
|
||||
auto const p = store->get_path(iter);
|
||||
hash.emplace(gstr.str(), Gtk::TreeRowReference(store, p));
|
||||
hash.try_emplace(gstr.str(), Gtk::TreeRowReference(store, p));
|
||||
gtr_get_favicon_from_url(
|
||||
session,
|
||||
tracker.announce,
|
||||
|
@ -2204,7 +2204,7 @@ void DetailsDialog::Impl::on_edit_trackers_response(int response, std::shared_pt
|
|||
|
||||
if (response == Gtk::RESPONSE_ACCEPT)
|
||||
{
|
||||
int const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY));
|
||||
auto const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY));
|
||||
auto* const text_buffer = static_cast<Gtk::TextBuffer*>(dialog->get_data(TEXT_BUFFER_KEY));
|
||||
tr_torrent* const tor = core_->find_torrent(torrent_id);
|
||||
|
||||
|
@ -2359,7 +2359,7 @@ void DetailsDialog::Impl::on_add_tracker_response(int response, std::shared_ptr<
|
|||
if (response == Gtk::RESPONSE_ACCEPT)
|
||||
{
|
||||
auto* e = static_cast<Gtk::Entry*>(dialog->get_data(URL_ENTRY_KEY));
|
||||
int const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY));
|
||||
auto const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY));
|
||||
auto const url = gtr_str_strip(e->get_text());
|
||||
|
||||
if (!url.empty())
|
||||
|
|
|
@ -592,7 +592,7 @@ std::string buildFilename(tr_torrent const* tor, Gtk::TreeModel::iterator const&
|
|||
tokens.push_front(child->get_value(file_cols.label));
|
||||
}
|
||||
|
||||
tokens.push_front(tr_torrentGetCurrentDir(tor));
|
||||
tokens.emplace_front(tr_torrentGetCurrentDir(tor));
|
||||
return Glib::build_filename(tokens);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ std::unique_ptr<IconCache> icon_cache_new(Gtk::Widget& for_widget, Gtk::IconSize
|
|||
auto icons = std::make_unique<IconCache>();
|
||||
icons->icon_theme = Gtk::IconTheme::get_for_screen(for_widget.get_screen());
|
||||
icons->icon_size = get_size_in_pixels(icon_size);
|
||||
icons->cache.emplace(VoidPixbufKey, create_void_pixbuf(icons->icon_size, icons->icon_size));
|
||||
icons->cache.try_emplace(VoidPixbufKey, create_void_pixbuf(icons->icon_size, icons->icon_size));
|
||||
return icons;
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ Glib::RefPtr<Gdk::Pixbuf> icon_cache_get_mime_type_icon(IconCache& icons, Glib::
|
|||
|
||||
if (pixbuf != nullptr)
|
||||
{
|
||||
icons.cache.emplace(key, pixbuf);
|
||||
icons.cache.try_emplace(key, pixbuf);
|
||||
}
|
||||
|
||||
return pixbuf;
|
||||
|
|
|
@ -160,7 +160,7 @@ void notify_callback(Glib::RefPtr<Gio::AsyncResult>& res, TrNotification const&
|
|||
|
||||
auto const id = Glib::VariantBase::cast_dynamic<UInt32VariantType>(result.get_child(0)).get();
|
||||
|
||||
active_notifications.emplace(id, n);
|
||||
active_notifications.try_emplace(id, n);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -207,7 +207,7 @@ void gtr_notify_torrent_completed(Glib::RefPtr<Session> const& core, int torrent
|
|||
}
|
||||
|
||||
std::map<Glib::ustring, Glib::VariantBase> hints;
|
||||
hints.emplace("category", StringVariantType::create("transfer.complete"));
|
||||
hints.try_emplace("category", StringVariantType::create("transfer.complete"));
|
||||
|
||||
proxy->call(
|
||||
"Notify",
|
||||
|
|
|
@ -1340,8 +1340,8 @@ namespace
|
|||
int gtr_compare_double(double const a, double const b, int decimal_places)
|
||||
{
|
||||
int ret;
|
||||
int64_t const ia = (int64_t)(a * pow(10, decimal_places));
|
||||
int64_t const ib = (int64_t)(b * pow(10, decimal_places));
|
||||
auto const ia = int64_t(a * pow(10, decimal_places));
|
||||
auto const ib = int64_t(b * pow(10, decimal_places));
|
||||
|
||||
if (ia < ib)
|
||||
{
|
||||
|
|
|
@ -98,7 +98,7 @@ Glib::ustring tr_strltime(time_t seconds)
|
|||
seconds = 0;
|
||||
}
|
||||
|
||||
int const days = (int)(seconds / 86400);
|
||||
auto const days = (int)(seconds / 86400);
|
||||
int const hours = (seconds % 86400) / 3600;
|
||||
int const minutes = (seconds % 3600) / 60;
|
||||
seconds = (seconds % 3600) % 60;
|
||||
|
|
|
@ -245,9 +245,7 @@ bool tr_announce_list::save(std::string const& torrent_file, tr_error** error) c
|
|||
// confirm that it's good by parsing it back again
|
||||
auto const contents = tr_variantToStr(&metainfo, TR_VARIANT_FMT_BENC);
|
||||
tr_variantFree(&metainfo);
|
||||
|
||||
auto tm = tr_torrent_metainfo{};
|
||||
if (!tm.parseBenc(contents))
|
||||
if (auto tm = tr_torrent_metainfo{}; !tm.parseBenc(contents))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ static tr_pex* listToPex(tr_variant* peerList, size_t* setme_len)
|
|||
{
|
||||
size_t n = 0;
|
||||
size_t const len = tr_variantListSize(peerList);
|
||||
tr_pex* pex = tr_new0(tr_pex, len);
|
||||
auto* const pex = tr_new0(tr_pex, len);
|
||||
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
{
|
||||
|
|
|
@ -805,7 +805,7 @@ static tr_announce_request* announce_request_new(
|
|||
tr_tier const* tier,
|
||||
tr_announce_event event)
|
||||
{
|
||||
tr_announce_request* req = tr_new0(tr_announce_request, 1);
|
||||
auto* const req = tr_new0(tr_announce_request, 1);
|
||||
req->port = tr_sessionGetPublicPeerPort(announcer->session);
|
||||
req->announce_url = tier->currentTracker->announce_url;
|
||||
req->tracker_id_str = tr_strdup(tier->currentTracker->tracker_id_str);
|
||||
|
@ -1151,7 +1151,7 @@ static void tierAnnounce(tr_announcer* announcer, tr_tier* tier)
|
|||
tr_announce_event announce_event = tier_announce_event_pull(tier);
|
||||
tr_announce_request* req = announce_request_new(announcer, tor, tier, announce_event);
|
||||
|
||||
struct announce_data* data = tr_new0(struct announce_data, 1);
|
||||
auto* const data = tr_new0(struct announce_data, 1);
|
||||
data->session = announcer->session;
|
||||
data->tierId = tier->key;
|
||||
data->isRunningOnSuccess = tor->isRunning;
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include "trevent.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define MY_NAME "Cache"
|
||||
static char constexpr MyName[] = "Cache";
|
||||
|
||||
#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__)
|
||||
#define dbgmsg(...) tr_logAddDeepNamed(MyName, __VA_ARGS__)
|
||||
|
||||
/****
|
||||
*****
|
||||
|
@ -74,7 +74,7 @@ struct run_info
|
|||
static int getBlockRun(tr_cache const* cache, int pos, struct run_info* info)
|
||||
{
|
||||
int const n = tr_ptrArraySize(&cache->blocks);
|
||||
struct cache_block const* const* blocks = (struct cache_block const* const*)tr_ptrArrayBase(&cache->blocks);
|
||||
auto const* const* blocks = (struct cache_block const* const*)tr_ptrArrayBase(&cache->blocks);
|
||||
struct cache_block const* ref = blocks[pos];
|
||||
tr_block_index_t block = ref->block;
|
||||
int len = 0;
|
||||
|
@ -162,9 +162,9 @@ static int calcRuns(tr_cache const* cache, struct run_info* runs)
|
|||
static int flushContiguous(tr_cache* cache, int pos, int n)
|
||||
{
|
||||
int err = 0;
|
||||
uint8_t* buf = tr_new(uint8_t, n * MAX_BLOCK_SIZE);
|
||||
uint8_t* walk = buf;
|
||||
struct cache_block** blocks = (struct cache_block**)tr_ptrArrayBase(&cache->blocks);
|
||||
auto* const buf = tr_new(uint8_t, n * MAX_BLOCK_SIZE);
|
||||
auto* walk = buf;
|
||||
auto** blocks = (struct cache_block**)tr_ptrArrayBase(&cache->blocks);
|
||||
|
||||
struct cache_block* b = blocks[pos];
|
||||
tr_torrent* tor = b->tor;
|
||||
|
@ -219,7 +219,7 @@ static int cacheTrim(tr_cache* cache)
|
|||
/* Amount of cache that should be removed by the flush. This influences how large
|
||||
* runs can grow as well as how often flushes will happen. */
|
||||
int const cacheCutoff = 1 + cache->max_blocks / 4;
|
||||
struct run_info* runs = tr_new(struct run_info, tr_ptrArraySize(&cache->blocks));
|
||||
auto* const runs = tr_new(struct run_info, tr_ptrArraySize(&cache->blocks));
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
|
@ -252,7 +252,7 @@ int tr_cacheSetLimit(tr_cache* cache, int64_t max_bytes)
|
|||
cache->max_blocks = getMaxBlocks(max_bytes);
|
||||
|
||||
tr_logAddNamedDbg(
|
||||
MY_NAME,
|
||||
MyName,
|
||||
"Maximum cache size set to %s (%d blocks)",
|
||||
tr_formatter_mem_B(cache->max_bytes).c_str(),
|
||||
cache->max_blocks);
|
||||
|
@ -267,7 +267,7 @@ int64_t tr_cacheGetLimit(tr_cache const* cache)
|
|||
|
||||
tr_cache* tr_cacheNew(int64_t max_bytes)
|
||||
{
|
||||
tr_cache* cache = tr_new0(tr_cache, 1);
|
||||
auto* const cache = tr_new0(tr_cache, 1);
|
||||
cache->blocks = {};
|
||||
cache->max_bytes = max_bytes;
|
||||
cache->max_blocks = getMaxBlocks(max_bytes);
|
||||
|
|
|
@ -55,7 +55,7 @@ extern "C"
|
|||
namespace
|
||||
{
|
||||
|
||||
#define MY_NAME "tr_crypto_utils"
|
||||
static char constexpr MyName[] = "tr_crypto_utils";
|
||||
|
||||
char const* ccrypto_error_to_str(CCCryptorStatus error_code)
|
||||
{
|
||||
|
@ -100,7 +100,7 @@ void log_ccrypto_error(CCCryptorStatus error_code, char const* file, int line)
|
|||
file,
|
||||
line,
|
||||
TR_LOG_ERROR,
|
||||
MY_NAME,
|
||||
MyName,
|
||||
"CCrypto error (%d): %s",
|
||||
error_code,
|
||||
ccrypto_error_to_str(error_code));
|
||||
|
|
|
@ -50,7 +50,7 @@ struct tr_dh_ctx
|
|||
****
|
||||
***/
|
||||
|
||||
#define MY_NAME "tr_crypto_utils"
|
||||
static char constexpr MyName[] = "tr_crypto_utils";
|
||||
|
||||
static void log_cyassl_error(int error_code, char const* file, int line)
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ static void log_cyassl_error(int error_code, char const* file, int line)
|
|||
CTaoCryptErrorString(error_code, error_message);
|
||||
#endif
|
||||
|
||||
tr_logAddMessage(file, line, TR_LOG_ERROR, MY_NAME, "CyaSSL error: %s", error_message);
|
||||
tr_logAddMessage(file, line, TR_LOG_ERROR, MyName, "CyaSSL error: %s", error_message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
****
|
||||
***/
|
||||
|
||||
#define MY_NAME "tr_crypto_utils"
|
||||
static char constexpr MyName[] = "tr_crypto_utils";
|
||||
|
||||
static void log_openssl_error(char const* file, int line)
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ static void log_openssl_error(char const* file, int line)
|
|||
#endif
|
||||
|
||||
ERR_error_string_n(error_code, buf, sizeof(buf));
|
||||
tr_logAddMessage(file, line, TR_LOG_ERROR, MY_NAME, "OpenSSL error: %s", buf);
|
||||
tr_logAddMessage(file, line, TR_LOG_ERROR, MyName, "OpenSSL error: %s", buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
****
|
||||
***/
|
||||
|
||||
#define MY_NAME "tr_crypto_utils"
|
||||
static char constexpr MyName[] = "tr_crypto_utils";
|
||||
|
||||
using api_ctr_drbg_context = API(ctr_drbg_context);
|
||||
using api_sha1_context = API(sha1_context);
|
||||
|
@ -60,7 +60,7 @@ static void log_polarssl_error(int error_code, char const* file, int line)
|
|||
error_strerror(error_code, error_message, sizeof(error_message));
|
||||
#endif
|
||||
|
||||
tr_logAddMessage(file, line, TR_LOG_ERROR, MY_NAME, "PolarSSL error: %s", error_message);
|
||||
tr_logAddMessage(file, line, TR_LOG_ERROR, MyName, "PolarSSL error: %s", error_message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
***
|
||||
**/
|
||||
|
||||
#define PRIME_LEN 96
|
||||
#define DH_PRIVKEY_LEN 20
|
||||
static auto constexpr PrimeLen = size_t{ 96 };
|
||||
static auto constexpr DhPrivkeyLen = size_t{ 20 };
|
||||
|
||||
static uint8_t const dh_P[PRIME_LEN] = {
|
||||
static uint8_t constexpr dh_P[PrimeLen] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, //
|
||||
0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, //
|
||||
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, //
|
||||
|
@ -34,7 +34,7 @@ static uint8_t const dh_P[PRIME_LEN] = {
|
|||
0xA6, 0x3A, 0x36, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x05, 0x63, //
|
||||
};
|
||||
|
||||
static uint8_t const dh_G[] = { 2 };
|
||||
static uint8_t constexpr dh_G[] = { 2 };
|
||||
|
||||
/**
|
||||
***
|
||||
|
@ -46,7 +46,7 @@ static void ensureKeyExists(tr_crypto* crypto)
|
|||
{
|
||||
size_t public_key_length = 0;
|
||||
crypto->dh = tr_dh_new(dh_P, sizeof(dh_P), dh_G, sizeof(dh_G));
|
||||
tr_dh_make_key(crypto->dh, DH_PRIVKEY_LEN, crypto->myPublicKey, &public_key_length);
|
||||
tr_dh_make_key(crypto->dh, DhPrivkeyLen, crypto->myPublicKey, &public_key_length);
|
||||
|
||||
TR_ASSERT(public_key_length == KEY_LEN);
|
||||
}
|
||||
|
|
|
@ -245,8 +245,7 @@ static handshake_parse_err_t parseHandshake(tr_handshake* handshake, struct evbu
|
|||
/* torrent hash */
|
||||
auto hash = tr_sha1_digest_t{};
|
||||
tr_peerIoReadBytes(handshake->io, inbuf, std::data(hash), std::size(hash));
|
||||
auto const torrent_hash = tr_peerIoGetTorrentHash(handshake->io);
|
||||
if (!torrent_hash || *torrent_hash != hash)
|
||||
if (auto const torrent_hash = tr_peerIoGetTorrentHash(handshake->io); !torrent_hash || *torrent_hash != hash)
|
||||
{
|
||||
dbgmsg(handshake, "peer returned the wrong hash. wtf?");
|
||||
return HANDSHAKE_BAD_TORRENT;
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
#include "port-forwarding.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define LIFETIME_SECS 3600
|
||||
#define COMMAND_WAIT_SECS 8
|
||||
static auto constexpr LifetimeSecs = uint32_t{ 3600 };
|
||||
static auto constexpr CommandWaitSecs = time_t{ 8 };
|
||||
|
||||
static char const* getKey(void)
|
||||
{
|
||||
|
@ -110,7 +110,7 @@ static bool canSendCommand(struct tr_natpmp const* nat)
|
|||
|
||||
static void setCommandTime(struct tr_natpmp* nat)
|
||||
{
|
||||
nat->command_time = tr_time() + COMMAND_WAIT_SECS;
|
||||
nat->command_time = tr_time() + CommandWaitSecs;
|
||||
}
|
||||
|
||||
tr_port_forwarding tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, bool is_enabled, tr_port* public_port)
|
||||
|
@ -199,7 +199,7 @@ tr_port_forwarding tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, b
|
|||
|
||||
if (nat->state == TR_NATPMP_SEND_MAP && canSendCommand(nat))
|
||||
{
|
||||
int const val = sendnewportmappingrequest(&nat->natpmp, NATPMP_PROTOCOL_TCP, private_port, private_port, LIFETIME_SECS);
|
||||
int const val = sendnewportmappingrequest(&nat->natpmp, NATPMP_PROTOCOL_TCP, private_port, private_port, LifetimeSecs);
|
||||
logVal("sendnewportmappingrequest", val);
|
||||
nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_MAP;
|
||||
setCommandTime(nat);
|
||||
|
|
|
@ -220,7 +220,7 @@ bool tr_address_from_sockaddr_storage(tr_address* setme_addr, tr_port* setme_por
|
|||
{
|
||||
if (from->ss_family == AF_INET)
|
||||
{
|
||||
struct sockaddr_in const* sin = (struct sockaddr_in const*)from;
|
||||
auto const* const sin = (struct sockaddr_in const*)from;
|
||||
setme_addr->type = TR_AF_INET;
|
||||
setme_addr->addr.addr4.s_addr = sin->sin_addr.s_addr;
|
||||
*setme_port = sin->sin_port;
|
||||
|
@ -229,7 +229,7 @@ bool tr_address_from_sockaddr_storage(tr_address* setme_addr, tr_port* setme_por
|
|||
|
||||
if (from->ss_family == AF_INET6)
|
||||
{
|
||||
struct sockaddr_in6 const* sin6 = (struct sockaddr_in6 const*)from;
|
||||
auto const* const sin6 = (struct sockaddr_in6 const*)from;
|
||||
setme_addr->type = TR_AF_INET6;
|
||||
setme_addr->addr.addr6 = sin6->sin6_addr;
|
||||
*setme_port = sin6->sin6_port;
|
||||
|
@ -702,13 +702,13 @@ static bool isMartianAddr(struct tr_address const* a)
|
|||
{
|
||||
case TR_AF_INET:
|
||||
{
|
||||
unsigned char const* address = (unsigned char const*)&a->addr.addr4;
|
||||
auto const* const address = (unsigned char const*)&a->addr.addr4;
|
||||
return address[0] == 0 || address[0] == 127 || (address[0] & 0xE0) == 0xE0;
|
||||
}
|
||||
|
||||
case TR_AF_INET6:
|
||||
{
|
||||
unsigned char const* address = (unsigned char const*)&a->addr.addr6;
|
||||
auto const* const address = (unsigned char const*)&a->addr.addr6;
|
||||
return address[0] == 0xFF || (memcmp(address, zeroes, 15) == 0 && (address[15] == 0 || address[15] == 1));
|
||||
}
|
||||
|
||||
|
|
|
@ -871,7 +871,7 @@ static void peerCallbackFunc(tr_peer* peer, tr_peer_event const* e, void* vs)
|
|||
break;
|
||||
|
||||
default:
|
||||
TR_ASSERT_MSG(false, "unhandled peer event type %d", (int)e->eventType);
|
||||
TR_ASSERT_MSG(false, "unhandled peer event type %d", int(e->eventType));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ static bool on_handshake_done(tr_handshake_result const& result)
|
|||
|
||||
if (!result.readAnythingFromPeer)
|
||||
{
|
||||
tordbg(s, "marking peer %s as unreachable... numFails is %d", tr_atomAddrStr(atom), (int)atom->numFails);
|
||||
tordbg(s, "marking peer %s as unreachable... numFails is %d", tr_atomAddrStr(atom), int(atom->numFails));
|
||||
atom->flags2 |= MyflagUnreachable;
|
||||
}
|
||||
}
|
||||
|
@ -1145,7 +1145,7 @@ void tr_peerMgrSetSwarmIsAllSeeds(tr_torrent* tor)
|
|||
|
||||
auto* const swarm = tor->swarm;
|
||||
auto atomCount = int{};
|
||||
struct peer_atom** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &atomCount);
|
||||
auto** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &atomCount);
|
||||
for (int i = 0; i < atomCount; ++i)
|
||||
{
|
||||
atomSetSeed(swarm, atoms[i]);
|
||||
|
@ -1253,7 +1253,7 @@ void tr_peerMgrGotBadPiece(tr_torrent* tor, tr_piece_index_t pieceIndex)
|
|||
"peer %s contributed to corrupt piece (%d); now has %d strikes",
|
||||
tr_atomAddrStr(peer->atom),
|
||||
pieceIndex,
|
||||
(int)peer->strikes + 1);
|
||||
int(peer->strikes + 1));
|
||||
addStrike(s, peer);
|
||||
}
|
||||
}
|
||||
|
@ -1365,7 +1365,7 @@ int tr_peerMgrGetPeers(tr_torrent const* tor, tr_pex** setme_pex, uint8_t af, ui
|
|||
}
|
||||
else /* TR_PEERS_INTERESTING */
|
||||
{
|
||||
struct peer_atom** atomBase = (struct peer_atom**)tr_ptrArrayBase(&s->pool);
|
||||
auto** atomBase = (struct peer_atom**)tr_ptrArrayBase(&s->pool);
|
||||
int const n = tr_ptrArraySize(&s->pool);
|
||||
atoms = tr_new(struct peer_atom*, n);
|
||||
|
||||
|
@ -1385,7 +1385,7 @@ int tr_peerMgrGetPeers(tr_torrent const* tor, tr_pex** setme_pex, uint8_t af, ui
|
|||
**/
|
||||
|
||||
int const n = std::min(atomCount, maxCount);
|
||||
tr_pex* const pex = tr_new0(tr_pex, n);
|
||||
auto* const pex = tr_new0(tr_pex, n);
|
||||
tr_pex* walk = pex;
|
||||
|
||||
auto count = int{};
|
||||
|
@ -1657,7 +1657,7 @@ uint64_t tr_peerMgrGetDesiredAvailable(tr_torrent const* tor)
|
|||
return 0;
|
||||
}
|
||||
|
||||
tr_peer const** const peers = (tr_peer const**)tr_ptrArrayBase(&s->peers);
|
||||
auto const** const peers = (tr_peer const**)tr_ptrArrayBase(&s->peers);
|
||||
for (size_t i = 0; i < n_peers; ++i)
|
||||
{
|
||||
if (peers[i]->atom != nullptr && atomIsSeed(peers[i]->atom))
|
||||
|
@ -1806,9 +1806,9 @@ struct tr_peer_stat* tr_peerMgrPeerStats(tr_torrent const* tor, int* setmeCount)
|
|||
TR_ASSERT(tr_isTorrent(tor));
|
||||
TR_ASSERT(tor->swarm->manager != nullptr);
|
||||
|
||||
tr_peerMsgs** peers = (tr_peerMsgs**)tr_ptrArrayBase(&tor->swarm->peers);
|
||||
auto** peers = (tr_peerMsgs**)tr_ptrArrayBase(&tor->swarm->peers);
|
||||
int const size = tr_ptrArraySize(&tor->swarm->peers);
|
||||
tr_peer_stat* ret = tr_new0(tr_peer_stat, size);
|
||||
auto* const ret = tr_new0(tr_peer_stat, size);
|
||||
|
||||
time_t const now = tr_time();
|
||||
uint64_t const now_msec = tr_time_msec();
|
||||
|
@ -2145,8 +2145,8 @@ static void rechokeUploads(tr_swarm* s, uint64_t const now)
|
|||
auto const lock = s->manager->unique_lock();
|
||||
|
||||
int const peerCount = tr_ptrArraySize(&s->peers);
|
||||
tr_peerMsgs** peers = (tr_peerMsgs**)tr_ptrArrayBase(&s->peers);
|
||||
struct ChokeData* choke = tr_new0(struct ChokeData, peerCount);
|
||||
auto** peers = (tr_peerMsgs**)tr_ptrArrayBase(&s->peers);
|
||||
auto* const choke = tr_new0(struct ChokeData, peerCount);
|
||||
tr_session const* session = s->manager->session;
|
||||
bool const chokeAll = !s->tor->clientCanUpload();
|
||||
bool const isMaxedOut = isBandwidthMaxedOut(s->tor->bandwidth, now, TR_UP);
|
||||
|
@ -2312,7 +2312,7 @@ static bool shouldPeerBeClosed(tr_swarm const* s, tr_peer const* peer, int peerC
|
|||
/* disconnect if it's been too long since piece data has been transferred.
|
||||
* this is on a sliding scale based on number of available peers... */
|
||||
{
|
||||
int const relaxStrictnessIfFewerThanN = (int)(getMaxPeerCount(tor) * 0.9 + 0.5);
|
||||
auto const relaxStrictnessIfFewerThanN = int(getMaxPeerCount(tor) * 0.9 + 0.5);
|
||||
/* if we have >= relaxIfFewerThan, strictness is 100%.
|
||||
* if we have zero connections, strictness is 0% */
|
||||
float const strictness = peerCount >= relaxStrictnessIfFewerThanN ? 1.0 :
|
||||
|
@ -2429,7 +2429,7 @@ static void closePeer(tr_peer* peer)
|
|||
else
|
||||
{
|
||||
++atom->numFails;
|
||||
tordbg(s, "incremented atom %s numFails to %d", tr_atomAddrStr(atom), (int)atom->numFails);
|
||||
tordbg(s, "incremented atom %s numFails to %d", tr_atomAddrStr(atom), int(atom->numFails));
|
||||
}
|
||||
|
||||
tordbg(s, "removing bad peer %s", tr_atomAddrStr(peer->atom));
|
||||
|
@ -2583,7 +2583,7 @@ static void reconnectPulse(evutil_socket_t /*fd*/, short /*what*/, void* vmgr)
|
|||
enforceSessionPeerLimit(mgr->session);
|
||||
|
||||
// try to make new peer connections
|
||||
auto const max_connections_per_pulse = (int)(MaxConnectionsPerSecond * (ReconnectPeriodMsec / 1000.0));
|
||||
auto const max_connections_per_pulse = int(MaxConnectionsPerSecond * (ReconnectPeriodMsec / 1000.0));
|
||||
makeNewPeerConnections(mgr, max_connections_per_pulse);
|
||||
}
|
||||
|
||||
|
@ -2743,14 +2743,14 @@ static void atomPulse(evutil_socket_t /*fd*/, short /*what*/, void* vmgr)
|
|||
tr_swarm* s = tor->swarm;
|
||||
int const maxAtomCount = getMaxAtomCount(tor);
|
||||
auto atomCount = int{};
|
||||
peer_atom** const atoms = (peer_atom**)tr_ptrArrayPeek(&s->pool, &atomCount);
|
||||
auto** const atoms = (peer_atom**)tr_ptrArrayPeek(&s->pool, &atomCount);
|
||||
|
||||
if (atomCount > maxAtomCount) /* we've got too many atoms... time to prune */
|
||||
{
|
||||
int keepCount = 0;
|
||||
int testCount = 0;
|
||||
struct peer_atom** keep = tr_new(struct peer_atom*, atomCount);
|
||||
struct peer_atom** test = tr_new(struct peer_atom*, atomCount);
|
||||
auto** keep = tr_new(struct peer_atom*, atomCount);
|
||||
auto** test = tr_new(struct peer_atom*, atomCount);
|
||||
|
||||
/* keep the ones that are in use */
|
||||
for (int i = 0; i < atomCount; ++i)
|
||||
|
@ -2930,7 +2930,7 @@ static uint64_t getPeerCandidateScore(tr_torrent const* tor, struct peer_atom co
|
|||
static bool calculateAllSeeds(tr_swarm* swarm)
|
||||
{
|
||||
int nAtoms = 0;
|
||||
struct peer_atom** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &nAtoms);
|
||||
auto** atoms = (struct peer_atom**)tr_ptrArrayPeek(&swarm->pool, &nAtoms);
|
||||
|
||||
for (int i = 0; i < nAtoms; ++i)
|
||||
{
|
||||
|
@ -3009,7 +3009,7 @@ static std::vector<peer_candidate> getPeerCandidates(tr_session* session, size_t
|
|||
}
|
||||
|
||||
auto nAtoms = int{};
|
||||
peer_atom** atoms = (peer_atom**)tr_ptrArrayPeek(&tor->swarm->pool, &nAtoms);
|
||||
auto** atoms = (peer_atom**)tr_ptrArrayPeek(&tor->swarm->pool, &nAtoms);
|
||||
|
||||
for (int i = 0; i < nAtoms; ++i)
|
||||
{
|
||||
|
|
|
@ -547,7 +547,7 @@ private:
|
|||
|
||||
void set_active(tr_direction direction, bool active)
|
||||
{
|
||||
// TODO dbgmsg(msgs, "direction [%d] is_active [%d]", (int)direction, (int)is_active);
|
||||
// TODO dbgmsg(msgs, "direction [%d] is_active [%d]", int(direction), int(is_active));
|
||||
auto& val = is_active_[direction];
|
||||
if (val != active)
|
||||
{
|
||||
|
@ -1135,7 +1135,7 @@ static void parseLtepHandshake(tr_peerMsgsImpl* msgs, uint32_t len, struct evbuf
|
|||
/* arbitrary limit, should be more than enough */
|
||||
if (len <= 4096)
|
||||
{
|
||||
dbgmsg(msgs, "here is the handshake: [%*.*s]", TR_ARG_TUPLE((int)len, (int)len, tmp));
|
||||
dbgmsg(msgs, "here is the handshake: [%*.*s]", TR_ARG_TUPLE(int(len), int(len), tmp));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1166,14 +1166,14 @@ static void parseLtepHandshake(tr_peerMsgsImpl* msgs, uint32_t len, struct evbuf
|
|||
{
|
||||
msgs->peerSupportsPex = i != 0;
|
||||
msgs->ut_pex_id = (uint8_t)i;
|
||||
dbgmsg(msgs, "msgs->ut_pex is %d", (int)msgs->ut_pex_id);
|
||||
dbgmsg(msgs, "msgs->ut_pex is %d", int(msgs->ut_pex_id));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(sub, TR_KEY_ut_metadata, &i))
|
||||
{
|
||||
msgs->peerSupportsMetadataXfer = i != 0;
|
||||
msgs->ut_metadata_id = (uint8_t)i;
|
||||
dbgmsg(msgs, "msgs->ut_metadata_id is %d", (int)msgs->ut_metadata_id);
|
||||
dbgmsg(msgs, "msgs->ut_metadata_id is %d", int(msgs->ut_metadata_id));
|
||||
}
|
||||
|
||||
if (tr_variantDictFindInt(sub, TR_KEY_ut_holepunch, &i))
|
||||
|
@ -1201,7 +1201,7 @@ static void parseLtepHandshake(tr_peerMsgsImpl* msgs, uint32_t len, struct evbuf
|
|||
{
|
||||
pex.port = htons((uint16_t)i);
|
||||
msgs->publishClientGotPort(pex.port);
|
||||
dbgmsg(msgs, "peer's port is now %d", (int)i);
|
||||
dbgmsg(msgs, "peer's port is now %d", int(i));
|
||||
}
|
||||
|
||||
uint8_t const* addr = nullptr;
|
||||
|
@ -1235,7 +1235,7 @@ static void parseUtMetadata(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuf
|
|||
int64_t msg_type = -1;
|
||||
int64_t piece = -1;
|
||||
int64_t total_size = 0;
|
||||
char* const tmp = tr_new(char, msglen);
|
||||
auto* const tmp = tr_new(char, msglen);
|
||||
|
||||
tr_peerIoReadBytes(msgs->io, inbuf, tmp, msglen);
|
||||
char const* const msg_end = (char const*)tmp + msglen;
|
||||
|
@ -1250,7 +1250,7 @@ static void parseUtMetadata(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuf
|
|||
tr_variantFree(&dict);
|
||||
}
|
||||
|
||||
dbgmsg(msgs, "got ut_metadata msg: type %d, piece %d, total_size %d", (int)msg_type, (int)piece, (int)total_size);
|
||||
dbgmsg(msgs, "got ut_metadata msg: type %d, piece %d, total_size %d", int(msg_type), int(piece), int(total_size));
|
||||
|
||||
if (msg_type == METADATA_MSG_TYPE_REJECT)
|
||||
{
|
||||
|
@ -1391,7 +1391,7 @@ static void parseLtep(tr_peerMsgsImpl* msgs, uint32_t msglen, struct evbuffer* i
|
|||
}
|
||||
else
|
||||
{
|
||||
dbgmsg(msgs, "skipping unknown ltep message (%d)", (int)ltep_msgid);
|
||||
dbgmsg(msgs, "skipping unknown ltep message (%d)", int(ltep_msgid));
|
||||
evbuffer_drain(inbuf, msglen);
|
||||
}
|
||||
}
|
||||
|
@ -1611,7 +1611,7 @@ static ReadState readBtPiece(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, size
|
|||
req->index,
|
||||
req->offset,
|
||||
req->length,
|
||||
(int)(req->length - evbuffer_get_length(block_buffer)));
|
||||
int(req->length - evbuffer_get_length(block_buffer)));
|
||||
|
||||
if (evbuffer_get_length(block_buffer) < req->length)
|
||||
{
|
||||
|
@ -1643,7 +1643,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si
|
|||
|
||||
--msglen; /* id length */
|
||||
|
||||
dbgmsg(msgs, "got BT id %d, len %d, buffer size is %zu", (int)id, (int)msglen, inlen);
|
||||
dbgmsg(msgs, "got BT id %d, len %d, buffer size is %zu", int(id), int(msglen), inlen);
|
||||
|
||||
if (inlen < msglen)
|
||||
{
|
||||
|
@ -1652,7 +1652,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si
|
|||
|
||||
if (!messageLengthIsCorrect(msgs, id, msglen + 1))
|
||||
{
|
||||
dbgmsg(msgs, "bad packet - BT message #%d with a length of %d", (int)id, (int)msglen);
|
||||
dbgmsg(msgs, "bad packet - BT message #%d with a length of %d", int(id), int(msglen));
|
||||
msgs->publishError(EMSGSIZE);
|
||||
return READ_ERR;
|
||||
}
|
||||
|
@ -1712,7 +1712,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si
|
|||
|
||||
case BtBitfield:
|
||||
{
|
||||
uint8_t* tmp = tr_new(uint8_t, msglen);
|
||||
auto* const tmp = tr_new(uint8_t, msglen);
|
||||
dbgmsg(msgs, "got a bitfield");
|
||||
tr_peerIoReadBytes(msgs->io, inbuf, tmp, msglen);
|
||||
msgs->have.setRaw(tmp, msglen);
|
||||
|
@ -1870,7 +1870,7 @@ static ReadState readBtMessage(tr_peerMsgsImpl* msgs, struct evbuffer* inbuf, si
|
|||
break;
|
||||
|
||||
default:
|
||||
dbgmsg(msgs, "peer sent us an UNKNOWN: %d", (int)id);
|
||||
dbgmsg(msgs, "peer sent us an UNKNOWN: %d", int(id));
|
||||
tr_peerIoDrain(msgs->io, inbuf, msglen);
|
||||
break;
|
||||
}
|
||||
|
@ -1982,7 +1982,7 @@ static ReadState canRead(tr_peerIo* io, void* vmsgs, size_t* piece)
|
|||
|
||||
default:
|
||||
#ifdef TR_ENABLE_ASSERTS
|
||||
TR_ASSERT_MSG(false, "unhandled peer messages state %d", (int)msgs->state);
|
||||
TR_ASSERT_MSG(false, "unhandled peer messages state %d", int(msgs->state));
|
||||
#else
|
||||
ret = READ_ERR;
|
||||
break;
|
||||
|
@ -1990,7 +1990,7 @@ static ReadState canRead(tr_peerIo* io, void* vmsgs, size_t* piece)
|
|||
}
|
||||
}
|
||||
|
||||
dbgmsg(msgs, "canRead: ret is %d", (int)ret);
|
||||
dbgmsg(msgs, "canRead: ret is %d", int(ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -2366,8 +2366,8 @@ static void tellPeerWhatWeHave(tr_peerMsgsImpl* msgs)
|
|||
/* some peers give us error messages if we send
|
||||
more than this many peers in a single pex message
|
||||
http://wiki.theory.org/BitTorrentPeerExchangeConventions */
|
||||
#define MAX_PEX_ADDED 50
|
||||
#define MAX_PEX_DROPPED 50
|
||||
static auto constexpr MaxPexAdded = int{ 50 };
|
||||
static auto constexpr MaxPexDropped = int{ 50 };
|
||||
|
||||
struct PexDiffs
|
||||
{
|
||||
|
@ -2384,7 +2384,7 @@ static void pexAddedCb(void const* vpex, void* userData)
|
|||
auto* diffs = static_cast<PexDiffs*>(userData);
|
||||
auto const* pex = static_cast<tr_pex const*>(vpex);
|
||||
|
||||
if (diffs->addedCount < MAX_PEX_ADDED)
|
||||
if (diffs->addedCount < MaxPexAdded)
|
||||
{
|
||||
diffs->added[diffs->addedCount++] = *pex;
|
||||
diffs->elements[diffs->elementCount++] = *pex;
|
||||
|
@ -2396,7 +2396,7 @@ static constexpr void pexDroppedCb(void const* vpex, void* userData)
|
|||
auto* diffs = static_cast<PexDiffs*>(userData);
|
||||
auto const* pex = static_cast<tr_pex const*>(vpex);
|
||||
|
||||
if (diffs->droppedCount < MAX_PEX_DROPPED)
|
||||
if (diffs->droppedCount < MaxPexDropped)
|
||||
{
|
||||
diffs->dropped[diffs->droppedCount++] = *pex;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ static char* tr_buildPath(char const* first_element, ...)
|
|||
element = va_arg(vl, char const*);
|
||||
}
|
||||
va_end(vl);
|
||||
char* const buf = tr_new(char, bufLen);
|
||||
auto* const buf = tr_new(char, bufLen);
|
||||
if (buf == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
|
@ -256,19 +256,19 @@ static char const* getHomeDir(void)
|
|||
return home;
|
||||
}
|
||||
|
||||
#if defined(__APPLE__) || defined(_WIN32)
|
||||
#define RESUME_SUBDIR "Resume"
|
||||
#define TORRENT_SUBDIR "Torrents"
|
||||
#else
|
||||
#define RESUME_SUBDIR "resume"
|
||||
#define TORRENT_SUBDIR "torrents"
|
||||
#endif
|
||||
|
||||
void tr_setConfigDir(tr_session* session, std::string_view config_dir)
|
||||
{
|
||||
#if defined(__APPLE__) || defined(_WIN32)
|
||||
auto constexpr ResumeSubdir = "Resume"sv;
|
||||
auto constexpr TorrentSubdir = "Torrents"sv;
|
||||
#else
|
||||
auto constexpr ResumeSubdir = "resume"sv;
|
||||
auto constexpr TorrentSubdir = "torrents"sv;
|
||||
#endif
|
||||
|
||||
session->config_dir = config_dir;
|
||||
session->resume_dir = tr_strvPath(config_dir, RESUME_SUBDIR);
|
||||
session->torrent_dir = tr_strvPath(config_dir, TORRENT_SUBDIR);
|
||||
session->resume_dir = tr_strvPath(config_dir, ResumeSubdir);
|
||||
session->torrent_dir = tr_strvPath(config_dir, TorrentSubdir);
|
||||
tr_sys_dir_create(session->resume_dir.c_str(), TR_SYS_DIR_CREATE_PARENTS, 0777, nullptr);
|
||||
tr_sys_dir_create(session->torrent_dir.c_str(), TR_SYS_DIR_CREATE_PARENTS, 0777, nullptr);
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ static void onTimer(evutil_socket_t /*fd*/, short /*what*/, void* vshared)
|
|||
|
||||
tr_shared* tr_sharedInit(tr_session* session)
|
||||
{
|
||||
tr_shared* s = tr_new0(tr_shared, 1);
|
||||
auto* const s = tr_new0(tr_shared, 1);
|
||||
|
||||
s->session = session;
|
||||
s->isEnabled = false;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "tr-macros.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define FLOOR 32
|
||||
static auto constexpr Floor = int{ 32 };
|
||||
|
||||
int tr_lowerBound(
|
||||
void const* key,
|
||||
|
@ -89,7 +89,7 @@ int tr_ptrArrayInsert(tr_ptrArray* t, void* ptr, int pos)
|
|||
{
|
||||
if (t->n_items >= t->n_alloc)
|
||||
{
|
||||
t->n_alloc = std::max(FLOOR, t->n_alloc * 2);
|
||||
t->n_alloc = std::max(Floor, t->n_alloc * 2);
|
||||
t->items = tr_renew(void*, t->items, t->n_alloc);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,10 +52,11 @@ using namespace std::literals;
|
|||
* http://www.webappsec.org/lists/websecurity/archive/2008-04/msg00037.html */
|
||||
#define REQUIRE_SESSION_ID
|
||||
|
||||
#define MY_NAME "RPC Server"
|
||||
static char constexpr MyName[] = "RPC Server";
|
||||
|
||||
#define MY_REALM "Transmission"
|
||||
|
||||
#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__)
|
||||
#define dbgmsg(...) tr_logAddDeepNamed(MyName, __VA_ARGS__)
|
||||
|
||||
static int constexpr DeflateLevel = 6; // medium / default
|
||||
|
||||
|
@ -99,8 +100,8 @@ static auto extract_parts_from_multipart(struct evkeyvalq const* headers, struct
|
|||
{
|
||||
auto ret = std::vector<tr_mimepart>{};
|
||||
|
||||
char const* content_type = evhttp_find_header(headers, "Content-Type");
|
||||
char const* in = (char const*)evbuffer_pullup(body, -1);
|
||||
auto const* const content_type = evhttp_find_header(headers, "Content-Type");
|
||||
auto const* in = (char const*)evbuffer_pullup(body, -1);
|
||||
size_t inlen = evbuffer_get_length(body);
|
||||
|
||||
char const* boundary_key = "boundary=";
|
||||
|
@ -453,7 +454,7 @@ static void handle_rpc(struct evhttp_request* req, tr_rpc_server* server)
|
|||
|
||||
if (q != nullptr)
|
||||
{
|
||||
struct rpc_response_data* data = tr_new0(struct rpc_response_data, 1);
|
||||
auto* const data = tr_new0(struct rpc_response_data, 1);
|
||||
data->req = req;
|
||||
data->server = server;
|
||||
tr_rpc_request_exec_uri(server->session, q + 1, rpc_response_func, data);
|
||||
|
@ -746,12 +747,12 @@ static void startServer(void* vserver)
|
|||
{
|
||||
int const retry_delay = rpc_server_start_retry(server);
|
||||
|
||||
tr_logAddNamedDbg(MY_NAME, "Unable to bind to %s:%d, retrying in %d seconds", address, port, retry_delay);
|
||||
tr_logAddNamedDbg(MyName, "Unable to bind to %s:%d, retrying in %d seconds", address, port, retry_delay);
|
||||
return;
|
||||
}
|
||||
|
||||
tr_logAddNamedError(
|
||||
MY_NAME,
|
||||
MyName,
|
||||
"Unable to bind to %s:%d after %d attempts, giving up",
|
||||
address,
|
||||
port,
|
||||
|
@ -762,7 +763,7 @@ static void startServer(void* vserver)
|
|||
evhttp_set_gencb(httpd, handle_request, server);
|
||||
server->httpd = httpd;
|
||||
|
||||
tr_logAddNamedDbg(MY_NAME, "Started listening on %s:%d", address, port);
|
||||
tr_logAddNamedDbg(MyName, "Started listening on %s:%d", address, port);
|
||||
}
|
||||
|
||||
rpc_server_start_retry_cancel(server);
|
||||
|
@ -787,7 +788,7 @@ static void stopServer(tr_rpc_server* server)
|
|||
server->httpd = nullptr;
|
||||
evhttp_free(httpd);
|
||||
|
||||
tr_logAddNamedDbg(MY_NAME, "Stopped listening on %s:%d", address, port);
|
||||
tr_logAddNamedDbg(MyName, "Stopped listening on %s:%d", address, port);
|
||||
}
|
||||
|
||||
static void onEnabledChanged(void* vserver)
|
||||
|
@ -872,13 +873,13 @@ static auto parseWhitelist(std::string_view whitelist)
|
|||
if (token.find_first_of("+-"sv) != token.npos)
|
||||
{
|
||||
tr_logAddNamedInfo(
|
||||
MY_NAME,
|
||||
MyName,
|
||||
"Adding address to whitelist: %" TR_PRIsv " (And it has a '+' or '-'! Are you using an old ACL by mistake?)",
|
||||
TR_PRIsv_ARG(token));
|
||||
}
|
||||
else
|
||||
{
|
||||
tr_logAddNamedInfo(MY_NAME, "Adding address to whitelist: %" TR_PRIsv, TR_PRIsv_ARG(token));
|
||||
tr_logAddNamedInfo(MyName, "Adding address to whitelist: %" TR_PRIsv, TR_PRIsv_ARG(token));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -995,7 +996,7 @@ void tr_rpcSetAntiBruteForceThreshold(tr_rpc_server* server, int badRequests)
|
|||
static void missing_settings_key(tr_quark const q)
|
||||
{
|
||||
char const* str = tr_quark_get_string(q);
|
||||
tr_logAddNamedError(MY_NAME, _("Couldn't find settings key \"%s\""), str);
|
||||
tr_logAddNamedError(MyName, _("Couldn't find settings key \"%s\""), str);
|
||||
}
|
||||
|
||||
tr_rpc_server::tr_rpc_server(tr_session* session_in, tr_variant* settings)
|
||||
|
@ -1154,13 +1155,13 @@ tr_rpc_server::tr_rpc_server(tr_session* session_in, tr_variant* settings)
|
|||
{
|
||||
if (!tr_address_from_string(&address, std::string{ sv }.c_str()))
|
||||
{
|
||||
tr_logAddNamedError(MY_NAME, _("%" TR_PRIsv " is not a valid address"), TR_PRIsv_ARG(sv));
|
||||
tr_logAddNamedError(MyName, _("%" TR_PRIsv " is not a valid address"), TR_PRIsv_ARG(sv));
|
||||
address = tr_inaddr_any;
|
||||
}
|
||||
else if (address.type != TR_AF_INET && address.type != TR_AF_INET6)
|
||||
{
|
||||
tr_logAddNamedError(
|
||||
MY_NAME,
|
||||
MyName,
|
||||
_("%" TR_PRIsv " is not an IPv4 or IPv6 address. RPC listeners must be IPv4 or IPv6"),
|
||||
TR_PRIsv_ARG(sv));
|
||||
address = tr_inaddr_any;
|
||||
|
@ -1172,7 +1173,7 @@ tr_rpc_server::tr_rpc_server(tr_session* session_in, tr_variant* settings)
|
|||
if (this->isEnabled)
|
||||
{
|
||||
tr_logAddNamedInfo(
|
||||
MY_NAME,
|
||||
MyName,
|
||||
_("Serving RPC and Web requests on %s:%d%s"),
|
||||
tr_rpcGetBindAddress(this),
|
||||
(int)this->port,
|
||||
|
@ -1181,19 +1182,19 @@ tr_rpc_server::tr_rpc_server(tr_session* session_in, tr_variant* settings)
|
|||
|
||||
if (this->isWhitelistEnabled)
|
||||
{
|
||||
tr_logAddNamedInfo(MY_NAME, "%s", _("Whitelist enabled"));
|
||||
tr_logAddNamedInfo(MyName, "%s", _("Whitelist enabled"));
|
||||
}
|
||||
|
||||
if (this->isPasswordEnabled)
|
||||
{
|
||||
tr_logAddNamedInfo(MY_NAME, "%s", _("Password required"));
|
||||
tr_logAddNamedInfo(MyName, "%s", _("Password required"));
|
||||
}
|
||||
}
|
||||
|
||||
char const* webClientDir = tr_getWebClientDir(this->session);
|
||||
if (!tr_str_is_empty(webClientDir))
|
||||
{
|
||||
tr_logAddNamedInfo(MY_NAME, _("Serving RPC and Web requests from directory '%s'"), webClientDir);
|
||||
tr_logAddNamedInfo(MyName, _("Serving RPC and Web requests from directory '%s'"), webClientDir);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -483,7 +483,7 @@ static void addPeers(tr_torrent const* tor, tr_variant* list)
|
|||
tr_torrentPeersFree(peers, peerCount);
|
||||
}
|
||||
|
||||
static void initField(tr_torrent* const tor, tr_stat const* const st, tr_variant* const initme, tr_quark key)
|
||||
static void initField(tr_torrent const* const tor, tr_stat const* const st, tr_variant* const initme, tr_quark key)
|
||||
{
|
||||
char* str = nullptr;
|
||||
|
||||
|
@ -1135,7 +1135,7 @@ static char const* torrentSet(
|
|||
|
||||
if (tr_variantDictFindInt(args_in, TR_KEY_bandwidthPriority, &tmp))
|
||||
{
|
||||
tr_priority_t const priority = (tr_priority_t)tmp;
|
||||
auto const priority = tr_priority_t(tmp);
|
||||
|
||||
if (tr_isPriority(priority))
|
||||
{
|
||||
|
@ -2444,7 +2444,7 @@ void tr_rpc_request_exec_json(
|
|||
}
|
||||
else
|
||||
{
|
||||
struct tr_rpc_idle_data* data = tr_new0(struct tr_rpc_idle_data, 1);
|
||||
auto* const data = tr_new0(struct tr_rpc_idle_data, 1);
|
||||
data->session = session;
|
||||
data->response = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(data->response, 3);
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
using namespace std::literals;
|
||||
|
||||
#define SESSION_ID_SIZE 48
|
||||
#define SESSION_ID_DURATION_SEC (60 * 60) /* expire in an hour */
|
||||
static auto constexpr SessionIdSize = size_t{ 48 };
|
||||
static auto constexpr SessionIdDurationSec = time_t{ 60 * 60 }; /* expire in an hour */
|
||||
|
||||
struct tr_session_id
|
||||
{
|
||||
|
@ -42,16 +42,16 @@ static char* generate_new_session_id_value(void)
|
|||
char const pool[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
size_t const pool_size = sizeof(pool) - 1;
|
||||
|
||||
char* buf = tr_new(char, SESSION_ID_SIZE + 1);
|
||||
auto* buf = tr_new(char, SessionIdSize + 1);
|
||||
|
||||
tr_rand_buffer(buf, SESSION_ID_SIZE);
|
||||
tr_rand_buffer(buf, SessionIdSize);
|
||||
|
||||
for (size_t i = 0; i < SESSION_ID_SIZE; ++i)
|
||||
for (size_t i = 0; i < SessionIdSize; ++i)
|
||||
{
|
||||
buf[i] = pool[(unsigned char)buf[i] % pool_size];
|
||||
}
|
||||
|
||||
buf[SESSION_ID_SIZE] = '\0';
|
||||
buf[SessionIdSize] = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ static void destroy_session_id_lock_file(tr_sys_file_t lock_file, char const* se
|
|||
|
||||
tr_session_id_t tr_session_id_new(void)
|
||||
{
|
||||
tr_session_id_t const session_id = tr_new0(struct tr_session_id, 1);
|
||||
auto const session_id = tr_new0(struct tr_session_id, 1);
|
||||
|
||||
session_id->current_lock_file = TR_BAD_SYS_FILE;
|
||||
session_id->previous_lock_file = TR_BAD_SYS_FILE;
|
||||
|
@ -156,7 +156,7 @@ char const* tr_session_id_get_current(tr_session_id_t session_id)
|
|||
session_id->previous_lock_file = session_id->current_lock_file;
|
||||
session_id->current_lock_file = create_session_id_lock_file(session_id->current_value);
|
||||
|
||||
session_id->expires_at = now + SESSION_ID_DURATION_SEC;
|
||||
session_id->expires_at = now + SessionIdDurationSec;
|
||||
}
|
||||
|
||||
return session_id->current_value;
|
||||
|
|
|
@ -1934,13 +1934,13 @@ static bool deadlineReached(time_t const deadline)
|
|||
return time(nullptr) >= deadline;
|
||||
}
|
||||
|
||||
#define SHUTDOWN_MAX_SECONDS 20
|
||||
static auto constexpr ShutdownMaxSeconds = time_t{ 20 };
|
||||
|
||||
void tr_sessionClose(tr_session* session)
|
||||
{
|
||||
TR_ASSERT(tr_isSession(session));
|
||||
|
||||
time_t const deadline = time(nullptr) + SHUTDOWN_MAX_SECONDS;
|
||||
time_t const deadline = time(nullptr) + ShutdownMaxSeconds;
|
||||
|
||||
dbgmsg(
|
||||
"shutting down transmission session %p... now is %zu, deadline is %zu",
|
||||
|
@ -2810,7 +2810,7 @@ int tr_sessionCountQueueFreeSlots(tr_session* session, tr_direction dir)
|
|||
/* is it stalled? */
|
||||
if (stalled_enabled)
|
||||
{
|
||||
int const idle_secs = (int)difftime(now, std::max(tor->startDate, tor->activityDate));
|
||||
auto const idle_secs = int(difftime(now, std::max(tor->startDate, tor->activityDate)));
|
||||
if (idle_secs >= stalled_if_idle_for_n_seconds)
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ static void saveCumulativeStats(tr_session const* session, tr_session_stats cons
|
|||
|
||||
void tr_statsInit(tr_session* session)
|
||||
{
|
||||
struct tr_stats_handle* stats = tr_new0(struct tr_stats_handle, 1);
|
||||
auto* const stats = tr_new0(struct tr_stats_handle, 1);
|
||||
|
||||
loadCumulativeStats(session, &stats->old);
|
||||
stats->single.sessionCount = 1;
|
||||
|
|
|
@ -86,7 +86,7 @@ bool tr_torrentSetMetadataSizeHint(tr_torrent* tor, int64_t size)
|
|||
return false;
|
||||
}
|
||||
|
||||
struct tr_incomplete_metadata* m = tr_new(struct tr_incomplete_metadata, 1);
|
||||
auto* const m = tr_new(struct tr_incomplete_metadata, 1);
|
||||
|
||||
if (m == nullptr)
|
||||
{
|
||||
|
@ -115,7 +115,7 @@ bool tr_torrentSetMetadataSizeHint(tr_torrent* tor, int64_t size)
|
|||
return true;
|
||||
}
|
||||
|
||||
void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len)
|
||||
void* tr_torrentGetMetadataPiece(tr_torrent const* tor, int piece, size_t* len)
|
||||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
TR_ASSERT(piece >= 0);
|
||||
|
@ -142,7 +142,7 @@ void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len)
|
|||
|
||||
if (0 < l && l <= METADATA_PIECE_SIZE)
|
||||
{
|
||||
char* buf = tr_new(char, l);
|
||||
auto* buf = tr_new(char, l);
|
||||
auto n = uint64_t{};
|
||||
|
||||
if (tr_sys_file_read(fd, buf, l, &n, nullptr) && n == l)
|
||||
|
@ -240,19 +240,23 @@ static void tr_buildMetainfoExceptInfoDict(tr_torrent_metainfo const& tm, tr_var
|
|||
}
|
||||
}
|
||||
|
||||
static bool useNewMetainfo(tr_torrent* tor, tr_incomplete_metadata* m, tr_error** error)
|
||||
static bool useNewMetainfo(tr_torrent* tor, tr_incomplete_metadata const* m, tr_error** error)
|
||||
{
|
||||
// test the info_dict checksum
|
||||
auto const sha1 = tr_sha1(std::string_view{ m->metadata, m->metadata_size });
|
||||
bool const checksum_passed = sha1 && *sha1 == tor->infoHash();
|
||||
if (!checksum_passed)
|
||||
if (bool const checksum_passed = sha1 && *sha1 == tor->infoHash(); !checksum_passed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// checksum passed; now try to parse it as benc
|
||||
auto info_dict_v = tr_variant{};
|
||||
auto const info_dict_sv = std::string_view{ m->metadata, m->metadata_size };
|
||||
if (!tr_variantFromBuf(&info_dict_v, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, info_dict_sv, nullptr, error))
|
||||
if (!tr_variantFromBuf(
|
||||
&info_dict_v,
|
||||
TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE,
|
||||
{ m->metadata, m->metadata_size },
|
||||
nullptr,
|
||||
error))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ struct tr_torrent;
|
|||
// defined by BEP #9
|
||||
inline constexpr int METADATA_PIECE_SIZE = 1024 * 16;
|
||||
|
||||
void* tr_torrentGetMetadataPiece(tr_torrent* tor, int piece, size_t* len);
|
||||
void* tr_torrentGetMetadataPiece(tr_torrent const* tor, int piece, size_t* len);
|
||||
|
||||
void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, int len);
|
||||
|
||||
|
|
|
@ -560,8 +560,7 @@ static void tr_torrentFireMetadataCompleted(tr_torrent* tor);
|
|||
static void torrentInitFromInfoDict(tr_torrent* tor)
|
||||
{
|
||||
tor->completion = tr_completion{ tor, &tor->blockInfo() };
|
||||
auto const obfuscated = tr_sha1("req2"sv, tor->infoHash());
|
||||
if (obfuscated)
|
||||
if (auto const obfuscated = tr_sha1("req2"sv, tor->infoHash()); obfuscated)
|
||||
{
|
||||
tor->obfuscated_hash = *obfuscated;
|
||||
}
|
||||
|
@ -2151,7 +2150,7 @@ static void removeEmptyFoldersAndJunkFiles(char const* folder)
|
|||
* 2. If there are nontorrent files, don't delete them...
|
||||
* 3. ...unless the other files are "junk", such as .DS_Store
|
||||
*/
|
||||
static void deleteLocalData(tr_torrent* tor, tr_fileFunc func)
|
||||
static void deleteLocalData(tr_torrent const* tor, tr_fileFunc func)
|
||||
{
|
||||
auto files = std::vector<std::string>{};
|
||||
auto folders = std::set<std::string>{};
|
||||
|
@ -2852,7 +2851,7 @@ static bool renameArgsAreValid(char const* oldpath, char const* newname)
|
|||
strchr(newname, TR_PATH_DELIMITER) == nullptr;
|
||||
}
|
||||
|
||||
static auto renameFindAffectedFiles(tr_torrent* tor, std::string_view oldpath)
|
||||
static auto renameFindAffectedFiles(tr_torrent const* tor, std::string_view oldpath)
|
||||
{
|
||||
auto indices = std::vector<tr_file_index_t>{};
|
||||
auto oldpath_as_dir = tr_strvJoin(oldpath, "/"sv);
|
||||
|
|
|
@ -38,25 +38,25 @@ THE SOFTWARE.
|
|||
|
||||
#ifndef WITH_UTP
|
||||
|
||||
#define MY_NAME "UTP"
|
||||
static char constexpr MyName[] = "UTP";
|
||||
|
||||
#define dbgmsg(...) tr_logAddDeepNamed(MY_NAME, __VA_ARGS__)
|
||||
#define dbgmsg(...) tr_logAddDeepNamed(MyName, __VA_ARGS__)
|
||||
|
||||
void UTP_Close(struct UTPSocket* socket)
|
||||
{
|
||||
tr_logAddNamedError(MY_NAME, "UTP_Close(%p) was called.", socket);
|
||||
tr_logAddNamedError(MyName, "UTP_Close(%p) was called.", socket);
|
||||
dbgmsg("UTP_Close(%p) was called.", socket);
|
||||
}
|
||||
|
||||
void UTP_RBDrained(struct UTPSocket* socket)
|
||||
{
|
||||
tr_logAddNamedError(MY_NAME, "UTP_RBDrained(%p) was called.", socket);
|
||||
tr_logAddNamedError(MyName, "UTP_RBDrained(%p) was called.", socket);
|
||||
dbgmsg("UTP_RBDrained(%p) was called.", socket);
|
||||
}
|
||||
|
||||
bool UTP_Write(struct UTPSocket* socket, size_t count)
|
||||
{
|
||||
tr_logAddNamedError(MY_NAME, "UTP_RBDrained(%p, %zu) was called.", socket, count);
|
||||
tr_logAddNamedError(MyName, "UTP_RBDrained(%p, %zu) was called.", socket, count);
|
||||
dbgmsg("UTP_RBDrained(%p, %zu) was called.", socket, count);
|
||||
return false;
|
||||
}
|
||||
|
@ -97,14 +97,13 @@ void tr_utpSendTo(
|
|||
#else
|
||||
|
||||
/* Greg says 50ms works for them. */
|
||||
|
||||
#define UTP_INTERVAL_US 50000
|
||||
static auto constexpr UtpIntervalUs = int{ 50000 };
|
||||
|
||||
static void incoming(void* vsession, struct UTPSocket* s)
|
||||
{
|
||||
auto* session = static_cast<tr_session*>(vsession);
|
||||
struct sockaddr_storage from_storage;
|
||||
struct sockaddr* from = (struct sockaddr*)&from_storage;
|
||||
auto* const from = (struct sockaddr*)&from_storage;
|
||||
socklen_t fromlen = sizeof(from_storage);
|
||||
tr_address addr;
|
||||
tr_port port = 0;
|
||||
|
@ -149,7 +148,7 @@ static void reset_timer(tr_session* ss)
|
|||
if (tr_sessionIsUTPEnabled(ss))
|
||||
{
|
||||
sec = 0;
|
||||
usec = UTP_INTERVAL_US / 2 + tr_rand_int_weak(UTP_INTERVAL_US);
|
||||
usec = UtpIntervalUs / 2 + tr_rand_int_weak(UtpIntervalUs);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -55,7 +55,7 @@ struct tr_upnp
|
|||
|
||||
tr_upnp* tr_upnpInit(void)
|
||||
{
|
||||
tr_upnp* ret = tr_new0(tr_upnp, 1);
|
||||
auto* const ret = tr_new0(tr_upnp, 1);
|
||||
|
||||
ret->state = TR_UPNP_DISCOVER;
|
||||
ret->port = -1;
|
||||
|
|
|
@ -770,7 +770,7 @@ bool tr_utf8_validate(std::string_view sv, char const** good_end)
|
|||
|
||||
static char* strip_non_utf8(std::string_view sv)
|
||||
{
|
||||
char* ret = tr_new(char, std::size(sv) + 1);
|
||||
auto* const ret = tr_new(char, std::size(sv) + 1);
|
||||
if (ret != nullptr)
|
||||
{
|
||||
auto const it = utf8::unchecked::replace_invalid(std::data(sv), std::data(sv) + std::size(sv), ret, '?');
|
||||
|
@ -783,7 +783,7 @@ static char* to_utf8(std::string_view sv)
|
|||
{
|
||||
#ifdef HAVE_ICONV
|
||||
size_t const buflen = std::size(sv) * 4 + 10;
|
||||
char* out = tr_new(char, buflen);
|
||||
auto* const out = tr_new(char, buflen);
|
||||
|
||||
auto constexpr Encodings = std::array<char const*, 2>{ "CURRENT", "ISO-8859-15" };
|
||||
for (auto const* test_encoding : Encodings)
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
using namespace std::literals;
|
||||
|
||||
/* arbitrary value... this is much deeper than our code goes */
|
||||
#define MAX_DEPTH 64
|
||||
static auto constexpr MaxDepth = int{ 64 };
|
||||
|
||||
struct json_wrapper_data
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ struct json_wrapper_data
|
|||
* e.g. they may all be objects with the same set of keys. So when
|
||||
* a container is popped off the stack, remember its size to use as
|
||||
* a preallocation heuristic for the next container at that depth. */
|
||||
std::array<size_t, MAX_DEPTH> preallocGuess;
|
||||
std::array<size_t, MaxDepth> preallocGuess;
|
||||
};
|
||||
|
||||
static tr_variant* get_node(struct jsonsl_st* jsn)
|
||||
|
@ -106,7 +106,7 @@ static void action_callback_PUSH(
|
|||
data->stack.push_back(node);
|
||||
|
||||
int const depth = std::size(data->stack);
|
||||
size_t const n = depth < MAX_DEPTH ? data->preallocGuess[depth] : 0;
|
||||
size_t const n = depth < MaxDepth ? data->preallocGuess[depth] : 0;
|
||||
if (state->type == JSONSL_T_LIST)
|
||||
{
|
||||
tr_variantInitList(node, n);
|
||||
|
@ -307,7 +307,7 @@ static void action_callback_POP(
|
|||
int const depth = std::size(data->stack);
|
||||
auto* v = data->stack.back();
|
||||
data->stack.pop_back();
|
||||
if (depth < MAX_DEPTH)
|
||||
if (depth < MaxDepth)
|
||||
{
|
||||
data->preallocGuess[depth] = v->val.l.count;
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ int tr_variantParseJson(tr_variant& setme, int parse_opts, std::string_view benc
|
|||
|
||||
auto data = json_wrapper_data{};
|
||||
|
||||
jsonsl_t jsn = jsonsl_new(MAX_DEPTH);
|
||||
jsonsl_t jsn = jsonsl_new(MaxDepth);
|
||||
jsn->action_callback_PUSH = action_callback_PUSH;
|
||||
jsn->action_callback_POP = action_callback_POP;
|
||||
jsn->error_callback = error_callback;
|
||||
|
|
|
@ -53,14 +53,14 @@ auto tr_watchdir_generic_interval = timeval{ 10, 0 };
|
|||
static void tr_watchdir_generic_on_event(evutil_socket_t /*fd*/, short /*type*/, void* context)
|
||||
{
|
||||
auto const handle = static_cast<tr_watchdir_t>(context);
|
||||
tr_watchdir_generic* const backend = BACKEND_UPCAST(tr_watchdir_get_backend(handle));
|
||||
auto* const backend = BACKEND_UPCAST(tr_watchdir_get_backend(handle));
|
||||
|
||||
tr_watchdir_scan(handle, &backend->dir_entries);
|
||||
}
|
||||
|
||||
static void tr_watchdir_generic_free(tr_watchdir_backend* backend_base)
|
||||
{
|
||||
tr_watchdir_generic* const backend = BACKEND_UPCAST(backend_base);
|
||||
auto* const backend = BACKEND_UPCAST(backend_base);
|
||||
|
||||
if (backend == nullptr)
|
||||
{
|
||||
|
|
|
@ -71,7 +71,7 @@ static void tr_watchdir_inotify_on_event(struct bufferevent* event, void* contex
|
|||
#endif
|
||||
struct inotify_event ev;
|
||||
size_t name_size = NAME_MAX + 1;
|
||||
char* name = tr_new(char, name_size);
|
||||
auto* name = tr_new(char, name_size);
|
||||
|
||||
/* Read the size of the struct excluding name into buf. Guaranteed to have at
|
||||
least sizeof(ev) available */
|
||||
|
@ -121,7 +121,7 @@ static void tr_watchdir_inotify_on_event(struct bufferevent* event, void* contex
|
|||
|
||||
static void tr_watchdir_inotify_free(tr_watchdir_backend* backend_base)
|
||||
{
|
||||
tr_watchdir_inotify* const backend = BACKEND_UPCAST(backend_base);
|
||||
auto* const backend = BACKEND_UPCAST(backend_base);
|
||||
|
||||
if (backend == nullptr)
|
||||
{
|
||||
|
|
|
@ -1037,7 +1037,7 @@ void DetailsDialog::refreshUI()
|
|||
for (Peer const& peer : peers)
|
||||
{
|
||||
QString const key = id_str + QLatin1Char(':') + peer.address;
|
||||
PeerItem* item = static_cast<PeerItem*>(peers_.value(key, nullptr));
|
||||
auto* item = static_cast<PeerItem*>(peers_.value(key, nullptr));
|
||||
|
||||
if (item == nullptr) // new peer has connected
|
||||
{
|
||||
|
|
|
@ -2375,7 +2375,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
}
|
||||
else if (stepMode == MODE_TORRENT_GET)
|
||||
{
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variant* args;
|
||||
tr_variant* fields;
|
||||
tr_variantInitDict(top, 3);
|
||||
|
@ -2807,11 +2807,10 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
tr_variant* args;
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "torrent-set-location"sv);
|
||||
args = tr_variantDictAddDict(top, Arguments, 3);
|
||||
tr_variant* args = tr_variantDictAddDict(top, Arguments, 3);
|
||||
tr_variantDictAddStr(args, TR_KEY_location, optarg);
|
||||
tr_variantDictAddBool(args, TR_KEY_move, false);
|
||||
addIdArg(args, id, nullptr);
|
||||
|
@ -2825,7 +2824,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
{
|
||||
case 920: /* session-info */
|
||||
{
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "session-get"sv);
|
||||
tr_variantDictAddInt(top, TR_KEY_tag, TAG_SESSION);
|
||||
|
@ -2841,7 +2840,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "torrent-start"sv);
|
||||
addIdArg(tr_variantDictAddDict(top, Arguments, 1), id, nullptr);
|
||||
|
@ -2859,7 +2858,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "torrent-stop"sv);
|
||||
addIdArg(tr_variantDictAddDict(top, Arguments, 1), id, nullptr);
|
||||
|
@ -2878,7 +2877,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
|
||||
case 850:
|
||||
{
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 1);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "session-close"sv);
|
||||
status |= flush(rpcurl, &top);
|
||||
|
@ -2887,7 +2886,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
|
||||
case 963:
|
||||
{
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 1);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "blocklist-update"sv);
|
||||
status |= flush(rpcurl, &top);
|
||||
|
@ -2896,7 +2895,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
|
||||
case 921:
|
||||
{
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "session-stats"sv);
|
||||
tr_variantDictAddInt(top, TR_KEY_tag, TAG_STATS);
|
||||
|
@ -2906,7 +2905,7 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
|
||||
case 962:
|
||||
{
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "port-test"sv);
|
||||
tr_variantDictAddInt(top, TR_KEY_tag, TAG_PORTTEST);
|
||||
|
@ -2916,15 +2915,13 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
|
||||
case 600:
|
||||
{
|
||||
tr_variant* top;
|
||||
|
||||
if (tset != nullptr)
|
||||
{
|
||||
addIdArg(tr_variantDictFind(tset, Arguments), id, nullptr);
|
||||
status |= flush(rpcurl, &tset);
|
||||
}
|
||||
|
||||
top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "torrent-reannounce"sv);
|
||||
addIdArg(tr_variantDictAddDict(top, Arguments, 1), id, nullptr);
|
||||
|
@ -2934,15 +2931,13 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
|
||||
case 'v':
|
||||
{
|
||||
tr_variant* top;
|
||||
|
||||
if (tset != nullptr)
|
||||
{
|
||||
addIdArg(tr_variantDictFind(tset, Arguments), id, nullptr);
|
||||
status |= flush(rpcurl, &tset);
|
||||
}
|
||||
|
||||
top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "torrent-verify"sv);
|
||||
addIdArg(tr_variantDictAddDict(top, Arguments, 1), id, nullptr);
|
||||
|
@ -2953,11 +2948,10 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
case 'r':
|
||||
case 840:
|
||||
{
|
||||
tr_variant* args;
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "torrent-remove"sv);
|
||||
args = tr_variantDictAddDict(top, Arguments, 2);
|
||||
auto* args = tr_variantDictAddDict(top, Arguments, 2);
|
||||
tr_variantDictAddBool(args, TR_KEY_delete_local_data, c == 840);
|
||||
addIdArg(args, id, nullptr);
|
||||
status |= flush(rpcurl, &top);
|
||||
|
@ -2966,11 +2960,10 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
|||
|
||||
case 960:
|
||||
{
|
||||
tr_variant* args;
|
||||
tr_variant* top = tr_new0(tr_variant, 1);
|
||||
auto* top = tr_new0(tr_variant, 1);
|
||||
tr_variantInitDict(top, 2);
|
||||
tr_variantDictAddStrView(top, TR_KEY_method, "torrent-set-location"sv);
|
||||
args = tr_variantDictAddDict(top, Arguments, 3);
|
||||
auto* args = tr_variantDictAddDict(top, Arguments, 3);
|
||||
tr_variantDictAddStr(args, TR_KEY_location, optarg);
|
||||
tr_variantDictAddBool(args, TR_KEY_move, true);
|
||||
addIdArg(args, id, nullptr);
|
||||
|
@ -3013,7 +3006,7 @@ static bool parsePortString(char const* s, int* port)
|
|||
errno = 0;
|
||||
|
||||
char* end = nullptr;
|
||||
int const i = (int)strtol(s, &end, 10);
|
||||
auto const i = int(strtol(s, &end, 10));
|
||||
bool const ok = (end != nullptr) && (*end == '\0') && (errno == 0);
|
||||
if (ok)
|
||||
{
|
||||
|
|
|
@ -263,7 +263,7 @@ void doScrape(tr_torrent_metainfo const& metainfo)
|
|||
|
||||
// print it out
|
||||
tr_variant top;
|
||||
char const* begin = (char const*)evbuffer_pullup(buf, -1);
|
||||
auto* const begin = (char const*)evbuffer_pullup(buf, -1);
|
||||
auto sv = std::string_view{ begin, evbuffer_get_length(buf) };
|
||||
if (!tr_variantFromBuf(&top, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, sv))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue