Update to Uncrustify 0.68.1

Tweak a few rules in the process. Now all code in cli, daemon, gtk,
libtransmission, qt, and utils is properly formatted with no manual
intervention.
This commit is contained in:
Mike Gelfand 2019-02-10 14:05:16 +03:00
parent c019317548
commit 82df3a87f4
57 changed files with 959 additions and 2185 deletions

View File

@ -99,8 +99,8 @@ static struct tr_option const options[] =
static char const* getUsage(void)
{
return "A fast and easy BitTorrent client\n"
"\n"
"Usage: " MY_READABLE_NAME " [options] <file|url|magnet>";
"\n"
"Usage: " MY_READABLE_NAME " [options] <file|url|magnet>";
}
static int parseCommandLine(tr_variant*, int argc, char const** argv);

View File

@ -87,13 +87,13 @@ static struct event_base* ev_base = NULL;
static char const* getUsage(void)
{
return "Transmission " LONG_VERSION_STRING " https://transmissionbt.com/\n"
"A fast and easy BitTorrent client\n"
"\n"
MY_NAME " is a headless Transmission session\n"
"that can be controlled via transmission-remote\n"
"or the web interface.\n"
"\n"
"Usage: " MY_NAME " [options]";
"A fast and easy BitTorrent client\n"
"\n"
MY_NAME " is a headless Transmission session\n"
"that can be controlled via transmission-remote\n"
"or the web interface.\n"
"\n"
"Usage: " MY_NAME " [options]";
}
static struct tr_option const options[] =
@ -129,16 +129,20 @@ static struct tr_option const options[] =
{ '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, "<limit>" },
{ 'l', "peerlimit-torrent", "Maximum number of peers per torrent (Default: " TR_DEFAULT_PEER_LIMIT_TORRENT_STR ")", "l", 1, "<limit>" },
{ 'L', "peerlimit-global", "Maximum overall number of peers (Default: " TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ")", "L", 1,
"<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>" },
{ 953, "global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio", "gsr", 1, "ratio" },
{ 954, "no-global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio", "GSR", 0, NULL },
{ 953, "global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio",
"gsr", 1, "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 }
};
@ -147,8 +151,8 @@ static bool reopen_log_file(char const* filename)
{
tr_error* error = NULL;
tr_sys_file_t const old_log_file = logfile;
tr_sys_file_t const new_log_file = tr_sys_file_open(filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_APPEND, 0666,
&error);
tr_sys_file_t const new_log_file = tr_sys_file_open(filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_APPEND,
0666, &error);
if (new_log_file == TR_BAD_SYS_FILE)
{
@ -648,7 +652,8 @@ static int daemon_start(void* raw_arg, bool foreground)
if (pid_filename != NULL && *pid_filename != '\0')
{
tr_error* error = NULL;
tr_sys_file_t fp = tr_sys_file_open(pid_filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE, 0666, &error);
tr_sys_file_t fp = tr_sys_file_open(pid_filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_TRUNCATE, 0666,
&error);
if (fp != TR_BAD_SYS_FILE)
{

View File

@ -86,7 +86,8 @@ static GtkActionEntry entries[] =
{ "open-torrent-toolbar", GTK_STOCK_OPEN, NULL, NULL, N_("Open a torrent"), G_CALLBACK(action_cb) },
{ "open-torrent-menu", GTK_STOCK_OPEN, NULL, NULL, N_("Open a torrent"), G_CALLBACK(action_cb) },
{ "torrent-start", GTK_STOCK_MEDIA_PLAY, N_("_Start"), "<control>S", N_("Start torrent"), G_CALLBACK(action_cb) },
{ "torrent-start-now", GTK_STOCK_MEDIA_PLAY, N_("Start _Now"), "<shift><control>S", N_("Start torrent now"), G_CALLBACK(action_cb) },
{ "torrent-start-now", GTK_STOCK_MEDIA_PLAY, N_("Start _Now"), "<shift><control>S", N_("Start torrent now"),
G_CALLBACK(action_cb) },
{ "show-stats", NULL, N_("_Statistics"), NULL, NULL, G_CALLBACK(action_cb) },
{ "donate", NULL, N_("_Donate"), NULL, NULL, G_CALLBACK(action_cb) },
{ "torrent-verify", NULL, N_("_Verify Local Data"), "<control>V", NULL, G_CALLBACK(action_cb) },
@ -206,14 +207,16 @@ void gtr_actions_init(GtkUIManager* ui_manager, gpointer callback_user_data)
gtk_action_group_add_radio_actions(action_group, sort_radio_entries, G_N_ELEMENTS(sort_radio_entries), active,
G_CALLBACK(sort_changed_cb), NULL);
gtk_action_group_add_toggle_actions(action_group, show_toggle_entries, G_N_ELEMENTS(show_toggle_entries), callback_user_data);
gtk_action_group_add_toggle_actions(action_group, show_toggle_entries, G_N_ELEMENTS(show_toggle_entries),
callback_user_data);
for (size_t i = 0; i < G_N_ELEMENTS(pref_toggle_entries); ++i)
{
pref_toggle_entries[i].is_active = gtr_pref_flag_get(tr_quark_new(pref_toggle_entries[i].name, TR_BAD_SIZE));
}
gtk_action_group_add_toggle_actions(action_group, pref_toggle_entries, G_N_ELEMENTS(pref_toggle_entries), callback_user_data);
gtk_action_group_add_toggle_actions(action_group, pref_toggle_entries, G_N_ELEMENTS(pref_toggle_entries),
callback_user_data);
gtk_action_group_add_actions(action_group, entries, n_entries, callback_user_data);

View File

@ -135,7 +135,7 @@ static gboolean refreshFilesForeach(GtkTreeModel* model, GtkTreePath* path UNUSE
(refresh_data->sort_column_id == FC_ENABLED && enabled != old_enabled)))
{
refresh_data->resort_needed = TRUE;
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE( data->model),
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(data->model),
GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
}
}

View File

@ -493,7 +493,7 @@ static gboolean test_torrent_activity(tr_torrent* tor, int type)
case ACTIVITY_FILTER_ACTIVE:
return st->peersSendingToUs > 0 || st->peersGettingFromUs > 0 || st->webseedsSendingToUs > 0 ||
st->activity == TR_STATUS_CHECK;
st->activity == TR_STATUS_CHECK;
case ACTIVITY_FILTER_PAUSED:
return st->activity == TR_STATUS_STOPPED;
@ -779,7 +779,7 @@ static gboolean is_row_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer
text = (char const*)g_object_get_qdata(o, TEXT_KEY);
return tor != NULL && test_tracker(tor, data->active_tracker_type, data->active_tracker_host) &&
test_torrent_activity(tor, data->active_activity_type) && testText(tor, text);
test_torrent_activity(tor, data->active_activity_type) && testText(tor, text);
}
static void selection_changed_cb(GtkComboBox* combo, gpointer vdata)

View File

@ -568,7 +568,8 @@ static void gtr_cell_renderer_render(GtkCellRenderer* renderer, GtrDrawable* dra
}
static void render_compact(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidget* widget,
GdkRectangle const* background_area, GdkRectangle const* cell_area UNUSED, GtkCellRendererState flags)
GdkRectangle const* background_area, GdkRectangle const* cell_area UNUSED,
GtkCellRendererState flags)
{
int xpad;
int ypad;
@ -754,7 +755,8 @@ static void render_full(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidge
}
static void torrent_cell_renderer_render(GtkCellRenderer* cell, GtrDrawable* window, GtkWidget* widget,
GdkRectangle const* background_area, GdkRectangle const* cell_area, GtkCellRendererState flags)
GdkRectangle const* background_area, GdkRectangle const* cell_area,
GtkCellRendererState flags)
{
TorrentCellRenderer* self = TORRENT_CELL_RENDERER(cell);

View File

@ -206,7 +206,7 @@ void gtr_get_host_from_url(char* buf, size_t buflen, char const* url)
static gboolean gtr_is_supported_url(char const* str)
{
return str != NULL && (g_str_has_prefix(str, "ftp://") || g_str_has_prefix(str, "http://") ||
g_str_has_prefix(str, "https://"));
g_str_has_prefix(str, "https://"));
}
gboolean gtr_is_magnet_link(char const* str)

View File

@ -1534,13 +1534,13 @@ static void flushCloseMessages(tr_announcer* announcer)
static bool tierNeedsToAnnounce(tr_tier const* tier, time_t const now)
{
return !tier->isAnnouncing && !tier->isScraping && tier->announceAt != 0 && tier->announceAt <= now &&
tier->announce_event_count > 0;
tier->announce_event_count > 0;
}
static bool tierNeedsToScrape(tr_tier const* tier, time_t const now)
{
return !tier->isScraping && tier->scrapeAt != 0 && tier->scrapeAt <= now && tier->currentTracker != NULL &&
tier->currentTracker->scrape != NULL;
tier->currentTracker->scrape != NULL;
}
static int compareTiers(void const* va, void const* vb)

View File

@ -305,17 +305,20 @@ static bool parseLine2(char const* line, struct tr_ipv4_range* range)
* CIDR notation: "0.0.0.0/8", IPv4 only
* https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation
*/
static bool parseLine3(char const* line, struct tr_ipv4_range* range) {
static bool parseLine3(char const* line, struct tr_ipv4_range* range)
{
unsigned ip[4];
unsigned pflen;
uint32_t ip_u;
uint32_t mask = 0xffffffff;
if (sscanf(line, "%u.%u.%u.%u/%u", &ip[0], &ip[1], &ip[2], &ip[3], &pflen) != 5) {
if (sscanf(line, "%u.%u.%u.%u/%u", &ip[0], &ip[1], &ip[2], &ip[3], &pflen) != 5)
{
return false;
}
if (pflen > 32 || ip[0] > 0xff || ip[1] > 0xff || ip[2] > 0xff || ip[3] > 0xff) {
if (pflen > 32 || ip[0] > 0xff || ip[1] > 0xff || ip[2] > 0xff || ip[3] > 0xff)
{
return false;
}

View File

@ -6,6 +6,7 @@
*
*/
/* *INDENT-OFF* */
#if defined(CYASSL_IS_WOLFSSL)
#define API_HEADER(x) <wolfssl/x>
#define API_HEADER_CRYPT(x) API_HEADER(wolfcrypt/x)
@ -24,6 +25,7 @@
#include API_HEADER_CRYPT(random.h)
#include API_HEADER_CRYPT(sha.h)
#include API_HEADER(version.h)
/* *INDENT-ON* */
#include "transmission.h"
#include "crypto-utils.h"

View File

@ -6,6 +6,7 @@
*
*/
/* *INDENT-OFF* */
#if defined(POLARSSL_IS_MBEDTLS)
#define API_HEADER(x) <mbedtls/x>
#define API(x) mbedtls_ ## x
@ -15,6 +16,7 @@
#define API(x) x
#define API_VERSION_NUMBER POLARSSL_VERSION_NUMBER
#endif
/* *INDENT-ON* */
#include API_HEADER(arc4.h)
#include API_HEADER(base64.h)
@ -40,6 +42,11 @@
#define MY_NAME "tr_crypto_utils"
typedef API (ctr_drbg_context) api_ctr_drbg_context;
typedef API (sha1_context) api_sha1_context;
typedef API (arc4_context) api_arc4_context;
typedef API (dhm_context) api_dhm_context;
static void log_polarssl_error(int error_code, char const* file, int line)
{
if (tr_logLevelIsActive(TR_LOG_ERROR))
@ -89,9 +96,9 @@ static int my_rand(void* context UNUSED, unsigned char* buffer, size_t buffer_si
return 0;
}
static API(ctr_drbg_context)* get_rng(void)
static api_ctr_drbg_context* get_rng(void)
{
static API(ctr_drbg_context) rng;
static api_ctr_drbg_context rng;
static bool rng_initialized = false;
if (!rng_initialized)
@ -132,7 +139,7 @@ static tr_lock* get_rng_lock(void)
tr_sha1_ctx_t tr_sha1_init(void)
{
API(sha1_context)* handle = tr_new0(API(sha1_context), 1);
api_sha1_context* handle = tr_new0(api_sha1_context, 1);
#if API_VERSION_NUMBER >= 0x01030800
API(sha1_init)(handle);
@ -180,7 +187,7 @@ bool tr_sha1_final(tr_sha1_ctx_t handle, uint8_t* hash)
tr_rc4_ctx_t tr_rc4_new(void)
{
API(arc4_context)* handle = tr_new0(API(arc4_context), 1);
api_arc4_context* handle = tr_new0(api_arc4_context, 1);
#if API_VERSION_NUMBER >= 0x01030800
API(arc4_init)(handle);
@ -231,7 +238,7 @@ tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t
TR_ASSERT(prime_num != NULL);
TR_ASSERT(generator_num != NULL);
API(dhm_context)* handle = tr_new0(API(dhm_context), 1);
api_dhm_context* handle = tr_new0(api_dhm_context, 1);
#if API_VERSION_NUMBER >= 0x01030800
API(dhm_init)(handle);
@ -264,7 +271,7 @@ bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length, uint8_t*
TR_ASSERT(raw_handle != NULL);
TR_ASSERT(public_key != NULL);
API(dhm_context)* handle = raw_handle;
api_dhm_context* handle = raw_handle;
if (public_key_length != NULL)
{
@ -279,7 +286,7 @@ tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, uint8_t const* other_public_k
TR_ASSERT(raw_handle != NULL);
TR_ASSERT(other_public_key != NULL);
API(dhm_context)* handle = raw_handle;
api_dhm_context* handle = raw_handle;
struct tr_dh_secret* ret;
size_t secret_key_length;

View File

@ -990,7 +990,7 @@ static int test_path_remove(void)
static int test_path_native_separators(void)
{
check_str(tr_sys_path_native_separators(NULL), == , NULL);
check_str(tr_sys_path_native_separators(NULL), ==, NULL);
char path1[] = "";
char path2[] = "a";

View File

@ -89,7 +89,7 @@ static int readOrWriteBytes(tr_session* session, tr_torrent* tor, int ioMode, tr
int const prealloc = (file->dnd || !doWrite) ? TR_PREALLOCATE_NONE : tor->session->preallocationMode;
if ((fd = tr_fdFileCheckout(session, tor->uniqueId, fileIndex, filename, doWrite, prealloc,
file->length)) == TR_BAD_SYS_FILE)
file->length)) == TR_BAD_SYS_FILE)
{
err = errno;
tr_logAddTorErr(tor, "tr_fdFileCheckout failed for \"%s\": %s", filename, tr_strerror(err));

View File

@ -54,7 +54,7 @@ bool libtest_check(char const* file, int line, bool pass, bool condition, char c
{
if (should_print(pass))
{
fprintf(stderr, "%s %s:%d: %s (%s)\n", pass ? "PASS" : "FAIL", file, line, condition_str, condition ? "true": "false");
fprintf(stderr, "%s %s:%d: %s (%s)\n", pass ? "PASS" : "FAIL", file, line, condition_str, condition ? "true" : "false");
}
return pass;

View File

@ -59,11 +59,12 @@ bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, v
{ \
++current_test; \
\
bool const check_bool_lhs = (lhs); \
bool const check_bool_rhs = (rhs); \
bool const check_lhs = (lhs); \
bool const check_rhs = (rhs); \
\
if (!libtest_check_bool(__FILE__, __LINE__, check_bool_lhs op check_bool_rhs, check_bool_lhs, check_bool_rhs, #lhs, \
#op, #rhs)) \
bool const check_result = check_lhs op check_rhs; \
\
if (!libtest_check_bool(__FILE__, __LINE__, check_result, check_lhs, check_rhs, #lhs, #op, #rhs)) \
{ \
return current_test; \
} \
@ -75,11 +76,12 @@ bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, v
{ \
++current_test; \
\
char const* const check_str_lhs = (lhs); \
char const* const check_str_rhs = (rhs); \
char const* const check_lhs = (lhs); \
char const* const check_rhs = (rhs); \
\
if (!libtest_check_str(__FILE__, __LINE__, tr_strcmp0(check_str_lhs, check_str_rhs) op 0, check_str_lhs, \
check_str_rhs, #lhs, #op, #rhs)) \
bool const check_result = tr_strcmp0(check_lhs, check_rhs) op 0; \
\
if (!libtest_check_str(__FILE__, __LINE__, check_result, check_lhs, check_rhs, #lhs, #op, #rhs)) \
{ \
return current_test; \
} \
@ -91,12 +93,13 @@ bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, v
{ \
++current_test; \
\
void const* const check_mem_lhs = (lhs); \
void const* const check_mem_rhs = (rhs); \
size_t const check_mem_size = (size);\
void const* const check_lhs = (lhs); \
void const* const check_rhs = (rhs); \
size_t const check_mem_size = (size); \
\
if (!libtest_check_mem(__FILE__, __LINE__, tr_memcmp0(check_mem_lhs, check_mem_rhs, check_mem_size) op 0, \
check_mem_lhs, check_mem_rhs, check_mem_size, #lhs, #op, #rhs)) \
bool const check_result = tr_memcmp0(check_lhs, check_rhs, check_mem_size) op 0; \
\
if (!libtest_check_mem(__FILE__, __LINE__, check_result, check_lhs, check_rhs, check_mem_size, #lhs, #op, #rhs)) \
{ \
return current_test; \
} \
@ -108,11 +111,12 @@ bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, v
{ \
++current_test; \
\
intmax_t const check_int_lhs = (lhs); \
intmax_t const check_int_rhs = (rhs); \
intmax_t const check_lhs = (lhs); \
intmax_t const check_rhs = (rhs); \
\
if (!libtest_check_int(__FILE__, __LINE__, check_int_lhs op check_int_rhs, check_int_lhs, check_int_rhs, #lhs, #op, \
#rhs)) \
bool const check_result = check_lhs op check_rhs; \
\
if (!libtest_check_int(__FILE__, __LINE__, check_result, check_lhs, check_rhs, #lhs, #op, #rhs)) \
{ \
return current_test; \
} \
@ -124,11 +128,12 @@ bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, v
{ \
++current_test; \
\
uintmax_t const check_uint_lhs = (lhs); \
uintmax_t const check_uint_rhs = (rhs); \
uintmax_t const check_lhs = (lhs); \
uintmax_t const check_rhs = (rhs); \
\
if (!libtest_check_uint(__FILE__, __LINE__, check_uint_lhs op check_uint_rhs, check_uint_lhs, check_uint_rhs, #lhs, \
#op, #rhs)) \
bool const check_result = check_lhs op check_rhs; \
\
if (!libtest_check_uint(__FILE__, __LINE__, check_result, check_lhs, check_rhs, #lhs, #op, #rhs)) \
{ \
return current_test; \
} \
@ -140,11 +145,12 @@ bool libtest_check_ptr(char const* file, int line, bool pass, void const* lhs, v
{ \
++current_test; \
\
void const* const check_ptr_lhs = (lhs); \
void const* const check_ptr_rhs = (rhs); \
void const* const check_lhs = (lhs); \
void const* const check_rhs = (rhs); \
\
if (!libtest_check_ptr(__FILE__, __LINE__, check_ptr_lhs op check_ptr_rhs, check_ptr_lhs, check_ptr_rhs, #lhs, #op, \
#rhs)) \
bool const check_result = check_lhs op check_rhs; \
\
if (!libtest_check_ptr(__FILE__, __LINE__, check_result, check_lhs, check_rhs, #lhs, #op, #rhs)) \
{ \
return current_test; \
} \

View File

@ -28,7 +28,7 @@ typedef struct tr_list
}
tr_list;
typedef int (* TrListCompareFunc)(void const* a, void const* b);
typedef tr_voidptr_compare_func TrListCompareFunc;
typedef void (* TrListForeachFunc)(void*);
/**

View File

@ -27,7 +27,7 @@ static inline bool tr_logLevelIsActive(tr_log_level level)
return tr_logGetLevel() >= level;
}
void tr_logAddMessage(char const* file, int line, tr_log_level level, char const* torrent, char const* fmt, ...)
void tr_logAddMessage(char const* file, int line, tr_log_level level, char const* torrent, char const* fmt, ...) \
TR_GNUC_PRINTF(5, 6);
#define tr_logAddNamed(level, name, ...) \
@ -61,7 +61,7 @@ tr_sys_file_t tr_logGetFile(void);
/** @brief return true if deep logging has been enabled by the user; false otherwise */
bool tr_logGetDeepEnabled(void);
void tr_logAddDeep(char const* file, int line, char const* name, char const* fmt, ...) TR_GNUC_PRINTF(4, 5)
void tr_logAddDeep(char const* file, int line, char const* name, char const* fmt, ...) TR_GNUC_PRINTF(4, 5) \
TR_GNUC_NONNULL(1, 4);
#define tr_logAddDeepNamed(name, ...) \

View File

@ -111,7 +111,8 @@ static int test_single_file(void)
}
static int test_single_directory_impl(tr_tracker_info const* trackers, size_t const trackerCount, void const** payloads,
size_t const* payloadSizes, size_t const payloadCount, char const* comment, bool const isPrivate)
size_t const* payloadSizes, size_t const payloadCount, char const* comment,
bool const isPrivate)
{
char* sandbox;
char* torrent_file;
@ -211,7 +212,8 @@ static int test_single_directory_impl(tr_tracker_info const* trackers, size_t co
}
static int test_single_directory_random_payload_impl(tr_tracker_info const* trackers, size_t const trackerCount,
size_t const maxFileCount, size_t const maxFileSize, char const* comment, bool const isPrivate)
size_t const maxFileCount, size_t const maxFileSize, char const* comment,
bool const isPrivate)
{
void** payloads;
size_t* payloadSizes;

View File

@ -89,7 +89,7 @@ static char* getTorrentFilename(tr_session const* session, tr_info const* inf, e
static bool path_component_is_suspicious(char const* component)
{
return component == NULL || strpbrk(component, PATH_DELIMITER_CHARS) != NULL || strcmp(component, ".") == 0 ||
strcmp(component, "..") == 0;
strcmp(component, "..") == 0;
}
static bool getfile(char** setme, char const* root, tr_variant* path, struct evbuffer* buf)
@ -626,7 +626,8 @@ static char const* tr_metainfoParseImpl(tr_session const* session, tr_info* inf,
/* files */
if (!isMagnet)
{
if ((str = parseFiles(inf, tr_variantDictFind(infoDict, TR_KEY_files), tr_variantDictFind(infoDict, TR_KEY_length))) != NULL)
if ((str = parseFiles(inf, tr_variantDictFind(infoDict, TR_KEY_files), tr_variantDictFind(infoDict,
TR_KEY_length))) != NULL)
{
return str;
}

View File

@ -375,7 +375,8 @@ struct tr_peer_socket tr_netOpenPeerSocket(tr_session* session, tr_address const
return ret;
}
struct tr_peer_socket tr_netOpenPeerUTPSocket(tr_session* session, tr_address const* addr, tr_port port, bool clientIsSeed UNUSED)
struct tr_peer_socket tr_netOpenPeerUTPSocket(tr_session* session, tr_address const* addr, tr_port port,
bool clientIsSeed UNUSED)
{
struct tr_peer_socket ret = TR_PEER_SOCKET_INIT;
@ -776,5 +777,5 @@ static bool isMartianAddr(struct tr_address const* a)
bool tr_address_is_valid_for_peers(tr_address const* addr, tr_port port)
{
return port != 0 && tr_address_is_valid(addr) && !isIPv6LinkLocalAddress(addr) && !isIPv4MappedAddress(addr) &&
!isMartianAddr(addr);
!isMartianAddr(addr);
}

View File

@ -128,7 +128,7 @@ void tr_peerIoUnrefImpl(char const* file, int line, tr_peerIo* io);
static inline bool tr_isPeerIo(tr_peerIo const* io)
{
return io != NULL && io->magicNumber == PEER_IO_MAGIC_NUMBER && io->refCount >= 0 && tr_isBandwidth(&io->bandwidth) &&
tr_address_is_valid(&io->addr);
tr_address_is_valid(&io->addr);
}
/**

View File

@ -149,7 +149,7 @@ struct peer_atom
static bool tr_isAtom(struct peer_atom const* atom)
{
return atom != NULL && atom->fromFirst < TR_PEER_FROM__MAX && atom->fromBest < TR_PEER_FROM__MAX &&
tr_address_is_valid(&atom->addr);
tr_address_is_valid(&atom->addr);
}
#endif
@ -411,7 +411,7 @@ 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);
getExistingHandshake(&s->manager->incomingHandshakes, &atom->addr);
}
static inline bool replicationExists(tr_swarm const* s)
@ -3643,8 +3643,7 @@ static int comparePeerLiveliness(void const* va, void const* vb)
return 0;
}
static void sortPeersByLivelinessImpl(tr_peer** peers, void** clientData, int n, uint64_t now, int (* compare)(void const* va,
void const* vb))
static void sortPeersByLivelinessImpl(tr_peer** peers, void** clientData, int n, uint64_t now, tr_voidptr_compare_func compare)
{
struct peer_liveliness* lives;
struct peer_liveliness* l;

View File

@ -2316,8 +2316,8 @@ typedef void (* tr_set_func)(void* element, void* userData);
* @param in_both called for items that are in both sets
* @param userData user data passed along to in_a, in_b, and in_both
*/
static void tr_set_compare(void const* va, size_t aCount, void const* vb, size_t bCount, int (* compare)(void const* a,
void const* b), size_t elementSize, tr_set_func in_a_cb, tr_set_func in_b_cb, tr_set_func in_both_cb, void* userData)
static void tr_set_compare(void const* va, size_t aCount, void const* vb, size_t bCount, tr_voidptr_compare_func compare,
size_t elementSize, tr_set_func in_a_cb, tr_set_func in_b_cb, tr_set_func in_both_cb, void* userData)
{
uint8_t const* a = va;
uint8_t const* b = vb;

View File

@ -386,7 +386,7 @@ static int64_t getquota(char const* device)
#ifdef __APPLE__
return freespace < 0 ? 0 : freespace;
#else
return freespace < 0 ? 0 : freespace * 1024;
return freespace < 0 ? 0 : (freespace * 1024);
#endif
}
@ -426,7 +426,7 @@ static int64_t getxfsquota(char* device)
}
freespace = limit - (dq.d_bcount >> 1);
return freespace < 0 ? 0 : freespace * 1024;
return freespace < 0 ? 0 : (freespace * 1024);
}
/* something went wrong */

View File

@ -101,7 +101,7 @@ void tr_ptrArrayErase(tr_ptrArray* t, int begin, int end)
***
**/
int tr_ptrArrayLowerBound(tr_ptrArray const* t, void const* ptr, int (* compare)(void const*, void const*), bool* exact_match)
int tr_ptrArrayLowerBound(tr_ptrArray const* t, void const* ptr, tr_voidptr_compare_func compare, bool* exact_match)
{
int pos = -1;
bool match = false;
@ -168,7 +168,7 @@ int tr_ptrArrayLowerBound(tr_ptrArray const* t, void const* ptr, int (* compare)
#else
static void assertArrayIsSortedAndUnique(tr_ptrArray const* t, int (* compare)(void const*, void const*))
static void assertArrayIsSortedAndUnique(tr_ptrArray const* t, tr_voidptr_compare_func compare)
{
for (int i = 0; i < t->n_items - 2; ++i)
{
@ -176,7 +176,7 @@ static void assertArrayIsSortedAndUnique(tr_ptrArray const* t, int (* compare)(v
}
}
static void assertIndexIsSortedAndUnique(tr_ptrArray const* t, int pos, int (* compare)(void const*, void const*))
static void assertIndexIsSortedAndUnique(tr_ptrArray const* t, int pos, tr_voidptr_compare_func compare)
{
if (pos > 0)
{
@ -191,7 +191,7 @@ static void assertIndexIsSortedAndUnique(tr_ptrArray const* t, int pos, int (* c
#endif
int tr_ptrArrayInsertSorted(tr_ptrArray* t, void* ptr, int (* compare)(void const*, void const*))
int tr_ptrArrayInsertSorted(tr_ptrArray* t, void* ptr, tr_voidptr_compare_func compare)
{
int pos;
int ret;
@ -204,14 +204,14 @@ int tr_ptrArrayInsertSorted(tr_ptrArray* t, void* ptr, int (* compare)(void cons
return ret;
}
void* tr_ptrArrayFindSorted(tr_ptrArray* t, void const* ptr, int (* compare)(void const*, void const*))
void* tr_ptrArrayFindSorted(tr_ptrArray* t, void const* ptr, tr_voidptr_compare_func compare)
{
bool match = false;
int const pos = tr_ptrArrayLowerBound(t, ptr, compare, &match);
return match ? t->items[pos] : NULL;
}
static void* tr_ptrArrayRemoveSortedValue(tr_ptrArray* t, void const* ptr, int (* compare)(void const*, void const*))
static void* tr_ptrArrayRemoveSortedValue(tr_ptrArray* t, void const* ptr, tr_voidptr_compare_func compare)
{
int pos;
bool match;
@ -232,7 +232,7 @@ static void* tr_ptrArrayRemoveSortedValue(tr_ptrArray* t, void const* ptr, int (
return ret;
}
void tr_ptrArrayRemoveSortedPointer(tr_ptrArray* t, void const* ptr, int (* compare)(void const*, void const*))
void tr_ptrArrayRemoveSortedPointer(tr_ptrArray* t, void const* ptr, tr_voidptr_compare_func compare)
{
void* removed = tr_ptrArrayRemoveSortedValue(t, ptr, compare);

View File

@ -31,7 +31,7 @@ typedef struct tr_ptrArray
}
tr_ptrArray;
typedef int (* PtrArrayCompareFunc)(void const* a, void const* b);
typedef tr_voidptr_compare_func PtrArrayCompareFunc;
typedef void (* PtrArrayForeachFunc)(void*);
@ -113,18 +113,17 @@ static inline bool tr_ptrArrayEmpty(tr_ptrArray const* a)
return tr_ptrArraySize(a) == 0;
}
int tr_ptrArrayLowerBound(tr_ptrArray const* array, void const* key, int (* compare)(void const* arrayItem, void const* key),
bool* exact_match);
int tr_ptrArrayLowerBound(tr_ptrArray const* array, void const* key, tr_voidptr_compare_func compare, bool* exact_match);
/** @brief Insert a pointer into the array at the position determined by the sort function
@return the index of the stored pointer */
int tr_ptrArrayInsertSorted(tr_ptrArray* array, void* value, int (* compare)(void const*, void const*));
int tr_ptrArrayInsertSorted(tr_ptrArray* array, void* value, tr_voidptr_compare_func compare);
/** @brief Remove this specific pointer from a sorted ptrarray */
void tr_ptrArrayRemoveSortedPointer(tr_ptrArray* t, void const* ptr, int (* compare)(void const*, void const*));
void tr_ptrArrayRemoveSortedPointer(tr_ptrArray* t, void const* ptr, tr_voidptr_compare_func compare);
/** @brief Find a pointer from an array sorted by the specified sort function
@return the matching pointer, or NULL if no match was found */
void* tr_ptrArrayFindSorted(tr_ptrArray* array, void const* key, int (* compare)(void const*, void const*));
void* tr_ptrArrayFindSorted(tr_ptrArray* array, void const* key, tr_voidptr_compare_func compare);
/* @} */

View File

@ -555,7 +555,7 @@ static bool isIPAddressWithOptionalPort(char const* host)
int address_len = sizeof(address);
/* TODO: move to net.{c,h} */
return evutil_parse_sockaddr_port(host, (struct sockaddr *) &address, &address_len) != -1;
return evutil_parse_sockaddr_port(host, (struct sockaddr*)&address, &address_len) != -1;
}
static bool isHostnameAllowed(tr_rpc_server const* server, struct evhttp_request* req)
@ -672,7 +672,8 @@ static void handle_request(struct evhttp_request* req, void* arg)
{
evhttp_add_header(req->output_headers, "WWW-Authenticate", "Basic realm=\"" MY_REALM "\"");
server->loginattempts++;
char* unauthuser = tr_strdup_printf("<p>Unauthorized User. %d unsuccessful login attempts.</p>", server->loginattempts);
char* unauthuser = tr_strdup_printf("<p>Unauthorized User. %d unsuccessful login attempts.</p>",
server->loginattempts);
send_simple_response(req, 401, unauthuser);
tr_free(unauthuser);
tr_free(user);
@ -1236,7 +1237,8 @@ tr_rpc_server* tr_rpcInit(tr_session* session, tr_variant* settings)
if (s->isEnabled)
{
tr_logAddNamedInfo(MY_NAME, _("Serving RPC and Web requests on %s:%d%s"), tr_rpcGetBindAddress(s), (int)s->port, s->url);
tr_logAddNamedInfo(MY_NAME, _("Serving RPC and Web requests on %s:%d%s"), tr_rpcGetBindAddress(s), (int)s->port,
s->url);
tr_runInEventThread(session, startServer, s);
if (s->isWhitelistEnabled)

View File

@ -34,10 +34,10 @@ static int test_spawn_async_missing_exe(void)
tr_error* error = NULL;
bool const ret = tr_spawn_async(args, NULL, NULL, &error);
check_bool(ret, == , false);
check_ptr(error, != , NULL);
check_int(error->code, != , 0);
check_str(error->message, != , NULL);
check_bool(ret, ==, false);
check_ptr(error, !=, NULL);
check_int(error->code, !=, 0);
check_str(error->message, !=, NULL);
tr_error_clear(&error);
@ -89,12 +89,12 @@ static int test_spawn_async_args(void)
check_str(buffer, ==, test_arg_2);
check(tr_sys_file_read_line(fd, buffer, sizeof(buffer), NULL));
check_str(buffer, == , test_arg_3);
check_str(buffer, ==, test_arg_3);
if (allow_batch_metachars)
{
check(tr_sys_file_read_line(fd, buffer, sizeof(buffer), NULL));
check_str(buffer, == , test_arg_4);
check_str(buffer, ==, test_arg_4);
}
check(!tr_sys_file_read_line(fd, buffer, sizeof(buffer), NULL));

View File

@ -509,7 +509,7 @@ static bool tr_torrentIsSeedIdleLimitDone(tr_torrent* tor)
{
uint16_t idleMinutes;
return tr_torrentGetSeedIdle(tor, &idleMinutes) &&
difftime(tr_time(), MAX(tor->startDate, tor->activityDate)) >= idleMinutes * 60u;
difftime(tr_time(), MAX(tor->startDate, tor->activityDate)) >= idleMinutes * 60u;
}
/***
@ -1317,7 +1317,7 @@ static time_t torrentGetIdleSecs(tr_torrent const* tor)
bool tr_torrentIsStalled(tr_torrent const* tor)
{
return tr_sessionGetQueueStalledEnabled(tor->session) &&
torrentGetIdleSecs(tor) > tr_sessionGetQueueStalledMinutes(tor->session) * 60;
torrentGetIdleSecs(tor) > tr_sessionGetQueueStalledMinutes(tor->session) * 60;
}
static double getVerifyProgress(tr_torrent const* tor)
@ -3769,7 +3769,7 @@ void tr_torrentSetQueueStartCallback(tr_torrent* torrent, void (* callback)(tr_t
static bool renameArgsAreValid(char const* oldpath, char const* newname)
{
return oldpath != NULL && *oldpath != '\0' && newname != NULL && *newname != '\0' && strcmp(newname, ".") != 0 &&
strcmp(newname, "..") != 0 && strchr(newname, TR_PATH_DELIMITER) == NULL;
strcmp(newname, "..") != 0 && strchr(newname, TR_PATH_DELIMITER) == NULL;
}
static tr_file_index_t* renameFindAffectedFiles(tr_torrent* tor, char const* oldpath, size_t* setme_n)

View File

@ -517,7 +517,8 @@ bool tr_lpdSendAnnounce(tr_torrent const* t)
/* destination address info has already been set up in tr_lpdInit(),
* so we refrain from preparing another sockaddr_in here */
int res = sendto(lpd_socket2, (void const*)query, len, 0, (struct sockaddr const*)&lpd_mcastAddr, sizeof(lpd_mcastAddr));
int res = sendto(lpd_socket2, (void const*)query, len, 0, (struct sockaddr const*)&lpd_mcastAddr,
sizeof(lpd_mcastAddr));
if (res != len)
{

View File

@ -140,7 +140,7 @@
#else
#define TR_STATIC_ASSERT(x, msg) \
{ \
typedef char __tr_static_check__[(x) ? 1 : -1] UNUSED; \
typedef char __tr_static_check__ [(x) ? 1 : -1] UNUSED; \
}
#endif

View File

@ -49,6 +49,8 @@ struct tr_variant;
typedef int8_t tr_priority_t;
typedef int (* tr_voidptr_compare_func)(void const* lhs, void const* rhs);
#define TR_RPC_SESSION_ID_HEADER "X-Transmission-Session-Id"
typedef enum

View File

@ -811,7 +811,7 @@ bool tr_urlIsValidTracker(char const* url)
size_t const url_len = strlen(url);
return isValidURLChars(url, url_len) && tr_urlParse(url, url_len, NULL, NULL, NULL, NULL) &&
(memcmp(url, "http://", 7) == 0 || memcmp(url, "https://", 8) == 0 || memcmp(url, "udp://", 6) == 0);
(memcmp(url, "http://", 7) == 0 || memcmp(url, "https://", 8) == 0 || memcmp(url, "udp://", 6) == 0);
}
bool tr_urlIsValid(char const* url, size_t url_len)
@ -827,8 +827,8 @@ bool tr_urlIsValid(char const* url, size_t url_len)
}
return isValidURLChars(url, url_len) && tr_urlParse(url, url_len, NULL, NULL, NULL, NULL) &&
(memcmp(url, "http://", 7) == 0 || memcmp(url, "https://", 8) == 0 || memcmp(url, "ftp://", 6) == 0 ||
memcmp(url, "sftp://", 7) == 0);
(memcmp(url, "http://", 7) == 0 || memcmp(url, "https://", 8) == 0 || memcmp(url, "ftp://", 6) == 0 ||
memcmp(url, "sftp://", 7) == 0);
}
bool tr_addressIsIP(char const* str)
@ -979,8 +979,8 @@ void tr_removeElementFromArray(void* array, unsigned int index_to_remove, size_t
sizeof_element * (--nmemb - index_to_remove));
}
int tr_lowerBound(void const* key, void const* base, size_t nmemb, size_t size, int (* compar)(void const* key,
void const* arrayMember), bool* exact_match)
int tr_lowerBound(void const* key, void const* base, size_t nmemb, size_t size, tr_voidptr_compare_func compar,
bool* exact_match)
{
size_t first = 0;
char const* cbase = base;
@ -1038,7 +1038,7 @@ int tr_lowerBound(void const* key, void const* base, size_t nmemb, size_t size,
} \
while (0)
static size_t quickfindPartition(char* base, size_t left, size_t right, size_t size, int (* compar)(void const*, void const*),
static size_t quickfindPartition(char* base, size_t left, size_t right, size_t size, tr_voidptr_compare_func compar,
size_t pivotIndex)
{
size_t storeIndex;
@ -1081,8 +1081,7 @@ static size_t quickfindPartition(char* base, size_t left, size_t right, size_t s
return storeIndex;
}
static void quickfindFirstK(char* base, size_t left, size_t right, size_t size, int (* compar)(void const*, void const*),
size_t k)
static void quickfindFirstK(char* base, size_t left, size_t right, size_t size, tr_voidptr_compare_func compar, size_t k)
{
if (right > left)
{
@ -1103,7 +1102,7 @@ static void quickfindFirstK(char* base, size_t left, size_t right, size_t size,
#ifdef TR_ENABLE_ASSERTS
static void checkBestScoresComeFirst(char* base, size_t nmemb, size_t size, int (* compar)(void const*, void const*), size_t k)
static void checkBestScoresComeFirst(char* base, size_t nmemb, size_t size, tr_voidptr_compare_func compar, size_t k)
{
size_t worstFirstPos = 0;
@ -1128,7 +1127,7 @@ static void checkBestScoresComeFirst(char* base, size_t nmemb, size_t size, int
#endif
void tr_quickfindFirstK(void* base, size_t nmemb, size_t size, int (* compar)(void const*, void const*), size_t k)
void tr_quickfindFirstK(void* base, size_t nmemb, size_t size, tr_voidptr_compare_func compar, size_t k)
{
if (k < nmemb)
{

View File

@ -126,6 +126,7 @@ void tr_win32_make_args_utf8(int* argc, char*** argv);
int tr_main_win32(int argc, char** argv, int (* real_main)(int, char**));
/* *INDENT-OFF* */
#define tr_main(...) \
main_impl(__VA_ARGS__); \
int main(int argc, char* argv[]) \
@ -133,6 +134,7 @@ int tr_main_win32(int argc, char** argv, int (* real_main)(int, char**));
return tr_main_win32(argc, argv, &main_impl); \
} \
int main_impl(__VA_ARGS__)
/* *INDENT-ON* */
#else
@ -167,6 +169,7 @@ void tr_free_ptrv(void* const* p);
*/
void* tr_memdup(void const* src, size_t byteCount);
/* *INDENT-OFF* */
#define tr_new(struct_type, n_structs) \
((struct_type*)tr_malloc(sizeof(struct_type) * (size_t)(n_structs)))
@ -175,6 +178,7 @@ void* tr_memdup(void const* src, size_t byteCount);
#define tr_renew(struct_type, mem, n_structs) \
((struct_type*)tr_realloc((mem), sizeof(struct_type) * (size_t)(n_structs)))
/* *INDENT-ON* */
void* tr_valloc(size_t bufLen);
@ -206,11 +210,11 @@ int tr_memcmp0(void const* lhs, void const* rhs, size_t size);
char* evbuffer_free_to_str(struct evbuffer* buf, size_t* result_len);
/** @brief similar to bsearch() but returns the index of the lower bound */
int tr_lowerBound(void const* key, void const* base, size_t nmemb, size_t size, int (* compar)(void const* key,
void const* arrayMember), bool* exact_match) TR_GNUC_HOT TR_GNUC_NONNULL(1, 5, 6);
int tr_lowerBound(void const* key, void const* base, size_t nmemb, size_t size, tr_voidptr_compare_func compar,
bool* exact_match) TR_GNUC_HOT TR_GNUC_NONNULL(1, 5, 6);
/** @brief moves the best k items to the first slots in the array. O(n) */
void tr_quickfindFirstK(void* base, size_t nmemb, size_t size, int (* compar)(void const*, void const*), size_t k);
void tr_quickfindFirstK(void* base, size_t nmemb, size_t size, tr_voidptr_compare_func compar, size_t k);
/**
* @brief sprintf() a string into a newly-allocated buffer large enough to hold it

View File

@ -117,7 +117,7 @@ static bool tr_variantIsContainer(tr_variant const* v)
static bool tr_variantIsSomething(tr_variant const* v)
{
return tr_variantIsContainer(v) || tr_variantIsInt(v) || tr_variantIsString(v) || tr_variantIsReal(v) ||
tr_variantIsBool(v);
tr_variantIsBool(v);
}
void tr_variantInit(tr_variant* v, char type)

View File

@ -87,7 +87,7 @@ tr_watchdir_backend* tr_watchdir_generic_new(tr_watchdir_t handle)
backend->base.free_func = &tr_watchdir_generic_free;
if ((backend->event = event_new(tr_watchdir_get_event_base(handle), -1, EV_PERSIST, &tr_watchdir_generic_on_event,
handle)) == NULL)
handle)) == NULL)
{
log_error("Failed to create event: %s", tr_strerror(errno));
goto fail;

View File

@ -145,7 +145,7 @@ tr_watchdir_backend* tr_watchdir_kqueue_new(tr_watchdir_t handle)
/* Create libevent task for event descriptor */
if ((backend->event = event_new(tr_watchdir_get_event_base(handle), backend->kq, EV_READ | EV_ET | EV_PERSIST,
&tr_watchdir_kqueue_on_event, handle)) == NULL)
&tr_watchdir_kqueue_on_event, handle)) == NULL)
{
log_error("Failed to create event: %s", tr_strerror(errno));
goto fail;

View File

@ -63,7 +63,7 @@ tr_watchdir_win32;
static BOOL tr_get_overlapped_result_ex(HANDLE handle, LPOVERLAPPED overlapped, LPDWORD bytes_transferred, DWORD timeout,
BOOL alertable)
{
typedef BOOL (WINAPI * impl_t)(HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
typedef BOOL (WINAPI* impl_t)(HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL);
static impl_t real_impl = NULL;
static bool is_real_impl_valid = false;
@ -268,7 +268,7 @@ tr_watchdir_backend* tr_watchdir_win32_new(tr_watchdir_t handle)
}
if ((backend->fd = CreateFileW(wide_path, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL)) == INVALID_HANDLE_VALUE)
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL)) == INVALID_HANDLE_VALUE)
{
log_error("Failed to open directory \"%s\"", path);
goto fail;

View File

@ -268,7 +268,8 @@ static void task_finish_func(void* vtask)
static void tr_webThreadFunc(void* vsession);
static struct tr_web_task* tr_webRunImpl(tr_session* session, int torrentId, char const* url, char const* range,
char const* cookies, tr_web_done_func done_func, void* done_func_user_data, struct evbuffer* buffer)
char const* cookies, tr_web_done_func done_func, void* done_func_user_data,
struct evbuffer* buffer)
{
struct tr_web_task* task = NULL;
@ -744,7 +745,7 @@ char* tr_http_unescape(char const* str, size_t len)
static bool is_rfc2396_alnum(uint8_t ch)
{
return ('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ch == '.' || ch == '-' ||
ch == '_' || ch == '~';
ch == '_' || ch == '~';
}
void tr_http_escape_sha1(char* out, uint8_t const* sha1_digest)

View File

@ -59,7 +59,7 @@ tr_option const opts[] =
char const* getUsage()
{
return "Usage:\n"
" transmission [OPTIONS...] [torrent files]";
" transmission [OPTIONS...] [torrent files]";
}
enum

View File

@ -164,7 +164,7 @@ private:
{
quint32 const ipv4Address = ipAddress.toIPv4Address();
collatedAddress = QLatin1String("1-") + QString::fromLatin1(QByteArray::number(ipv4Address, 16).
rightJustified(8, '0'));
rightJustified(8, '0'));
}
else if (ipAddress.protocol() == QAbstractSocket::IPv6Protocol)
{
@ -529,7 +529,7 @@ void DetailsDialog::refresh()
//: %2 is overall size of torrent data,
//: %3 is percentage (%1/%2*100)
string = tr("%1 of %2 (%3%)").arg(Formatter::sizeToString(haveVerified)).arg(Formatter::sizeToString(sizeWhenDone)).
arg(pct);
arg(pct);
}
else
{
@ -539,7 +539,7 @@ void DetailsDialog::refresh()
//: %3 is percentage (%1/%2*100),
//: %4 is amount of downloaded but not yet verified data
string = tr("%1 of %2 (%3%), %4 Unverified").arg(Formatter::sizeToString(haveVerified + haveUnverified)).
arg(Formatter::sizeToString(sizeWhenDone)).arg(pct).arg(Formatter::sizeToString(haveUnverified));
arg(Formatter::sizeToString(sizeWhenDone)).arg(pct).arg(Formatter::sizeToString(haveUnverified));
}
}
@ -784,7 +784,7 @@ void DetailsDialog::refresh()
else if (pieceSize > 0)
{
string = tr("%1 (%Ln pieces @ %2)", "", pieces).arg(Formatter::sizeToString(size)).
arg(Formatter::memToString(pieceSize));
arg(Formatter::memToString(pieceSize));
}
else
{

View File

@ -23,12 +23,14 @@ class FileTreeItem
Q_DISABLE_COPY(FileTreeItem)
public:
/* *INDENT-OFF* */
enum
{
LOW = (1 << 0),
NORMAL = (1 << 1),
HIGH = (1 << 2)
};
/* *INDENT-ON* */
public:
FileTreeItem(QString const& name = QString(), int fileIndex = -1, uint64_t size = 0) :

View File

@ -686,7 +686,7 @@ void MainWindow::openAbout()
void MainWindow::openHelp()
{
QDesktopServices::openUrl(QUrl(QString::fromLatin1("https://transmissionbt.com/help/gtk/%1.%2x").arg(MAJOR_VERSION).
arg(MINOR_VERSION / 10)));
arg(MINOR_VERSION / 10)));
}
void MainWindow::refreshTitle()
@ -769,13 +769,13 @@ void MainWindow::refreshStatusBar()
{
tr_session_stats const& stats(mySession.getStats());
str = tr("Down: %1, Up: %2").arg(Formatter::sizeToString(stats.downloadedBytes)).
arg(Formatter::sizeToString(stats.uploadedBytes));
arg(Formatter::sizeToString(stats.uploadedBytes));
}
else if (mode == TotalTransferStatsModeName)
{
tr_session_stats const& stats(mySession.getCumulativeStats());
str = tr("Down: %1, Up: %2").arg(Formatter::sizeToString(stats.downloadedBytes)).
arg(Formatter::sizeToString(stats.uploadedBytes));
arg(Formatter::sizeToString(stats.uploadedBytes));
}
else // default is "total-ratio"
{

View File

@ -113,12 +113,12 @@ void MakeProgressDialog::onProgress()
else if (b.result == TR_MAKEMETA_IO_READ)
{
str = tr("Error reading \"%1\": %2").arg(QString::fromUtf8(b.errfile)).
arg(QString::fromLocal8Bit(tr_strerror(b.my_errno)));
arg(QString::fromLocal8Bit(tr_strerror(b.my_errno)));
}
else if (b.result == TR_MAKEMETA_IO_WRITE)
{
str = tr("Error writing \"%1\": %2").arg(QString::fromUtf8(b.errfile)).
arg(QString::fromLocal8Bit(tr_strerror(b.my_errno)));
arg(QString::fromLocal8Bit(tr_strerror(b.my_errno)));
}
ui.progressLabel->setText(str);
@ -221,7 +221,7 @@ void MakeDialog::onSourceChanged()
QString files = tr("%Ln File(s)", nullptr, myBuilder->fileCount);
QString pieces = tr("%Ln Piece(s)", nullptr, myBuilder->pieceCount);
text = tr("%1 in %2; %3 @ %4").arg(Formatter::sizeToString(myBuilder->totalSize)).arg(files).arg(pieces).
arg(Formatter::sizeToString(myBuilder->pieceSize));
arg(Formatter::sizeToString(myBuilder->pieceSize));
}
ui.sourceSizeLabel->setText(text);

View File

@ -92,5 +92,5 @@ RelocateDialog::RelocateDialog(Session& session, TorrentModel const& model, QSet
QString RelocateDialog::newLocation() const
{
return ui.newLocationStack->currentWidget() == ui.newLocationButton ? ui.newLocationButton->path() :
ui.newLocationEdit->text();
ui.newLocationEdit->text();
}

View File

@ -222,7 +222,7 @@ void RpcClient::networkRequestFinished(QNetworkReply* reply)
reply->deleteLater();
QFutureInterface<RpcResponse> promise = reply->property(REQUEST_FUTUREINTERFACE_PROPERTY_KEY).
value<QFutureInterface<RpcResponse>>();
value<QFutureInterface<RpcResponse>>();
#ifdef DEBUG_HTTP
std::cerr << "http response header: " << std::endl;

View File

@ -52,7 +52,7 @@ public:
private:
// Internally queued function. Takes the last response future, makes a
// request and returns a new response future.
typedef std::function<RpcResponseFuture (RpcResponseFuture const&)> QueuedFunction;
typedef std::function<RpcResponseFuture(RpcResponseFuture const&)> QueuedFunction;
// Internally stored error handler function. Takes the last response future and returns nothing.
typedef std::function<void (RpcResponseFuture const&)> ErrorHandlerFunction;
@ -68,7 +68,7 @@ private:
// normal closure, takes response and returns new future
template<typename Func, typename std::enable_if<
std::is_same<typename std::result_of<Func(RpcResponse const&)>::type, RpcResponseFuture>::value
>::type* = nullptr>
>::type* = nullptr>
QueuedFunction normalizeFunc(Func const& func)
{
return [func](RpcResponseFuture const& r)
@ -80,7 +80,7 @@ private:
// closure without argument (first step), takes nothing and returns new future
template<typename Func, typename std::enable_if<
std::is_same<typename std::result_of<Func()>::type, RpcResponseFuture>::value
>::type* = nullptr>
>::type* = nullptr>
QueuedFunction normalizeFunc(Func const& func)
{
return [func](RpcResponseFuture const&)
@ -92,7 +92,7 @@ private:
// closure without return value ("auxiliary"), takes response and returns nothing -- internally we reuse the last future
template<typename Func, typename std::enable_if<
std::is_same<typename std::result_of<Func(RpcResponse const&)>::type, void>::value
>::type* = nullptr>
>::type* = nullptr>
QueuedFunction normalizeFunc(Func const& func)
{
return [func](RpcResponseFuture const& r)
@ -105,7 +105,7 @@ private:
// closure without argument and return value, takes nothing and returns nothing -- next function will also get nothing
template<typename Func, typename std::enable_if<
std::is_same<typename std::result_of<Func()>::type, void>::value
>::type* = nullptr>
>::type* = nullptr>
QueuedFunction normalizeFunc(Func const& func)
{
return [func](RpcResponseFuture const& r)
@ -118,7 +118,7 @@ private:
// normal error handler, takes last response
template<typename Func, typename std::enable_if<
std::is_same<typename std::result_of<Func(RpcResponse const&)>::type, void>::value
>::type* = nullptr>
>::type* = nullptr>
ErrorHandlerFunction normalizeErrorHandler(Func const& func)
{
return [func](RpcResponseFuture const& r)
@ -130,7 +130,7 @@ private:
// error handler without an argument, takes nothing
template<typename Func, typename std::enable_if<
std::is_same<typename std::result_of<Func()>::type, void>::value
>::type* = nullptr>
>::type* = nullptr>
ErrorHandlerFunction normalizeErrorHandler(Func const& func)
{
return [func](RpcResponseFuture const& r)

View File

@ -147,11 +147,16 @@ void Session::copyMagnetLinkToClipboard(int torrentId)
q->add([this](RpcResponse const& r)
{
tr_variant* torrents;
tr_variant* child;
if (!tr_variantDictFindList(r.args.get(), TR_KEY_torrents, &torrents))
{
return;
}
tr_variant* const child = tr_variantListChild(torrents, 0);
char const* str;
if (tr_variantDictFindList(r.args.get(), TR_KEY_torrents, &torrents) &&
(child = tr_variantListChild(torrents, 0)) && tr_variantDictFindStr(child, TR_KEY_magnetLink, &str, nullptr))
if (child != nullptr && tr_variantDictFindStr(child, TR_KEY_magnetLink, &str, nullptr))
{
qApp->clipboard()->setText(QString::fromUtf8(str));
}
@ -998,10 +1003,15 @@ void Session::addTorrent(AddData const& addMe, tr_variant* args, bool trashOrigi
q->add([this, addMe](RpcResponse const& r)
{
tr_variant* dup;
if (!tr_variantDictFindDict(r.args.get(), TR_KEY_torrent_duplicate, &dup))
{
return;
}
char const* str;
if (tr_variantDictFindDict(r.args.get(), TR_KEY_torrent_duplicate, &dup) &&
tr_variantDictFindStr(dup, TR_KEY_name, &str, nullptr))
if (tr_variantDictFindStr(dup, TR_KEY_name, &str, nullptr))
{
QString const name = QString::fromUtf8(str);
QMessageBox* d = new QMessageBox(QMessageBox::Warning, tr("Add Torrent"),

View File

@ -10,12 +10,12 @@
QIcon::Mode StyleHelper::getIconMode(QStyle::State state)
{
if ((state & QStyle::State_Enabled) == 0)
if (!state.testFlag(QStyle::State_Enabled))
{
return QIcon::Disabled;
}
if ((state & QStyle::State_Selected) != 0)
if (state.testFlag(QStyle::State_Selected))
{
return QIcon::Selected;
}

View File

@ -175,7 +175,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
//: First part of torrent progress string;
//: %1 is the percentage of torrent metadata downloaded
str = tr("Magnetized transfer - retrieving metadata (%1%)").
arg(Formatter::percentToString(tor.metadataPercentDone() * 100.0));
arg(Formatter::percentToString(tor.metadataPercentDone() * 100.0));
}
else if (!isDone) // downloading
{
@ -184,7 +184,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
//: %2 is how much we'll have when done,
//: %3 is a percentage of the two
str = tr("%1 of %2 (%3%)").arg(Formatter::sizeToString(haveTotal)).arg(Formatter::sizeToString(tor.sizeWhenDone())).
arg(Formatter::percentToString(tor.percentDone() * 100.0));
arg(Formatter::percentToString(tor.percentDone() * 100.0));
}
else if (!isSeed) // partial seed
{
@ -198,10 +198,10 @@ QString TorrentDelegate::progressString(Torrent const& tor)
//: %5 is our upload-to-download ratio,
//: %6 is the ratio we want to reach before we stop uploading
str = tr("%1 of %2 (%3%), uploaded %4 (Ratio: %5 Goal: %6)").arg(Formatter::sizeToString(haveTotal)).
arg(Formatter::sizeToString(tor.totalSize())).
arg(Formatter::percentToString(tor.percentComplete() * 100.0)).
arg(Formatter::sizeToString(tor.uploadedEver())).arg(Formatter::ratioToString(tor.ratio())).
arg(Formatter::ratioToString(seedRatio));
arg(Formatter::sizeToString(tor.totalSize())).
arg(Formatter::percentToString(tor.percentComplete() * 100.0)).
arg(Formatter::sizeToString(tor.uploadedEver())).arg(Formatter::ratioToString(tor.ratio())).
arg(Formatter::ratioToString(seedRatio));
}
else
{
@ -212,9 +212,9 @@ QString TorrentDelegate::progressString(Torrent const& tor)
//: %4 is how much we've uploaded,
//: %5 is our upload-to-download ratio
str = tr("%1 of %2 (%3%), uploaded %4 (Ratio: %5)").arg(Formatter::sizeToString(haveTotal)).
arg(Formatter::sizeToString(tor.totalSize())).
arg(Formatter::percentToString(tor.percentComplete() * 100.0)).
arg(Formatter::sizeToString(tor.uploadedEver())).arg(Formatter::ratioToString(tor.ratio()));
arg(Formatter::sizeToString(tor.totalSize())).
arg(Formatter::percentToString(tor.percentComplete() * 100.0)).
arg(Formatter::sizeToString(tor.uploadedEver())).arg(Formatter::ratioToString(tor.ratio()));
}
}
else // seeding
@ -227,8 +227,8 @@ QString TorrentDelegate::progressString(Torrent const& tor)
//: %3 is our upload-to-download ratio,
//: %4 is the ratio we want to reach before we stop uploading
str = tr("%1, uploaded %2 (Ratio: %3 Goal: %4)").arg(Formatter::sizeToString(haveTotal)).
arg(Formatter::sizeToString(tor.uploadedEver())).arg(Formatter::ratioToString(tor.ratio())).
arg(Formatter::ratioToString(seedRatio));
arg(Formatter::sizeToString(tor.uploadedEver())).arg(Formatter::ratioToString(tor.ratio())).
arg(Formatter::ratioToString(seedRatio));
}
else // seeding w/o a ratio
{
@ -237,7 +237,7 @@ QString TorrentDelegate::progressString(Torrent const& tor)
//: %2 is how much we've uploaded,
//: %3 is our upload-to-download ratio
str = tr("%1, uploaded %2 (Ratio: %3)").arg(Formatter::sizeToString(haveTotal)).
arg(Formatter::sizeToString(tor.uploadedEver())).arg(Formatter::ratioToString(tor.ratio()));
arg(Formatter::sizeToString(tor.uploadedEver())).arg(Formatter::ratioToString(tor.ratio()));
}
}
@ -329,7 +329,7 @@ QString TorrentDelegate::statusString(Torrent const& tor)
if (!tor.hasMetadata())
{
str = tr("Downloading metadata from %Ln peer(s) (%1% done)", nullptr, tor.peersWeAreDownloadingFrom()).
arg(Formatter::percentToString(100.0 * tor.metadataPercentDone()));
arg(Formatter::percentToString(100.0 * tor.metadataPercentDone()));
}
else
{
@ -344,7 +344,7 @@ QString TorrentDelegate::statusString(Torrent const& tor)
{
//: First part of phrase "Downloading from ... of ... connected peer(s) and ... web seed(s)"
str = tr("Downloading from %1 of %Ln connected peer(s)", nullptr, tor.connectedPeersAndWebseeds()).
arg(tor.peersWeAreDownloadingFrom());
arg(tor.peersWeAreDownloadingFrom());
}
if (tor.webseedsWeAreDownloadingFrom())
@ -364,7 +364,8 @@ QString TorrentDelegate::statusString(Torrent const& tor)
}
else
{
str = tr("Seeding to %1 of %Ln connected peer(s)", nullptr, tor.connectedPeers()).arg(tor.peersWeAreUploadingTo());
str = tr("Seeding to %1 of %Ln connected peer(s)", nullptr, tor.connectedPeers()).
arg(tor.peersWeAreUploadingTo());
}
break;

View File

@ -113,7 +113,7 @@ ItemLayout::ItemLayout(QString const& nameText, QString const& statusText, QIcon
QSize const barSize(barStyle.rect.width() * 2 - style->subElementRect(QStyle::SE_ProgressBarGroove, &barStyle).width(),
barStyle.rect.height());
QRect baseRect(topLeft, QSize(width, std::max({iconSize, nameSize.height(), statusSize.height(), barSize.height()})));
QRect baseRect(topLeft, QSize(width, std::max({ iconSize, nameSize.height(), statusSize.height(), barSize.height() })));
iconRect = style->alignedRect(direction, Qt::AlignLeft | Qt::AlignVCenter, QSize(iconSize, iconSize), baseRect);
emblemRect = style->alignedRect(direction, Qt::AlignRight | Qt::AlignBottom, emblemIcon.actualSize(iconRect.size() / 2,

View File

@ -215,20 +215,20 @@ QString TrackerDelegate::getText(TrackerInfo const& inf) const
if (inf.st.lastAnnounceSucceeded)
{
//: %1 and %2 are replaced with HTML markup, %3 is duration
str += tr("Got a list of%1 %Ln peer(s)%2 %3 ago", nullptr, inf.st.lastAnnouncePeerCount).arg(success_markup_begin).
arg(success_markup_end).arg(tstr);
str += tr("Got a list of%1 %Ln peer(s)%2 %3 ago", nullptr, inf.st.lastAnnouncePeerCount).
arg(success_markup_begin).arg(success_markup_end).arg(tstr);
}
else if (inf.st.lastAnnounceTimedOut)
{
//: %1 and %2 are replaced with HTML markup, %3 is duration
str += tr("Peer list request %1timed out%2 %3 ago; will retry").arg(timeout_markup_begin).
arg(timeout_markup_end).arg(tstr);
arg(timeout_markup_end).arg(tstr);
}
else
{
//: %1 and %3 are replaced with HTML markup, %2 is error message, %4 is duration
str += tr("Got an error %1\"%2\"%3 %4 ago").arg(err_markup_begin).arg(inf.st.lastAnnounceResult).
arg(err_markup_end).arg(tstr);
arg(err_markup_end).arg(tstr);
}
}
@ -277,25 +277,25 @@ QString TrackerDelegate::getText(TrackerInfo const& inf) const
//: First part of phrase "Tracker had ... seeder(s) and ... leecher(s) ... ago";
//: %1 and %2 are replaced with HTML markup
str += tr("Tracker had%1 %Ln seeder(s)%2", nullptr, inf.st.seederCount).arg(success_markup_begin).
arg(success_markup_end);
arg(success_markup_end);
//: Second part of phrase "Tracker had ... seeder(s) and ... leecher(s) ... ago";
//: %1 and %2 are replaced with HTML markup, %3 is duration;
//: notice that leading space (before "and") is included here
str += tr(" and%1 %Ln leecher(s)%2 %3 ago", nullptr, inf.st.leecherCount).arg(success_markup_begin).
arg(success_markup_end).arg(tstr);
arg(success_markup_end).arg(tstr);
}
else
{
//: %1 and %2 are replaced with HTML markup, %3 is duration
str += tr("Tracker had %1no information%2 on peer counts %3 ago").arg(success_markup_begin).
arg(success_markup_end).arg(tstr);
arg(success_markup_end).arg(tstr);
}
}
else
{
//: %1 and %3 are replaced with HTML markup, %2 is error message, %4 is duration
str += tr("Got a scrape error %1\"%2\"%3 %4 ago").arg(err_markup_begin).arg(inf.st.lastScrapeResult).
arg(err_markup_end).arg(tstr);
arg(err_markup_end).arg(tstr);
}
}

View File

@ -210,7 +210,7 @@ int Utils::measureViewItem(QAbstractItemView* view, QString const& text)
option.font = view->font();
return view->style()->sizeFromContents(QStyle::CT_ItemViewItem, &option, QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), view).
width();
width();
}
int Utils::measureHeaderItem(QHeaderView* view, QString const& text)

View File

@ -51,7 +51,7 @@ public:
{
if (dialog.isNull())
{
dialog = new DialogT(std::forward<ArgsT>(args) ...);
dialog = new DialogT(std::forward<ArgsT>(args)...);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->show();
}

File diff suppressed because it is too large Load Diff

View File

@ -238,15 +238,15 @@ enum
static char const* getUsage(void)
{
return MY_NAME " " LONG_VERSION_STRING "\n"
"A fast and easy BitTorrent client\n"
"https://transmissionbt.com/\n"
"\n"
"Usage: " MY_NAME " [host] [options]\n"
" " MY_NAME " [port] [options]\n"
" " MY_NAME " [host:port] [options]\n"
" " MY_NAME " [http(s?)://host:port/transmission/] [options]\n"
"\n"
"See the man page for detailed explanations and many examples.";
"A fast and easy BitTorrent client\n"
"https://transmissionbt.com/\n"
"\n"
"Usage: " MY_NAME " [host] [options]\n"
" " MY_NAME " [port] [options]\n"
" " MY_NAME " [host:port] [options]\n"
" " MY_NAME " [http(s?)://host:port/transmission/] [options]\n"
"\n"
"See the man page for detailed explanations and many examples.";
}
/***
@ -271,7 +271,8 @@ static tr_option opts[] =
{ '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, "<speed>" },
{ 'd', "downlimit", "Set the max download speed in "SPEED_K_STR " for the current torrent(s) or globally", "d", 1,
"<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 },
@ -317,8 +318,10 @@ static tr_option opts[] =
{ 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 },
{ 953, "global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio", "gsr", 1, "ratio" },
{ 954, "no-global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed regardless of ratio", "GSR", 0, NULL },
{ 953, "global-seedratio", "All torrents, unless overridden by a per-torrent setting, should seed until a specific ratio",
"gsr", 1, "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 },
@ -336,7 +339,8 @@ static tr_option opts[] =
{ 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 },
{ '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>" },
{ '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 },
@ -1033,7 +1037,8 @@ static void printDetails(tr_variant* top)
}
}
if (tr_variantDictFindInt(t, TR_KEY_peersConnected, &i) && tr_variantDictFindInt(t, TR_KEY_peersGettingFromUs, &j) &&
if (tr_variantDictFindInt(t, TR_KEY_peersConnected, &i) &&
tr_variantDictFindInt(t, TR_KEY_peersGettingFromUs, &j) &&
tr_variantDictFindInt(t, TR_KEY_peersSendingToUs, &k))
{
printf(" Peers: connected to %" PRId64 ", uploading to %" PRId64 ", downloading from %" PRId64 "\n", i, j, k);
@ -1126,7 +1131,8 @@ static void printDetails(tr_variant* top)
printf("LIMITS & BANDWIDTH\n");
if (tr_variantDictFindBool(t, TR_KEY_downloadLimited, &boolVal) && tr_variantDictFindInt(t, TR_KEY_downloadLimit, &i))
if (tr_variantDictFindBool(t, TR_KEY_downloadLimited, &boolVal) &&
tr_variantDictFindInt(t, TR_KEY_downloadLimit, &i))
{
printf(" Download Limit: ");
@ -1230,8 +1236,10 @@ static void printFileList(tr_variant* top)
char const* filename;
tr_variant* file = tr_variantListChild(files, j);
if (tr_variantDictFindInt(file, TR_KEY_length, &length) && tr_variantDictFindStr(file, TR_KEY_name, &filename, NULL) &&
tr_variantDictFindInt(file, TR_KEY_bytesCompleted, &have) && tr_variantGetInt(tr_variantListChild(priorities, j), &priority) &&
if (tr_variantDictFindInt(file, TR_KEY_length, &length) &&
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))
{
char sizestr[64];
@ -1277,12 +1285,15 @@ static void printPeersImpl(tr_variant* peers)
int64_t rateToPeer;
tr_variant* d = tr_variantListChild(peers, i);
if (tr_variantDictFindStr(d, TR_KEY_address, &address, NULL) && tr_variantDictFindStr(d, TR_KEY_clientName, &client, NULL) &&
tr_variantDictFindReal(d, TR_KEY_progress, &progress) && tr_variantDictFindStr(d, TR_KEY_flagStr, &flagstr, NULL) &&
tr_variantDictFindInt(d, TR_KEY_rateToClient, &rateToClient) && tr_variantDictFindInt(d, TR_KEY_rateToPeer, &rateToPeer))
if (tr_variantDictFindStr(d, TR_KEY_address, &address, NULL) &&
tr_variantDictFindStr(d, TR_KEY_clientName, &client, NULL) &&
tr_variantDictFindReal(d, TR_KEY_progress, &progress) &&
tr_variantDictFindStr(d, TR_KEY_flagStr, &flagstr, NULL) &&
tr_variantDictFindInt(d, TR_KEY_rateToClient, &rateToClient) &&
tr_variantDictFindInt(d, TR_KEY_rateToPeer, &rateToPeer))
{
printf("%-40s %-12s %-5.1f %6.1f %6.1f %s\n", address, flagstr, (progress * 100.0), rateToClient / (double)tr_speed_K,
rateToPeer / (double)tr_speed_K, client);
printf("%-40s %-12s %-5.1f %6.1f %6.1f %s\n", address, flagstr, (progress * 100.0),
rateToClient / (double)tr_speed_K, rateToPeer / (double)tr_speed_K, client);
}
}
}
@ -1351,7 +1362,8 @@ static void printPieces(tr_variant* top)
size_t rawlen;
tr_variant* torrent = tr_variantListChild(torrents, i);
if (tr_variantDictFindRaw(torrent, TR_KEY_pieces, &raw, &rawlen) && tr_variantDictFindInt(torrent, TR_KEY_pieceCount, &j))
if (tr_variantDictFindRaw(torrent, TR_KEY_pieces, &raw, &rawlen) &&
tr_variantDictFindInt(torrent, TR_KEY_pieceCount, &j))
{
assert(j >= 0);
printPiecesImpl(raw, rawlen, (size_t)j);
@ -1392,8 +1404,8 @@ static void printTorrentList(tr_variant* top)
double total_down = 0;
char haveStr[32];
printf("%-4s %-4s %9s %-8s %6s %6s %-5s %-11s %s\n", "ID", "Done", "Have", "ETA", "Up", "Down", "Ratio", "Status",
"Name");
printf("%-4s %-4s %9s %-8s %6s %6s %-5s %-11s %s\n", "ID", "Done", "Have", "ETA", "Up", "Down", "Ratio",
"Status", "Name");
for (int i = 0, n = tr_variantListSize(list); i < n; ++i)
{
@ -1408,10 +1420,14 @@ static void printTorrentList(tr_variant* top)
char const* name;
tr_variant* d = tr_variantListChild(list, i);
if (tr_variantDictFindInt(d, TR_KEY_eta, &eta) && tr_variantDictFindInt(d, TR_KEY_id, &id) &&
tr_variantDictFindInt(d, TR_KEY_leftUntilDone, &leftUntilDone) && tr_variantDictFindStr(d, TR_KEY_name, &name, NULL) &&
tr_variantDictFindInt(d, TR_KEY_rateDownload, &down) && tr_variantDictFindInt(d, TR_KEY_rateUpload, &up) &&
tr_variantDictFindInt(d, TR_KEY_sizeWhenDone, &sizeWhenDone) && tr_variantDictFindInt(d, TR_KEY_status, &status) &&
if (tr_variantDictFindInt(d, TR_KEY_eta, &eta) &&
tr_variantDictFindInt(d, TR_KEY_id, &id) &&
tr_variantDictFindInt(d, TR_KEY_leftUntilDone, &leftUntilDone) &&
tr_variantDictFindStr(d, TR_KEY_name, &name, NULL) &&
tr_variantDictFindInt(d, TR_KEY_rateDownload, &down) &&
tr_variantDictFindInt(d, TR_KEY_rateUpload, &up) &&
tr_variantDictFindInt(d, TR_KEY_sizeWhenDone, &sizeWhenDone) &&
tr_variantDictFindInt(d, TR_KEY_status, &status) &&
tr_variantDictFindReal(d, TR_KEY_uploadRatio, &ratio))
{
char etaStr[16];
@ -1790,9 +1806,9 @@ static void printSession(tr_variant* top)
tr_strlcpy(buf, "Unlimited", sizeof(buf));
}
printf(" Upload speed limit: %s (%s limit: %s; %s turtle limit: %s)\n", buf, upEnabled ? "Enabled" : "Disabled",
tr_formatter_speed_KBps(buf2, upLimit, sizeof(buf2)), altEnabled ? "Enabled" : "Disabled",
tr_formatter_speed_KBps(buf3, altUp, sizeof(buf3)));
printf(" Upload speed limit: %s (%s limit: %s; %s turtle limit: %s)\n", buf,
upEnabled ? "Enabled" : "Disabled", tr_formatter_speed_KBps(buf2, upLimit, sizeof(buf2)),
altEnabled ? "Enabled" : "Disabled", tr_formatter_speed_KBps(buf3, altUp, sizeof(buf3)));
if (altEnabled)
{
@ -1807,14 +1823,14 @@ static void printSession(tr_variant* top)
tr_strlcpy(buf, "Unlimited", sizeof(buf));
}
printf(" Download speed limit: %s (%s limit: %s; %s turtle limit: %s)\n", buf, downEnabled ? "Enabled" : "Disabled",
tr_formatter_speed_KBps(buf2, downLimit, sizeof(buf2)), altEnabled ? "Enabled" : "Disabled",
tr_formatter_speed_KBps(buf3, altDown, sizeof(buf3)));
printf(" Download speed limit: %s (%s limit: %s; %s turtle limit: %s)\n", buf,
downEnabled ? "Enabled" : "Disabled", tr_formatter_speed_KBps(buf2, downLimit, sizeof(buf2)),
altEnabled ? "Enabled" : "Disabled", tr_formatter_speed_KBps(buf3, altDown, sizeof(buf3)));
if (altTimeEnabled)
{
printf(" Turtle schedule: %02d:%02d - %02d:%02d ", (int)(altBegin / 60), (int)(altBegin % 60), (int)(altEnd / 60),
(int)(altEnd % 60));
printf(" Turtle schedule: %02d:%02d - %02d:%02d ", (int)(altBegin / 60), (int)(altBegin % 60),
(int)(altEnd / 60), (int)(altEnd % 60));
if ((altDay & TR_SCHED_SUN) != 0)
{
@ -1895,8 +1911,10 @@ static void printSessionStats(tr_variant* top)
printf(" Duration: %s\n", tr_strltime(buf, secs, sizeof(buf)));
}
if (tr_variantDictFindDict(args, TR_KEY_cumulative_stats, &d) && tr_variantDictFindInt(d, TR_KEY_sessionCount, &sessions) &&
tr_variantDictFindInt(d, TR_KEY_uploadedBytes, &up) && tr_variantDictFindInt(d, TR_KEY_downloadedBytes, &down) &&
if (tr_variantDictFindDict(args, TR_KEY_cumulative_stats, &d) &&
tr_variantDictFindInt(d, TR_KEY_sessionCount, &sessions) &&
tr_variantDictFindInt(d, TR_KEY_uploadedBytes, &up) &&
tr_variantDictFindInt(d, TR_KEY_downloadedBytes, &down) &&
tr_variantDictFindInt(d, TR_KEY_secondsActive, &secs))
{
printf("\nTOTAL\n");
@ -1918,7 +1936,8 @@ static int processResponse(char const* rpcurl, void const* response, size_t len)
if (debug)
{
fprintf(stderr, "got response (len %d):\n--------\n%*.*s\n--------\n", (int)len, (int)len, (int)len, (char const*)response);
fprintf(stderr, "got response (len %d):\n--------\n%*.*s\n--------\n", (int)len, (int)len, (int)len,
(char const*)response);
}
if (tr_variantFromJson(&top, response, len) != 0)
@ -1985,7 +2004,8 @@ static int processResponse(char const* rpcurl, void const* response, size_t len)
int64_t i;
tr_variant* b = &top;
if (tr_variantDictFindDict(&top, ARGUMENTS, &b) && tr_variantDictFindDict(b, TR_KEY_torrent_added, &b) &&
if (tr_variantDictFindDict(&top, ARGUMENTS, &b) &&
tr_variantDictFindDict(b, TR_KEY_torrent_added, &b) &&
tr_variantDictFindInt(b, TR_KEY_id, &i))
{
tr_snprintf(id, sizeof(id), "%" PRId64, i);

View File

@ -194,7 +194,7 @@ static void showInfo(tr_info const* inf)
{
files[i] = &inf->files[i];
}
if (!unsorted)
{
qsort(files, inf->fileCount, sizeof(tr_file*), compare_files_by_name);