Use explicit boolean conversions

This commit is contained in:
Mike Gelfand 2019-07-14 15:40:41 +03:00
parent 16d385e4c7
commit 10cdd7f790
40 changed files with 268 additions and 267 deletions

View File

@ -75,25 +75,25 @@ static char const* torrentPath = NULL;
static struct tr_option const options[] =
{
{ 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL },
{ 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL },
{ 'd', "downlimit", "Set max download speed in "SPEED_K_STR, "d", 1, "<speed>" },
{ 'D', "no-downlimit", "Don't limit the download speed", "D", 0, NULL },
{ 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL },
{ 'f', "finish", "Run a script when the torrent finishes", "f", 1, "<script>" },
{ 'g', "config-dir", "Where to find configuration files", "g", 1, "<path>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL },
{ 'M', "no-portmap", "Disable portmapping", "M", 0, NULL },
{ 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", 1, "<port>" },
{ 't', "tos", "Peer socket TOS (0 to 255, default=" TR_DEFAULT_PEER_SOCKET_TOS_STR ")", "t", 1, "<tos>" },
{ 'u', "uplimit", "Set max upload speed in "SPEED_K_STR, "u", 1, "<speed>" },
{ 'U', "no-uplimit", "Don't limit the upload speed", "U", 0, NULL },
{ 'v', "verify", "Verify the specified torrent", "v", 0, NULL },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 'w', "download-dir", "Where to save downloaded data", "w", 1, "<path>" },
{ 0, NULL, NULL, NULL, 0, NULL }
{ 'b', "blocklist", "Enable peer blocklists", "b", false, NULL },
{ 'B', "no-blocklist", "Disable peer blocklists", "B", false, NULL },
{ 'd', "downlimit", "Set max download speed in "SPEED_K_STR, "d", true, "<speed>" },
{ 'D', "no-downlimit", "Don't limit the download speed", "D", false, NULL },
{ 910, "encryption-required", "Encrypt all peer connections", "er", false, NULL },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, NULL },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, NULL },
{ 'f', "finish", "Run a script when the torrent finishes", "f", true, "<script>" },
{ 'g', "config-dir", "Where to find configuration files", "g", true, "<path>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, NULL },
{ 'M', "no-portmap", "Disable portmapping", "M", false, NULL },
{ 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", true, "<port>" },
{ 't', "tos", "Peer socket TOS (0 to 255, default=" TR_DEFAULT_PEER_SOCKET_TOS_STR ")", "t", true, "<tos>" },
{ 'u', "uplimit", "Set max upload speed in "SPEED_K_STR, "u", true, "<speed>" },
{ 'U', "no-uplimit", "Don't limit the upload speed", "U", false, NULL },
{ 'v', "verify", "Verify the specified torrent", "v", false, NULL },
{ 'V', "version", "Show version number and exit", "V", false, NULL },
{ 'w', "download-dir", "Where to save downloaded data", "w", true, "<path>" },
{ 0, NULL, NULL, NULL, false, NULL }
};
static char const* getUsage(void)

View File

@ -98,53 +98,53 @@ static char const* getUsage(void)
static struct tr_option const options[] =
{
{ 'a', "allowed", "Allowed IP addresses. (Default: " TR_DEFAULT_RPC_WHITELIST ")", "a", 1, "<list>" },
{ 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL },
{ 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL },
{ 'c', "watch-dir", "Where to watch for new .torrent files", "c", 1, "<directory>" },
{ 'C', "no-watch-dir", "Disable the watch-dir", "C", 0, NULL },
{ 941, "incomplete-dir", "Where to store new torrents until they're complete", NULL, 1, "<directory>" },
{ 942, "no-incomplete-dir", "Don't store incomplete torrents in a different location", NULL, 0, NULL },
{ 'd', "dump-settings", "Dump the settings and exit", "d", 0, NULL },
{ 'e', "logfile", "Dump the log messages to this filename", "e", 1, "<filename>" },
{ 'f', "foreground", "Run in the foreground instead of daemonizing", "f", 0, NULL },
{ 'g', "config-dir", "Where to look for configuration files", "g", 1, "<path>" },
{ 'p', "port", "RPC port (Default: " TR_DEFAULT_RPC_PORT_STR ")", "p", 1, "<port>" },
{ 't', "auth", "Require authentication", "t", 0, NULL },
{ 'T', "no-auth", "Don't require authentication", "T", 0, NULL },
{ 'u', "username", "Set username for authentication", "u", 1, "<username>" },
{ 'v', "password", "Set password for authentication", "v", 1, "<password>" },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 810, "log-error", "Show error messages", NULL, 0, NULL },
{ 811, "log-info", "Show error and info messages", NULL, 0, NULL },
{ 812, "log-debug", "Show error, info, and debug messages", NULL, 0, NULL },
{ 'w', "download-dir", "Where to save downloaded data", "w", 1, "<path>" },
{ 800, "paused", "Pause all torrents on startup", NULL, 0, NULL },
{ 'o', "dht", "Enable distributed hash tables (DHT)", "o", 0, NULL },
{ 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", 0, NULL },
{ 'y', "lpd", "Enable local peer discovery (LPD)", "y", 0, NULL },
{ 'Y', "no-lpd", "Disable local peer discovery (LPD)", "Y", 0, NULL },
{ 830, "utp", "Enable uTP for peer connections", NULL, 0, NULL },
{ 831, "no-utp", "Disable uTP for peer connections", NULL, 0, NULL },
{ 'P', "peerport", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "P", 1, "<port>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL },
{ 'M', "no-portmap", "Disable portmapping", "M", 0, NULL },
{ 'L', "peerlimit-global", "Maximum overall number of peers (Default: " TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ")", "L", 1,
{ 'a', "allowed", "Allowed IP addresses. (Default: " TR_DEFAULT_RPC_WHITELIST ")", "a", true, "<list>" },
{ 'b', "blocklist", "Enable peer blocklists", "b", false, NULL },
{ 'B', "no-blocklist", "Disable peer blocklists", "B", false, NULL },
{ 'c', "watch-dir", "Where to watch for new .torrent files", "c", true, "<directory>" },
{ 'C', "no-watch-dir", "Disable the watch-dir", "C", false, NULL },
{ 941, "incomplete-dir", "Where to store new torrents until they're complete", NULL, true, "<directory>" },
{ 942, "no-incomplete-dir", "Don't store incomplete torrents in a different location", NULL, false, NULL },
{ 'd', "dump-settings", "Dump the settings and exit", "d", false, NULL },
{ 'e', "logfile", "Dump the log messages to this filename", "e", true, "<filename>" },
{ 'f', "foreground", "Run in the foreground instead of daemonizing", "f", false, NULL },
{ 'g', "config-dir", "Where to look for configuration files", "g", true, "<path>" },
{ 'p', "port", "RPC port (Default: " TR_DEFAULT_RPC_PORT_STR ")", "p", true, "<port>" },
{ 't', "auth", "Require authentication", "t", false, NULL },
{ 'T', "no-auth", "Don't require authentication", "T", false, NULL },
{ 'u', "username", "Set username for authentication", "u", true, "<username>" },
{ 'v', "password", "Set password for authentication", "v", true, "<password>" },
{ 'V', "version", "Show version number and exit", "V", false, NULL },
{ 810, "log-error", "Show error messages", NULL, false, NULL },
{ 811, "log-info", "Show error and info messages", NULL, false, NULL },
{ 812, "log-debug", "Show error, info, and debug messages", NULL, false, NULL },
{ 'w', "download-dir", "Where to save downloaded data", "w", true, "<path>" },
{ 800, "paused", "Pause all torrents on startup", NULL, false, NULL },
{ 'o', "dht", "Enable distributed hash tables (DHT)", "o", false, NULL },
{ 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", false, NULL },
{ 'y', "lpd", "Enable local peer discovery (LPD)", "y", false, NULL },
{ 'Y', "no-lpd", "Disable local peer discovery (LPD)", "Y", false, NULL },
{ 830, "utp", "Enable uTP for peer connections", NULL, false, NULL },
{ 831, "no-utp", "Disable uTP for peer connections", NULL, false, NULL },
{ 'P', "peerport", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "P", true, "<port>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, NULL },
{ 'M', "no-portmap", "Disable portmapping", "M", false, NULL },
{ 'L', "peerlimit-global", "Maximum overall number of peers (Default: " TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ")", "L", true,
"<limit>" },
{ 'l', "peerlimit-torrent", "Maximum number of peers per torrent (Default: " TR_DEFAULT_PEER_LIMIT_TORRENT_STR ")", "l", 1,
"<limit>" },
{ 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL },
{ 'i', "bind-address-ipv4", "Where to listen for peer connections", "i", 1, "<ipv4 addr>" },
{ 'I', "bind-address-ipv6", "Where to listen for peer connections", "I", 1, "<ipv6 addr>" },
{ 'r', "rpc-bind-address", "Where to listen for RPC connections", "r", 1, "<ip addr>" },
{ 'l', "peerlimit-torrent", "Maximum number of peers per torrent (Default: " TR_DEFAULT_PEER_LIMIT_TORRENT_STR ")", "l",
true, "<limit>" },
{ 910, "encryption-required", "Encrypt all peer connections", "er", false, NULL },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, NULL },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, NULL },
{ 'i', "bind-address-ipv4", "Where to listen for peer connections", "i", true, "<ipv4 addr>" },
{ 'I', "bind-address-ipv6", "Where to listen for peer connections", "I", true, "<ipv6 addr>" },
{ 'r', "rpc-bind-address", "Where to listen for RPC connections", "r", true, "<ip addr>" },
{ 953, "global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio",
"gsr", 1, "ratio" },
"gsr", true, "ratio" },
{ 954, "no-global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio",
"GSR", 0, NULL },
{ 'x', "pid-file", "Enable PID file", "x", 1, "<pid-file>" },
{ 0, NULL, NULL, NULL, 0, NULL }
"GSR", false, NULL },
{ 'x', "pid-file", "Enable PID file", "x", true, "<pid-file>" },
{ 0, NULL, NULL, NULL, false, NULL }
};
static bool reopen_log_file(char const* filename)

View File

@ -1771,7 +1771,7 @@ static gboolean core_read_rpc_response_idle(void* vresponse)
if (data != NULL)
{
if (data->response_func)
if (data->response_func != NULL)
{
(*data->response_func)(data->core, response, data->response_func_user_data);
}

View File

@ -1547,7 +1547,7 @@ static void on_scrape_done(tr_scrape_response const* response, void* vsession)
}
}
if (announcer)
if (announcer != NULL)
{
++announcer->slotsAvailable;
}

View File

@ -378,7 +378,7 @@ void tr_bitfieldSetRaw(tr_bitfield* b, void const* bits, size_t byte_count, bool
TR_ASSERT(excess_bit_count >= 0);
TR_ASSERT(excess_bit_count <= 7);
if (excess_bit_count)
if (excess_bit_count != 0)
{
b->bits[b->alloc_count - 1] &= 0xff << excess_bit_count;
}

View File

@ -120,7 +120,7 @@ void tr_cpBlockAdd(tr_completion* cp, tr_block_index_t block)
cp->sizeNow += tr_torBlockCountBytes(tor, block);
cp->haveValidIsDirty = true;
cp->sizeWhenDoneIsDirty |= tor->info.pieces[piece].dnd;
cp->sizeWhenDoneIsDirty = cp->sizeWhenDoneIsDirty || tor->info.pieces[piece].dnd;
}
}

View File

@ -311,7 +311,7 @@ tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t
p = BN_bin2bn(prime_num, prime_num_length, NULL);
g = BN_bin2bn(generator_num, generator_num_length, NULL);
if (!check_pointer(p) || !check_pointer(g) || !DH_set0_pqg(handle, p, NULL, g))
if (!check_pointer(p) || !check_pointer(g) || DH_set0_pqg(handle, p, NULL, g) == 0)
{
BN_free(p);
BN_free(g);

View File

@ -395,7 +395,7 @@ static void ensureSessionFdInfoExists(tr_session* session)
/* set the open-file limit to the largest safe size wrt FD_SETSIZE */
struct rlimit limit;
if (!getrlimit(RLIMIT_NOFILE, &limit))
if (getrlimit(RLIMIT_NOFILE, &limit) == 0)
{
int const old_limit = (int)limit.rlim_cur;
int const new_limit = MIN(limit.rlim_max, FD_SETSIZE);

View File

@ -487,28 +487,28 @@ tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, tr_
{
native_flags |= O_RDWR;
}
else if (flags & TR_SYS_FILE_READ)
else if ((flags & TR_SYS_FILE_READ) != 0)
{
native_flags |= O_RDONLY;
}
else if (flags & TR_SYS_FILE_WRITE)
else if ((flags & TR_SYS_FILE_WRITE) != 0)
{
native_flags |= O_WRONLY;
}
native_flags |=
(flags & TR_SYS_FILE_CREATE ? O_CREAT : 0) |
(flags & TR_SYS_FILE_CREATE_NEW ? O_CREAT | O_EXCL : 0) |
(flags & TR_SYS_FILE_APPEND ? O_APPEND : 0) |
(flags & TR_SYS_FILE_TRUNCATE ? O_TRUNC : 0) |
(flags & TR_SYS_FILE_SEQUENTIAL ? O_SEQUENTIAL : 0) |
((flags & TR_SYS_FILE_CREATE) != 0 ? O_CREAT : 0) |
((flags & TR_SYS_FILE_CREATE_NEW) != 0 ? O_CREAT | O_EXCL : 0) |
((flags & TR_SYS_FILE_APPEND) != 0 ? O_APPEND : 0) |
((flags & TR_SYS_FILE_TRUNCATE) != 0 ? O_TRUNC : 0) |
((flags & TR_SYS_FILE_SEQUENTIAL) != 0 ? O_SEQUENTIAL : 0) |
O_BINARY | O_LARGEFILE | O_CLOEXEC;
ret = open(path, native_flags, permissions);
if (ret != TR_BAD_SYS_FILE)
{
if (flags & TR_SYS_FILE_SEQUENTIAL)
if ((flags & TR_SYS_FILE_SEQUENTIAL) != 0)
{
set_file_for_single_pass(ret);
}

View File

@ -370,7 +370,7 @@ static uint32_t getCryptoSelect(tr_handshake const* handshake, uint32_t crypto_p
for (int i = 0; i < nChoices; ++i)
{
if (crypto_provide & choices[i])
if ((crypto_provide & choices[i]) != 0)
{
return choices[i];
}
@ -837,7 +837,7 @@ static ReadState readCryptoProvide(tr_handshake* handshake, struct evbuffer* inb
obfuscatedTorrentHash[i] = req2[i] ^ req3[i];
}
if ((tor = tr_torrentFindFromObfuscatedHash(handshake->session, obfuscatedTorrentHash)))
if ((tor = tr_torrentFindFromObfuscatedHash(handshake->session, obfuscatedTorrentHash)) != NULL)
{
bool const clientIsSeed = tr_torrentIsSeed(tor);
bool const peerIsSeed = tr_peerMgrPeerIsSeed(tor, tr_peerIoGetAddress(handshake->io, NULL));

View File

@ -163,7 +163,7 @@ static void* tr_list_remove_node(tr_list** list, tr_list* node)
*list = next;
}
data = node ? node->data : NULL;
data = node != NULL ? node->data : NULL;
node_free(node);
return data;
}

View File

@ -28,7 +28,7 @@ static int myQueueLength = 0;
#ifndef _WIN32
/* make null versions of these win32 functions */
static inline int IsDebuggerPresent(void)
static inline bool IsDebuggerPresent(void)
{
return false;
}
@ -162,7 +162,7 @@ bool tr_logGetDeepEnabled(void)
if (deepLoggingIsActive < 0)
{
deepLoggingIsActive = IsDebuggerPresent() || tr_logGetFile() != TR_BAD_SYS_FILE;
deepLoggingIsActive = (int8_t)(IsDebuggerPresent() || tr_logGetFile() != TR_BAD_SYS_FILE);
}
return deepLoggingIsActive != 0;

View File

@ -281,7 +281,7 @@ static uint8_t* getHashInfo(tr_metainfo_builder* b)
return NULL;
}
while (totalRemain)
while (totalRemain != 0)
{
TR_ASSERT(b->pieceIndex < b->pieceCount);

View File

@ -1109,7 +1109,7 @@ static inline void processBuffer(tr_crypto* crypto, struct evbuffer* buffer, siz
TR_ASSERT(size >= iovec.iov_len);
size -= iovec.iov_len;
}
while (!evbuffer_ptr_set(buffer, &pos, iovec.iov_len, EVBUFFER_PTR_ADD));
while (evbuffer_ptr_set(buffer, &pos, iovec.iov_len, EVBUFFER_PTR_ADD) == 0);
TR_ASSERT(size == 0);
}

View File

@ -328,7 +328,7 @@ static inline void swarmUnlock(tr_swarm* swarm)
#ifdef TR_ENABLE_ASSERTS
static inline int swarmIsLocked(tr_swarm const* swarm)
static inline bool swarmIsLocked(tr_swarm const* swarm)
{
return tr_sessionIsLocked(swarm->manager->session);
}
@ -410,8 +410,8 @@ static bool peerIsInUse(tr_swarm const* cs, struct peer_atom const* atom)
TR_ASSERT(swarmIsLocked(s));
return atom->peer != NULL || getExistingHandshake(&s->outgoingHandshakes, &atom->addr) ||
getExistingHandshake(&s->manager->incomingHandshakes, &atom->addr);
return atom->peer != NULL || getExistingHandshake(&s->outgoingHandshakes, &atom->addr) != NULL ||
getExistingHandshake(&s->manager->incomingHandshakes, &atom->addr) != NULL;
}
static inline bool replicationExists(tr_swarm const* s)
@ -587,10 +587,10 @@ static bool isAtomBlocklisted(tr_session* session, struct peer_atom* atom)
{
if (atom->blocklisted < 0)
{
atom->blocklisted = tr_sessionIsAddressBlocked(session, &atom->addr);
atom->blocklisted = (int8_t)tr_sessionIsAddressBlocked(session, &atom->addr);
}
return atom->blocklisted;
return atom->blocklisted != 0;
}
/***
@ -3564,7 +3564,7 @@ static void closePeer(tr_swarm* s, tr_peer* peer)
/* if we transferred piece data, then they might be good peers,
so reset their `numFails' weight to zero. otherwise we connected
to them fruitlessly, so mark it as another fail */
if (atom->piece_data_time)
if (atom->piece_data_time != 0)
{
tordbg(s, "resetting atom %s numFails to 0", tr_atomAddrStr(atom));
atom->numFails = 0;

View File

@ -186,7 +186,7 @@ struct tr_peerMsgs
int prefetchCount;
int is_active[2];
bool is_active[2];
/* how long the outMessages batch should be allowed to grow before
* it's flushed -- some messages (like requests >:) should be sent
@ -402,7 +402,7 @@ static void protocolSendAllowedFast(tr_peerMsgs* msgs, uint32_t pieceIndex)
#endif
static void protocolSendChoke(tr_peerMsgs* msgs, int choke)
static void protocolSendChoke(tr_peerMsgs* msgs, bool choke)
{
struct evbuffer* out = msgs->outMessages;
@ -908,7 +908,7 @@ static void sendLtepHandshake(tr_peerMsgs* msgs)
}
tr_variantInitDict(&val, 8);
tr_variantDictAddInt(&val, TR_KEY_e, getSession(msgs)->encryptionMode != TR_CLEAR_PREFERRED);
tr_variantDictAddBool(&val, TR_KEY_e, getSession(msgs)->encryptionMode != TR_CLEAR_PREFERRED);
if (ipv6 != NULL)
{
@ -922,7 +922,7 @@ static void sendLtepHandshake(tr_peerMsgs* msgs)
tr_variantDictAddInt(&val, TR_KEY_p, tr_sessionGetPublicPeerPort(getSession(msgs)));
tr_variantDictAddInt(&val, TR_KEY_reqq, REQQ);
tr_variantDictAddInt(&val, TR_KEY_upload_only, tr_torrentIsSeed(msgs->torrent));
tr_variantDictAddBool(&val, TR_KEY_upload_only, tr_torrentIsSeed(msgs->torrent));
tr_variantDictAddQuark(&val, TR_KEY_v, version_quark);
if (allow_metadata_xfer || allow_pex)
@ -1656,7 +1656,7 @@ static int readBtMessage(tr_peerMsgs* msgs, struct evbuffer* inbuf, size_t inlen
if (msgs->dht_port > 0)
{
tr_dhtAddNode(getSession(msgs), tr_peerAddress(&msgs->peer), msgs->dht_port, 0);
tr_dhtAddNode(getSession(msgs), tr_peerAddress(&msgs->peer), msgs->dht_port, false);
}
break;
@ -1817,7 +1817,7 @@ static int clientGotBlock(tr_peerMsgs* msgs, struct evbuffer* data, struct peer_
return 0;
}
static int peerPulse(void* vmsgs);
static void peerPulse(void* vmsgs);
static void didWrite(tr_peerIo* io, size_t bytesWritten, bool wasPieceData, void* vmsgs)
{
@ -1878,7 +1878,7 @@ static ReadState canRead(tr_peerIo* io, void* vmsgs, size_t* piece)
return ret;
}
int tr_peerMsgsIsReadingBlock(tr_peerMsgs const* msgs, tr_block_index_t block)
bool tr_peerMsgsIsReadingBlock(tr_peerMsgs const* msgs, tr_block_index_t block)
{
if (msgs->state != AWAITING_BT_PIECE)
{
@ -2105,7 +2105,7 @@ static size_t fillOutputBuffer(tr_peerMsgs* msgs, time_t now)
if (requestIsValid(msgs, &req) && tr_torrentPieceIsComplete(msgs->torrent, req.index))
{
int err;
bool err;
uint32_t const msglen = 4 + 1 + 4 + 4 + req.length;
struct evbuffer* out;
struct evbuffer_iovec iovec[1];
@ -2120,21 +2120,23 @@ static size_t fillOutputBuffer(tr_peerMsgs* msgs, time_t now)
evbuffer_reserve_space(out, req.length, iovec, 1);
err = tr_cacheReadBlock(getSession(msgs)->cache, msgs->torrent, req.index, req.offset, req.length,
iovec[0].iov_base);
iovec[0].iov_base) != 0;
iovec[0].iov_len = req.length;
evbuffer_commit_space(out, iovec, 1);
/* check the piece if it needs checking... */
if (err == 0 && tr_torrentPieceNeedsCheck(msgs->torrent, req.index))
if (!err && tr_torrentPieceNeedsCheck(msgs->torrent, req.index))
{
if ((err = !tr_torrentCheckPiece(msgs->torrent, req.index)) != 0)
err = !tr_torrentCheckPiece(msgs->torrent, req.index);
if (err)
{
tr_torrentSetLocalError(msgs->torrent, _("Please Verify Local Data! Piece #%zu is corrupt."),
(size_t)req.index);
}
}
if (err != 0)
if (err)
{
if (fext)
{
@ -2154,7 +2156,7 @@ static size_t fillOutputBuffer(tr_peerMsgs* msgs, time_t now)
evbuffer_free(out);
if (err != 0)
if (err)
{
bytesWritten = 0;
msgs = NULL;
@ -2185,7 +2187,7 @@ static size_t fillOutputBuffer(tr_peerMsgs* msgs, time_t now)
return bytesWritten;
}
static int peerPulse(void* vmsgs)
static void peerPulse(void* vmsgs)
{
tr_peerMsgs* msgs = vmsgs;
time_t const now = tr_time();
@ -2204,8 +2206,6 @@ static int peerPulse(void* vmsgs)
break;
}
}
return true; /* loop forever */
}
void tr_peerMsgsPulse(tr_peerMsgs* msgs)
@ -2755,7 +2755,7 @@ tr_peerMsgs* tr_peerMsgsNew(struct tr_torrent* torrent, struct tr_peerIo* io, tr
/* Only send PORT over IPv6 when the IPv6 DHT is running (BEP-32). */
struct tr_address const* addr = tr_peerIoGetAddress(m->io, NULL);
if (addr->type == TR_AF_INET || tr_globalIPv6())
if (addr->type == TR_AF_INET || tr_globalIPv6() != NULL)
{
protocolSendPort(m, tr_dhtPort(torrent->session));
}

View File

@ -58,7 +58,7 @@ bool tr_peerMsgsIsIncomingConnection(tr_peerMsgs const* msgs);
void tr_peerMsgsSetChoke(tr_peerMsgs* msgs, bool peerIsChoked);
int tr_peerMsgsIsReadingBlock(tr_peerMsgs const* msgs, tr_block_index_t block);
bool tr_peerMsgsIsReadingBlock(tr_peerMsgs const* msgs, tr_block_index_t block);
void tr_peerMsgsSetInterested(tr_peerMsgs* msgs, bool clientIsInterested);

View File

@ -159,7 +159,7 @@ static void saveDND(tr_variant* dict, tr_torrent const* tor)
for (tr_file_index_t i = 0; i < n; ++i)
{
tr_variantListAddInt(list, inf->files[i].dnd ? 1 : 0);
tr_variantListAddBool(list, inf->files[i].dnd);
}
}
@ -171,7 +171,7 @@ static uint64_t loadDND(tr_variant* dict, tr_torrent* tor)
if (tr_variantDictFindList(dict, TR_KEY_dnd, &list) && tr_variantListSize(list) == n)
{
int64_t tmp;
bool tmp;
tr_file_index_t* dl = tr_new(tr_file_index_t, n);
tr_file_index_t* dnd = tr_new(tr_file_index_t, n);
tr_file_index_t dlCount = 0;
@ -179,7 +179,7 @@ static uint64_t loadDND(tr_variant* dict, tr_torrent* tor)
for (tr_file_index_t i = 0; i < n; ++i)
{
if (tr_variantGetInt(tr_variantListChild(list, i), &tmp) && tmp != 0)
if (tr_variantGetBool(tr_variantListChild(list, i), &tmp) && tmp)
{
dnd[dndCount++] = i;
}

View File

@ -489,7 +489,7 @@ static void addTrackerStats(tr_tracker_stat const* st, int n, tr_variant* list)
tr_variantDictAddInt(d, TR_KEY_lastScrapeStartTime, s->lastScrapeStartTime);
tr_variantDictAddBool(d, TR_KEY_lastScrapeSucceeded, s->lastScrapeSucceeded);
tr_variantDictAddInt(d, TR_KEY_lastScrapeTime, s->lastScrapeTime);
tr_variantDictAddInt(d, TR_KEY_lastScrapeTimedOut, s->lastScrapeTimedOut);
tr_variantDictAddBool(d, TR_KEY_lastScrapeTimedOut, s->lastScrapeTimedOut);
tr_variantDictAddInt(d, TR_KEY_leecherCount, s->leecherCount);
tr_variantDictAddInt(d, TR_KEY_nextAnnounceTime, s->nextAnnounceTime);
tr_variantDictAddInt(d, TR_KEY_nextScrapeTime, s->nextScrapeTime);
@ -552,7 +552,7 @@ static void addField(tr_torrent* const tor, tr_info const* const inf, tr_stat co
break;
case TR_KEY_comment:
tr_variantDictAddStr(d, key, inf->comment ? inf->comment : "");
tr_variantDictAddStr(d, key, inf->comment != NULL ? inf->comment : "");
break;
case TR_KEY_corruptEver:
@ -560,7 +560,7 @@ static void addField(tr_torrent* const tor, tr_info const* const inf, tr_stat co
break;
case TR_KEY_creator:
tr_variantDictAddStr(d, key, inf->creator ? inf->creator : "");
tr_variantDictAddStr(d, key, inf->creator != NULL ? inf->creator : "");
break;
case TR_KEY_dateCreated:
@ -1082,7 +1082,7 @@ static char const* setFileDLs(tr_torrent* tor, bool do_download, tr_variant* lis
}
}
if (fileCount)
if (fileCount != 0)
{
tr_torrentSetFileDLs(tor, files, fileCount, do_download);
}

View File

@ -2021,7 +2021,7 @@ static void sessionCloseImpl(void* vsession)
sessionCloseImplStart(session);
}
static int deadlineReached(time_t const deadline)
static bool deadlineReached(time_t const deadline)
{
return time(NULL) >= deadline;
}
@ -2393,7 +2393,7 @@ bool tr_sessionIsPortForwardingEnabled(tr_session const* session)
****
***/
static int tr_stringEndsWith(char const* str, char const* end)
static bool tr_stringEndsWith(char const* str, char const* end)
{
size_t const slen = strlen(str);
size_t const elen = strlen(end);

View File

@ -133,7 +133,7 @@ void tr_statsInit(tr_session* session)
static struct tr_stats_handle* getStats(tr_session const* session)
{
return session ? session->sessionStats : NULL;
return session != NULL ? session->sessionStats : NULL;
}
void tr_statsSaveDirty(tr_session* session)

View File

@ -141,7 +141,7 @@ bool tr_spawn_async(char* const* cmd, char* const* env, char const* work_dir, tr
return false;
}
if (fcntl(pipe_fds[1], F_SETFD, fcntl(pipe_fds[1], F_GETFD) | FD_CLOEXEC))
if (fcntl(pipe_fds[1], F_SETFD, fcntl(pipe_fds[1], F_GETFD) | FD_CLOEXEC) == -1)
{
set_system_error(error, errno, "Call to fcntl()");
close(pipe_fds[0]);

View File

@ -86,7 +86,7 @@ int tr_ctorSetMetainfo(tr_ctor* ctor, uint8_t const* metainfo, size_t len)
clearMetainfo(ctor);
err = tr_variantFromBenc(&ctor->metainfo, metainfo, len);
ctor->isSet_metainfo = !err;
ctor->isSet_metainfo = err == 0;
return err;
}

View File

@ -305,7 +305,7 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in
memset(&info, 0, sizeof(tr_info));
success = tr_metainfoParse(tor->session, &newMetainfo, &info, &hasInfo, &infoDictLength);
if (success && !tr_getBlockSize(info.pieceSize))
if (success && tr_getBlockSize(info.pieceSize) == 0)
{
tr_torrentSetLocalError(tor, "%s", _("Magnet torrent's metadata is not usable"));
tr_metainfoFree(&info);

View File

@ -94,7 +94,7 @@ tr_torrent* tr_torrentFindFromHashString(tr_session* session, char const* str)
while ((tor = tr_torrentNext(session, tor)) != NULL)
{
if (!evutil_ascii_strcasecmp(str, tor->info.hashString))
if (evutil_ascii_strcasecmp(str, tor->info.hashString) == 0)
{
return tor;
}
@ -1099,7 +1099,7 @@ static tr_parse_result torrentParseImpl(tr_ctor const* ctor, tr_info* setmeInfo,
result = TR_PARSE_ERR;
}
if (didParse && hasInfo && !tr_getBlockSize(setmeInfo->pieceSize))
if (didParse && hasInfo && tr_getBlockSize(setmeInfo->pieceSize) == 0)
{
result = TR_PARSE_ERR;
}
@ -1417,7 +1417,7 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
s->haveUnchecked = tr_torrentHaveTotal(tor) - s->haveValid;
s->desiredAvailable = tr_peerMgrGetDesiredAvailable(tor);
s->ratio = tr_getRatio(s->uploadedEver, s->downloadedEver ? s->downloadedEver : s->haveValid);
s->ratio = tr_getRatio(s->uploadedEver, s->downloadedEver != 0 ? s->downloadedEver : s->haveValid);
seedRatioApplies = tr_torrentGetSeedRatioBytes(tor, &seedRatioBytesLeft, &seedRatioBytesGoal);
@ -2421,13 +2421,13 @@ tr_priority_t* tr_torrentGetFilePriorities(tr_torrent const* tor)
*** File DND
**/
static void setFileDND(tr_torrent* tor, tr_file_index_t fileIndex, int doDownload)
static void setFileDND(tr_torrent* tor, tr_file_index_t fileIndex, bool doDownload)
{
int8_t const dnd = !doDownload;
bool const dnd = !doDownload;
tr_piece_index_t firstPiece;
int8_t firstPieceDND;
bool firstPieceDND;
tr_piece_index_t lastPiece;
int8_t lastPieceDND;
bool lastPieceDND;
tr_file* file = &tor->info.files[fileIndex];
file->dnd = dnd;

View File

@ -681,12 +681,12 @@ static void callback(void* ignore UNUSED, int event, unsigned char const* info_h
if (event == DHT_EVENT_SEARCH_DONE)
{
tr_logAddTorInfo(tor, "%s", "IPv4 DHT announce done");
tor->dhtAnnounceInProgress = 0;
tor->dhtAnnounceInProgress = false;
}
else
{
tr_logAddTorInfo(tor, "%s", "IPv6 DHT announce done");
tor->dhtAnnounce6InProgress = 0;
tor->dhtAnnounce6InProgress = false;
}
}
}
@ -761,14 +761,14 @@ void tr_dhtUpkeep(tr_session* session)
if (tor->dhtAnnounceAt <= now)
{
int const rc = tr_dhtAnnounce(tor, AF_INET, 1);
int const rc = tr_dhtAnnounce(tor, AF_INET, true);
tor->dhtAnnounceAt = now + ((rc == 0) ? 5 + tr_rand_int_weak(5) : 25 * 60 + tr_rand_int_weak(3 * 60));
}
if (tor->dhtAnnounce6At <= now)
{
int const rc = tr_dhtAnnounce(tor, AF_INET6, 1);
int const rc = tr_dhtAnnounce(tor, AF_INET6, true);
tor->dhtAnnounce6At = now + ((rc == 0) ? 5 + tr_rand_int_weak(5) : 25 * 60 + tr_rand_int_weak(3 * 60));
}

View File

@ -13,14 +13,14 @@
static struct tr_option const options[] =
{
{ 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", 0, NULL },
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", 1, "<file>" },
{ 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", 1, "<size in KiB>" },
{ 'c', "comment", "Add a comment", "c", 1, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", 1, "<url>" },
{ 'q', "pooka", "Pooka", "pk", 0, NULL },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 0, NULL, NULL, NULL, 0, NULL }
{ 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", false, NULL },
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", true, "<file>" },
{ 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", true, "<size in KiB>" },
{ 'c', "comment", "Add a comment", "c", true, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", true, "<url>" },
{ 'q', "pooka", "Pooka", "pk", false, NULL },
{ 'V', "version", "Show version number and exit", "V", false, NULL },
{ 0, NULL, NULL, NULL, false, NULL }
};
static int run_test(int argc, char const** argv, int expected_n, int* expected_c, char const** expected_optarg)

View File

@ -129,7 +129,7 @@ void tr_getopt_usage(char const* progName, char const* description, struct tr_op
help.longName = "help";
help.description = "Display this help page and exit";
help.shortName = "h";
help.has_arg = 0;
help.has_arg = false;
maxWidth(&help, &longWidth, &shortWidth, &argWidth);
if (description == NULL)

View File

@ -27,7 +27,7 @@ typedef struct tr_option
char const* longName; /* --long-form */
char const* description; /* option's description for tr_getopt_usage() */
char const* shortName; /* short form */
int has_arg; /* 0 for no argument, 1 for argument */
bool has_arg; /* 0 for no argument, 1 for argument */
char const* argName; /* argument's description for tr_getopt_usage() */
}
tr_option;

View File

@ -1574,8 +1574,8 @@ typedef struct tr_file
uint64_t length; /* Length of the file, in bytes */
char* name; /* Path to the file */
int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */
int8_t dnd; /* "do not download" flag */
int8_t is_renamed; /* true if we're using a different path from the one in the metainfo; ie, if the user has renamed it */
bool dnd; /* "do not download" flag */
bool is_renamed; /* true if we're using a different path from the one in the metainfo; ie, if the user has renamed it */
tr_piece_index_t firstPiece; /* We need pieces [firstPiece... */
tr_piece_index_t lastPiece; /* ...lastPiece] to dl this file */
uint64_t offset; /* file begins at the torrent's nth byte */
@ -1588,7 +1588,7 @@ typedef struct tr_piece
time_t timeChecked; /* the last time we tested this piece */
uint8_t hash[SHA_DIGEST_LENGTH]; /* pieces hash */
int8_t priority; /* TR_PRI_HIGH, _NORMAL, or _LOW */
int8_t dnd; /* "do not download" flag */
bool dnd; /* "do not download" flag */
}
tr_piece;

View File

@ -259,7 +259,7 @@ int tr_upnpPulse(tr_upnp* handle, int port, bool isEnabled, bool doPortCheck)
if (handle->urls.controlURL == NULL)
{
handle->isMapped = 0;
handle->isMapped = false;
}
else
{

View File

@ -636,7 +636,7 @@ bool tr_str_has_suffix(char const* str, char const* suffix)
return false;
}
return !evutil_ascii_strncasecmp(str + str_len - suffix_len, suffix, suffix_len);
return evutil_ascii_strncasecmp(str + str_len - suffix_len, suffix, suffix_len) == 0;
}
/****

View File

@ -976,7 +976,7 @@ static void tr_variantListCopy(tr_variant* target, tr_variant const* src)
{
if (tr_variantIsBool(val))
{
bool boolVal = 0;
bool boolVal = false;
tr_variantGetBool(val, &boolVal);
tr_variantListAddBool(target, boolVal);
}

View File

@ -367,7 +367,7 @@ static void web_response_func(tr_session* session, bool did_connect UNUSED, bool
tr_webseed* w;
tr_torrent* tor;
struct tr_webseed_task* t = vtask;
int const success = (response_code == 206);
bool const success = response_code == 206;
if (t->dead)
{
@ -486,7 +486,7 @@ static void task_request_next_chunk(struct tr_webseed_task* t)
file = &inf->files[file_index];
this_pass = MIN(remain, file->length - file_offset);
if (!urls[file_index])
if (urls[file_index] == NULL)
{
urls[file_index] = evbuffer_free_to_str(make_url(t->webseed, file), NULL);
}

View File

@ -46,14 +46,14 @@ QLatin1String const MY_READABLE_NAME("transmission-qt");
tr_option const opts[] =
{
{ 'g', "config-dir", "Where to look for configuration files", "g", 1, "<path>" },
{ 'm', "minimized", "Start minimized in system tray", "m", 0, nullptr },
{ 'p', "port", "Port to use when connecting to an existing session", "p", 1, "<port>" },
{ 'r', "remote", "Connect to an existing session at the specified hostname", "r", 1, "<host>" },
{ 'u', "username", "Username to use when connecting to an existing session", "u", 1, "<username>" },
{ 'v', "version", "Show version number and exit", "v", 0, nullptr },
{ 'w', "password", "Password to use when connecting to an existing session", "w", 1, "<password>" },
{ 0, nullptr, nullptr, nullptr, 0, nullptr }
{ 'g', "config-dir", "Where to look for configuration files", "g", true, "<path>" },
{ 'm', "minimized", "Start minimized in system tray", "m", false, nullptr },
{ 'p', "port", "Port to use when connecting to an existing session", "p", true, "<port>" },
{ 'r', "remote", "Connect to an existing session at the specified hostname", "r", true, "<host>" },
{ 'u', "username", "Username to use when connecting to an existing session", "u", true, "<username>" },
{ 'v', "version", "Show version number and exit", "v", false, nullptr },
{ 'w', "password", "Password to use when connecting to an existing session", "w", true, "<password>" },
{ 0, nullptr, nullptr, nullptr, false, nullptr }
};
char const* getUsage()

View File

@ -1360,7 +1360,7 @@ void MainWindow::removeTorrents(bool const deleteFiles)
tr("Delete these %Ln torrent(s)' downloaded files?", nullptr, count);
}
if (!incomplete && !connected)
if (incomplete == 0 && connected == 0)
{
secondary_text = count == 1 ?
tr("Once removed, continuing the transfer will require the torrent file or magnet link.") :

View File

@ -34,13 +34,13 @@ static uint32_t piecesize_kib = 0;
static tr_option options[] =
{
{ 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", 0, NULL },
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", 1, "<file>" },
{ 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", 1, "<size in KiB>" },
{ 'c', "comment", "Add a comment", "c", 1, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", 1, "<url>" },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 0, NULL, NULL, NULL, 0, NULL }
{ 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", false, NULL },
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", true, "<file>" },
{ 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", true, "<size in KiB>" },
{ 'c', "comment", "Add a comment", "c", true, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", true, "<url>" },
{ 'V', "version", "Show version number and exit", "V", false, NULL },
{ 0, NULL, NULL, NULL, false, NULL }
};
static char const* getUsage(void)

View File

@ -30,11 +30,11 @@ static char const* replace[2] = { NULL, NULL };
static tr_option options[] =
{
{ 'a', "add", "Add a tracker's announce URL", "a", 1, "<url>" },
{ 'd', "delete", "Delete a tracker's announce URL", "d", 1, "<url>" },
{ 'r', "replace", "Search and replace a substring in the announce URLs", "r", 1, "<old> <new>" },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 0, NULL, NULL, NULL, 0, NULL }
{ 'a', "add", "Add a tracker's announce URL", "a", true, "<url>" },
{ 'd', "delete", "Delete a tracker's announce URL", "d", true, "<url>" },
{ 'r', "replace", "Search and replace a substring in the announce URLs", "r", true, "<old> <new>" },
{ 'V', "version", "Show version number and exit", "V", false, NULL },
{ 0, NULL, NULL, NULL, false, NULL }
};
static char const* getUsage(void)

View File

@ -258,97 +258,98 @@ static char const* getUsage(void)
static tr_option opts[] =
{
{ 'a', "add", "Add torrent files by filename or URL", "a", 0, NULL },
{ 970, "alt-speed", "Use the alternate Limits", "as", 0, NULL },
{ 971, "no-alt-speed", "Don't use the alternate Limits", "AS", 0, NULL },
{ 972, "alt-speed-downlimit", "max alternate download speed (in "SPEED_K_STR ")", "asd", 1, "<speed>" },
{ 973, "alt-speed-uplimit", "max alternate upload speed (in "SPEED_K_STR ")", "asu", 1, "<speed>" },
{ 974, "alt-speed-scheduler", "Use the scheduled on/off times", "asc", 0, NULL },
{ 975, "no-alt-speed-scheduler", "Don't use the scheduled on/off times", "ASC", 0, NULL },
{ 976, "alt-speed-time-begin", "Time to start using the alt speed limits (in hhmm)", NULL, 1, "<time>" },
{ 977, "alt-speed-time-end", "Time to stop using the alt speed limits (in hhmm)", NULL, 1, "<time>" },
{ 978, "alt-speed-days", "Numbers for any/all days of the week - eg. \"1-7\"", NULL, 1, "<days>" },
{ 963, "blocklist-update", "Blocklist update", NULL, 0, NULL },
{ 'c', "incomplete-dir", "Where to store new torrents until they're complete", "c", 1, "<dir>" },
{ 'C', "no-incomplete-dir", "Don't store incomplete torrents in a different location", "C", 0, NULL },
{ 'b', "debug", "Print debugging information", "b", 0, NULL },
{ 'd', "downlimit", "Set the max download speed in "SPEED_K_STR " for the current torrent(s) or globally", "d", 1,
{ 'a', "add", "Add torrent files by filename or URL", "a", false, NULL },
{ 970, "alt-speed", "Use the alternate Limits", "as", false, NULL },
{ 971, "no-alt-speed", "Don't use the alternate Limits", "AS", false, NULL },
{ 972, "alt-speed-downlimit", "max alternate download speed (in "SPEED_K_STR ")", "asd", true, "<speed>" },
{ 973, "alt-speed-uplimit", "max alternate upload speed (in "SPEED_K_STR ")", "asu", true, "<speed>" },
{ 974, "alt-speed-scheduler", "Use the scheduled on/off times", "asc", false, NULL },
{ 975, "no-alt-speed-scheduler", "Don't use the scheduled on/off times", "ASC", false, NULL },
{ 976, "alt-speed-time-begin", "Time to start using the alt speed limits (in hhmm)", NULL, true, "<time>" },
{ 977, "alt-speed-time-end", "Time to stop using the alt speed limits (in hhmm)", NULL, true, "<time>" },
{ 978, "alt-speed-days", "Numbers for any/all days of the week - eg. \"1-7\"", NULL, true, "<days>" },
{ 963, "blocklist-update", "Blocklist update", NULL, false, NULL },
{ 'c', "incomplete-dir", "Where to store new torrents until they're complete", "c", true, "<dir>" },
{ 'C', "no-incomplete-dir", "Don't store incomplete torrents in a different location", "C", false, NULL },
{ 'b', "debug", "Print debugging information", "b", false, NULL },
{ 'd', "downlimit", "Set the max download speed in "SPEED_K_STR " for the current torrent(s) or globally", "d", true,
"<speed>" },
{ 'D', "no-downlimit", "Disable max download speed for the current torrent(s) or globally", "D", 0, NULL },
{ 'e', "cache", "Set the maximum size of the session's memory cache (in " MEM_M_STR ")", "e", 1, "<size>" },
{ 910, "encryption-required", "Encrypt all peer connections", "er", 0, NULL },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", 0, NULL },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", 0, NULL },
{ 850, "exit", "Tell the transmission session to shut down", NULL, 0, NULL },
{ 940, "files", "List the current torrent(s)' files", "f", 0, NULL },
{ 'g', "get", "Mark files for download", "g", 1, "<files>" },
{ 'G', "no-get", "Mark files for not downloading", "G", 1, "<files>" },
{ 'i', "info", "Show the current torrent(s)' details", "i", 0, NULL },
{ 940, "info-files", "List the current torrent(s)' files", "if", 0, NULL },
{ 941, "info-peers", "List the current torrent(s)' peers", "ip", 0, NULL },
{ 942, "info-pieces", "List the current torrent(s)' pieces", "ic", 0, NULL },
{ 943, "info-trackers", "List the current torrent(s)' trackers", "it", 0, NULL },
{ 920, "session-info", "Show the session's details", "si", 0, NULL },
{ 921, "session-stats", "Show the session's statistics", "st", 0, NULL },
{ 'l', "list", "List all torrents", "l", 0, NULL },
{ 'L', "labels", "Set the current torrents' labels", "L", 1, "<label[,label...]>" },
{ 960, "move", "Move current torrent's data to a new folder", NULL, 1, "<path>" },
{ 961, "find", "Tell Transmission where to find a torrent's data", NULL, 1, "<path>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", 0, NULL },
{ 'M', "no-portmap", "Disable portmapping", "M", 0, NULL },
{ 'n', "auth", "Set username and password", "n", 1, "<user:pw>" },
{ 810, "authenv", "Set authentication info from the TR_AUTH environment variable (user:pw)", "ne", 0, NULL },
{ 'N', "netrc", "Set authentication info from a .netrc file", "N", 1, "<file>" },
{ 820, "ssl", "Use SSL when talking to daemon", NULL, 0, NULL },
{ 'o', "dht", "Enable distributed hash tables (DHT)", "o", 0, NULL },
{ 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", 0, NULL },
{ 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", 1, "<port>" },
{ 962, "port-test", "Port testing", "pt", 0, NULL },
{ 'P', "random-port", "Random port for incoming peers", "P", 0, NULL },
{ 900, "priority-high", "Try to download these file(s) first", "ph", 1, "<files>" },
{ 901, "priority-normal", "Try to download these file(s) normally", "pn", 1, "<files>" },
{ 902, "priority-low", "Try to download these file(s) last", "pl", 1, "<files>" },
{ 700, "bandwidth-high", "Give this torrent first chance at available bandwidth", "Bh", 0, NULL },
{ 701, "bandwidth-normal", "Give this torrent bandwidth left over by high priority torrents", "Bn", 0, NULL },
{ 702, "bandwidth-low", "Give this torrent bandwidth left over by high and normal priority torrents", "Bl", 0, NULL },
{ 600, "reannounce", "Reannounce the current torrent(s)", NULL, 0, NULL },
{ 'r', "remove", "Remove the current torrent(s)", "r", 0, NULL },
{ 930, "peers", "Set the maximum number of peers for the current torrent(s) or globally", "pr", 1, "<max>" },
{ 840, "remove-and-delete", "Remove the current torrent(s) and delete local data", "rad", 0, NULL },
{ 800, "torrent-done-script", "Specify a script to run when a torrent finishes", NULL, 1, "<file>" },
{ 801, "no-torrent-done-script", "Don't run a script when torrents finish", NULL, 0, NULL },
{ 950, "seedratio", "Let the current torrent(s) seed until a specific ratio", "sr", 1, "ratio" },
{ 951, "seedratio-default", "Let the current torrent(s) use the global seedratio settings", "srd", 0, NULL },
{ 952, "no-seedratio", "Let the current torrent(s) seed regardless of ratio", "SR", 0, NULL },
{ 'D', "no-downlimit", "Disable max download speed for the current torrent(s) or globally", "D", false, NULL },
{ 'e', "cache", "Set the maximum size of the session's memory cache (in " MEM_M_STR ")", "e", true, "<size>" },
{ 910, "encryption-required", "Encrypt all peer connections", "er", false, NULL },
{ 911, "encryption-preferred", "Prefer encrypted peer connections", "ep", false, NULL },
{ 912, "encryption-tolerated", "Prefer unencrypted peer connections", "et", false, NULL },
{ 850, "exit", "Tell the transmission session to shut down", NULL, false, NULL },
{ 940, "files", "List the current torrent(s)' files", "f", false, NULL },
{ 'g', "get", "Mark files for download", "g", true, "<files>" },
{ 'G', "no-get", "Mark files for not downloading", "G", true, "<files>" },
{ 'i', "info", "Show the current torrent(s)' details", "i", false, NULL },
{ 940, "info-files", "List the current torrent(s)' files", "if", false, NULL },
{ 941, "info-peers", "List the current torrent(s)' peers", "ip", false, NULL },
{ 942, "info-pieces", "List the current torrent(s)' pieces", "ic", false, NULL },
{ 943, "info-trackers", "List the current torrent(s)' trackers", "it", false, NULL },
{ 920, "session-info", "Show the session's details", "si", false, NULL },
{ 921, "session-stats", "Show the session's statistics", "st", false, NULL },
{ 'l', "list", "List all torrents", "l", false, NULL },
{ 'L', "labels", "Set the current torrents' labels", "L", true, "<label[,label...]>" },
{ 960, "move", "Move current torrent's data to a new folder", NULL, true, "<path>" },
{ 961, "find", "Tell Transmission where to find a torrent's data", NULL, true, "<path>" },
{ 'm', "portmap", "Enable portmapping via NAT-PMP or UPnP", "m", false, NULL },
{ 'M', "no-portmap", "Disable portmapping", "M", false, NULL },
{ 'n', "auth", "Set username and password", "n", true, "<user:pw>" },
{ 810, "authenv", "Set authentication info from the TR_AUTH environment variable (user:pw)", "ne", false, NULL },
{ 'N', "netrc", "Set authentication info from a .netrc file", "N", true, "<file>" },
{ 820, "ssl", "Use SSL when talking to daemon", NULL, false, NULL },
{ 'o', "dht", "Enable distributed hash tables (DHT)", "o", false, NULL },
{ 'O', "no-dht", "Disable distributed hash tables (DHT)", "O", false, NULL },
{ 'p', "port", "Port for incoming peers (Default: " TR_DEFAULT_PEER_PORT_STR ")", "p", true, "<port>" },
{ 962, "port-test", "Port testing", "pt", false, NULL },
{ 'P', "random-port", "Random port for incoming peers", "P", false, NULL },
{ 900, "priority-high", "Try to download these file(s) first", "ph", true, "<files>" },
{ 901, "priority-normal", "Try to download these file(s) normally", "pn", true, "<files>" },
{ 902, "priority-low", "Try to download these file(s) last", "pl", true, "<files>" },
{ 700, "bandwidth-high", "Give this torrent first chance at available bandwidth", "Bh", false, NULL },
{ 701, "bandwidth-normal", "Give this torrent bandwidth left over by high priority torrents", "Bn", false, NULL },
{ 702, "bandwidth-low", "Give this torrent bandwidth left over by high and normal priority torrents", "Bl", false, NULL },
{ 600, "reannounce", "Reannounce the current torrent(s)", NULL, false, NULL },
{ 'r', "remove", "Remove the current torrent(s)", "r", false, NULL },
{ 930, "peers", "Set the maximum number of peers for the current torrent(s) or globally", "pr", true, "<max>" },
{ 840, "remove-and-delete", "Remove the current torrent(s) and delete local data", "rad", false, NULL },
{ 800, "torrent-done-script", "Specify a script to run when a torrent finishes", NULL, true, "<file>" },
{ 801, "no-torrent-done-script", "Don't run a script when torrents finish", NULL, false, NULL },
{ 950, "seedratio", "Let the current torrent(s) seed until a specific ratio", "sr", true, "ratio" },
{ 951, "seedratio-default", "Let the current torrent(s) use the global seedratio settings", "srd", false, NULL },
{ 952, "no-seedratio", "Let the current torrent(s) seed regardless of ratio", "SR", false, NULL },
{ 953, "global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio",
"gsr", 1, "ratio" },
"gsr", true, "ratio" },
{ 954, "no-global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio",
"GSR", 0, NULL },
{ 710, "tracker-add", "Add a tracker to a torrent", "td", 1, "<tracker>" },
{ 712, "tracker-remove", "Remove a tracker from a torrent", "tr", 1, "<trackerId>" },
{ 's', "start", "Start the current torrent(s)", "s", 0, NULL },
{ 'S', "stop", "Stop the current torrent(s)", "S", 0, NULL },
{ 't', "torrent", "Set the current torrent(s)", "t", 1, "<torrent>" },
{ 990, "start-paused", "Start added torrents paused", NULL, 0, NULL },
{ 991, "no-start-paused", "Start added torrents unpaused", NULL, 0, NULL },
{ 992, "trash-torrent", "Delete torrents after adding", NULL, 0, NULL },
{ 993, "no-trash-torrent", "Do not delete torrents after adding", NULL, 0, NULL },
{ 984, "honor-session", "Make the current torrent(s) honor the session limits", "hl", 0, NULL },
{ 985, "no-honor-session", "Make the current torrent(s) not honor the session limits", "HL", 0, NULL },
{ 'u', "uplimit", "Set the max upload speed in "SPEED_K_STR " for the current torrent(s) or globally", "u", 1, "<speed>" },
{ 'U', "no-uplimit", "Disable max upload speed for the current torrent(s) or globally", "U", 0, NULL },
{ 830, "utp", "Enable uTP for peer connections", NULL, 0, NULL },
{ 831, "no-utp", "Disable uTP for peer connections", NULL, 0, NULL },
{ 'v', "verify", "Verify the current torrent(s)", "v", 0, NULL },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
"GSR", false, NULL },
{ 710, "tracker-add", "Add a tracker to a torrent", "td", true, "<tracker>" },
{ 712, "tracker-remove", "Remove a tracker from a torrent", "tr", true, "<trackerId>" },
{ 's', "start", "Start the current torrent(s)", "s", false, NULL },
{ 'S', "stop", "Stop the current torrent(s)", "S", false, NULL },
{ 't', "torrent", "Set the current torrent(s)", "t", true, "<torrent>" },
{ 990, "start-paused", "Start added torrents paused", NULL, false, NULL },
{ 991, "no-start-paused", "Start added torrents unpaused", NULL, false, NULL },
{ 992, "trash-torrent", "Delete torrents after adding", NULL, false, NULL },
{ 993, "no-trash-torrent", "Do not delete torrents after adding", NULL, false, NULL },
{ 984, "honor-session", "Make the current torrent(s) honor the session limits", "hl", false, NULL },
{ 985, "no-honor-session", "Make the current torrent(s) not honor the session limits", "HL", false, NULL },
{ 'u', "uplimit", "Set the max upload speed in "SPEED_K_STR " for the current torrent(s) or globally", "u", true,
"<speed>" },
{ 'U', "no-uplimit", "Disable max upload speed for the current torrent(s) or globally", "U", false, NULL },
{ 830, "utp", "Enable uTP for peer connections", NULL, false, NULL },
{ 831, "no-utp", "Disable uTP for peer connections", NULL, false, NULL },
{ 'v', "verify", "Verify the current torrent(s)", "v", false, NULL },
{ 'V', "version", "Show version number and exit", "V", false, NULL },
{ 'w', "download-dir", "When used in conjunction with --add, set the new torrent's download folder. "
"Otherwise, set the default download folder", "w", 1, "<path>" },
{ 'x', "pex", "Enable peer exchange (PEX)", "x", 0, NULL },
{ 'X', "no-pex", "Disable peer exchange (PEX)", "X", 0, NULL },
{ 'y', "lpd", "Enable local peer discovery (LPD)", "y", 0, NULL },
{ 'Y', "no-lpd", "Disable local peer discovery (LPD)", "Y", 0, NULL },
{ 941, "peer-info", "List the current torrent(s)' peers", "pi", 0, NULL },
{ 0, NULL, NULL, NULL, 0, NULL }
"Otherwise, set the default download folder", "w", true, "<path>" },
{ 'x', "pex", "Enable peer exchange (PEX)", "x", false, NULL },
{ 'X', "no-pex", "Disable peer exchange (PEX)", "X", false, NULL },
{ 'y', "lpd", "Enable local peer discovery (LPD)", "y", false, NULL },
{ 'Y', "no-lpd", "Disable local peer discovery (LPD)", "Y", false, NULL },
{ 941, "peer-info", "List the current torrent(s)' peers", "pi", false, NULL },
{ 0, NULL, NULL, NULL, false, NULL }
};
static void showUsage(void)
@ -525,7 +526,7 @@ static int getOptMode(int val)
}
}
static bool debug = 0;
static bool debug = false;
static char* auth = NULL;
static char* netrc = NULL;
static char* sessionId = NULL;
@ -1275,7 +1276,7 @@ static void printFileList(tr_variant* top)
int64_t have;
int64_t length;
int64_t priority;
int64_t wanted;
bool wanted;
char const* filename;
tr_variant* file = tr_variantListChild(files, j);
@ -1283,7 +1284,7 @@ static void printFileList(tr_variant* top)
tr_variantDictFindStr(file, TR_KEY_name, &filename, NULL) &&
tr_variantDictFindInt(file, TR_KEY_bytesCompleted, &have) &&
tr_variantGetInt(tr_variantListChild(priorities, j), &priority) &&
tr_variantGetInt(tr_variantListChild(wanteds, j), &wanted))
tr_variantGetBool(tr_variantListChild(wanteds, j), &wanted))
{
char sizestr[64];
double percent = (double)have / length;
@ -1376,7 +1377,7 @@ static void printPiecesImpl(uint8_t const* raw, size_t rawlen, size_t j)
{
for (int e = 0; i < j && e < 8; ++e, ++i)
{
printf("%c", str[k] & (1 << (7 - e)) ? '1' : '0');
printf("%c", (str[k] & (1 << (7 - e))) != 0 ? '1' : '0');
}
printf(" ");

View File

@ -30,11 +30,11 @@
static tr_option options[] =
{
{ 'm', "magnet", "Give a magnet link for the specified torrent", "m", 0, NULL },
{ 's', "scrape", "Ask the torrent's trackers how many peers are in the torrent's swarm", "s", 0, NULL },
{ 'u', "unsorted", "Do not sort files by name", "u", 0, NULL },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
{ 0, NULL, NULL, NULL, 0, NULL }
{ 'm', "magnet", "Give a magnet link for the specified torrent", "m", false, NULL },
{ 's', "scrape", "Ask the torrent's trackers how many peers are in the torrent's swarm", "s", false, NULL },
{ 'u', "unsorted", "Do not sort files by name", "u", false, NULL },
{ 'V', "version", "Show version number and exit", "V", false, NULL },
{ 0, NULL, NULL, NULL, false, NULL }
};
static char const* getUsage(void)