Align type qualifiers to the right (code style)

This way all the qualifiers (`const`, `volatile`, `mutable`) are grouped
together, e.g. `T const* const x` vs. `const T* const x`. Also helps reading
types right-to-left, e.g. "constant pointer to constant T" vs. "constant
pointer to T which is constant".
This commit is contained in:
Mike Gelfand 2017-04-20 19:02:19 +03:00
parent d7930984ef
commit dadffa2c0f
261 changed files with 4637 additions and 4631 deletions

View File

@ -71,9 +71,9 @@ static bool verify = false;
static sig_atomic_t gotsig = false;
static sig_atomic_t manualUpdate = false;
static const char* torrentPath = NULL;
static char const* torrentPath = NULL;
static const struct tr_option options[] =
static struct tr_option const options[] =
{
{ 'b', "blocklist", "Enable peer blocklists", "b", 0, NULL },
{ 'B', "no-blocklist", "Disable peer blocklists", "B", 0, NULL },
@ -96,14 +96,14 @@ static const struct tr_option options[] =
{ 0, NULL, NULL, NULL, 0, NULL }
};
static const char* getUsage(void)
static char const* getUsage(void)
{
return "A fast and easy BitTorrent client\n"
"\n"
"Usage: " MY_READABLE_NAME " [options] <file|url|magnet>";
}
static int parseCommandLine(tr_variant*, int argc, const char** argv);
static int parseCommandLine(tr_variant*, int argc, char const** argv);
static void sigHandler(int signal);
@ -136,13 +136,13 @@ static char* tr_strlratio(char* buf, double ratio, size_t buflen)
static bool waitingOnWeb;
static void onTorrentFileDownloaded(tr_session* session UNUSED, bool did_connect UNUSED, bool did_timeout UNUSED,
long response_code UNUSED, const void* response, size_t response_byte_count, void* ctor)
long response_code UNUSED, void const* response, size_t response_byte_count, void* ctor)
{
tr_ctorSetMetainfo(ctor, response, response_byte_count);
waitingOnWeb = false;
}
static void getStatusStr(const tr_stat* st, char* buf, size_t buflen)
static void getStatusStr(tr_stat const* st, char* buf, size_t buflen)
{
if (st->activity == TR_STATUS_CHECK_WAIT)
{
@ -184,12 +184,12 @@ static void getStatusStr(const tr_stat* st, char* buf, size_t buflen)
}
}
static const char* getConfigDir(int argc, const char** argv)
static char const* getConfigDir(int argc, char const** argv)
{
int c;
const char* configDir = NULL;
const char* optarg;
const int ind = tr_optind;
char const* configDir = NULL;
char const* optarg;
int const ind = tr_optind;
while ((c = tr_getopt(getUsage(), argc, argv, options, &optarg)))
{
@ -216,10 +216,10 @@ int tr_main(int argc, char* argv[])
tr_ctor* ctor;
tr_torrent* tor = NULL;
tr_variant settings;
const char* configDir;
char const* configDir;
uint8_t* fileContents;
size_t fileLength;
const char* str;
char const* str;
tr_formatter_mem_init(MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR);
tr_formatter_size_init(DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR);
@ -236,11 +236,11 @@ int tr_main(int argc, char* argv[])
/* load the defaults from config file + libtransmission defaults */
tr_variantInitDict(&settings, 0);
configDir = getConfigDir(argc, (const char**)argv);
configDir = getConfigDir(argc, (char const**)argv);
tr_sessionLoadSettings(&settings, configDir, MY_CONFIG_NAME);
/* the command line overrides defaults */
if (parseCommandLine(&settings, argc, (const char**)argv))
if (parseCommandLine(&settings, argc, (char const**)argv))
{
return EXIT_FAILURE;
}
@ -333,8 +333,8 @@ int tr_main(int argc, char* argv[])
for (;;)
{
char line[LINEWIDTH];
const tr_stat* st;
const char* messageName[] =
tr_stat const* st;
char const* messageName[] =
{
NULL,
"Tracker gave a warning:",
@ -395,10 +395,10 @@ int tr_main(int argc, char* argv[])
****
***/
static int parseCommandLine(tr_variant* d, int argc, const char** argv)
static int parseCommandLine(tr_variant* d, int argc, char const** argv)
{
int c;
const char* optarg;
char const* optarg;
while ((c = tr_getopt(getUsage(), argc, argv, options, &optarg)))
{

View File

@ -24,7 +24,7 @@
****
***/
static const dtr_callbacks* callbacks = NULL;
static dtr_callbacks const* callbacks = NULL;
static void* callback_arg = NULL;
static int signal_pipe[2];
@ -33,7 +33,7 @@ static int signal_pipe[2];
****
***/
static void set_system_error(tr_error** error, int code, const char* message)
static void set_system_error(tr_error** error, int code, char const* message)
{
tr_error_set(error, code, "%s (%d): %s", message, code, tr_strerror(code));
}
@ -62,7 +62,7 @@ static void handle_signal(int sig)
static void send_signal_to_pipe(int sig)
{
const int old_errno = errno;
int const old_errno = errno;
if (write(signal_pipe[1], &sig, sizeof(sig)) == -1)
{
@ -143,7 +143,7 @@ static bool setup_signal_handler(int sig, tr_error** error)
****
***/
bool dtr_daemon(const dtr_callbacks* cb, void* cb_arg, bool foreground, int* exit_code, tr_error** error)
bool dtr_daemon(dtr_callbacks const* cb, void* cb_arg, bool foreground, int* exit_code, tr_error** error)
{
callbacks = cb;
callback_arg = cb_arg;
@ -194,7 +194,7 @@ bool dtr_daemon(const dtr_callbacks* cb, void* cb_arg, bool foreground, int* exi
*/
{
const int fd = open("/dev/null", O_RDWR, 0);
int const fd = open("/dev/null", O_RDWR, 0);
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);

View File

@ -28,10 +28,10 @@
#define SERVICE_CONTROL_PRESHUTDOWN 0x0000000F
#endif
static const dtr_callbacks* callbacks = NULL;
static dtr_callbacks const* callbacks = NULL;
static void* callback_arg = NULL;
static const LPCWSTR service_name = L"TransmissionDaemon";
static LPCWSTR const service_name = L"TransmissionDaemon";
static SERVICE_STATUS_HANDLE status_handle = NULL;
static DWORD current_state = SERVICE_STOPPED;
@ -42,14 +42,14 @@ static HANDLE service_stop_thread = NULL;
****
***/
static void set_system_error(tr_error** error, DWORD code, const char* message)
static void set_system_error(tr_error** error, DWORD code, char const* message)
{
char* const system_message = tr_win32_format_message(code);
tr_error_set(error, code, "%s (0x%08lx): %s", message, code, system_message);
tr_free(system_message);
}
static void do_log_system_error(const char* file, int line, tr_log_level level, DWORD code, const char* message)
static void do_log_system_error(char const* file, int line, tr_log_level level, DWORD code, char const* message)
{
char* const system_message = tr_win32_format_message(code);
tr_logAddMessage(file, line, level, "[dtr_daemon] %s (0x%08lx): %s", message, code, system_message);
@ -59,7 +59,7 @@ static void do_log_system_error(const char* file, int line, tr_log_level level,
#define log_system_error(level, code, message) \
do \
{ \
const DWORD local_code = (code); \
DWORD const local_code = (code); \
\
if (tr_logLevelIsActive((level))) \
{ \
@ -107,7 +107,7 @@ static unsigned int __stdcall service_stop_thread_main(void* param)
{
callbacks->on_stop(callback_arg);
const DWORD sleep_time = 500;
DWORD const sleep_time = 500;
DWORD wait_time = (DWORD)(UINT_PTR)param;
for (DWORD checkpoint = 2; WaitForSingleObject(service_thread, sleep_time) == WAIT_TIMEOUT; ++checkpoint)
@ -126,7 +126,7 @@ static void stop_service(void)
return;
}
const DWORD wait_time = 30 * 1000;
DWORD const wait_time = 30 * 1000;
update_service_status(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, wait_time);
@ -224,7 +224,7 @@ static VOID WINAPI service_main(DWORD argc, LPWSTR* argv)
****
***/
bool dtr_daemon(const dtr_callbacks* cb, void* cb_arg, bool foreground, int* exit_code, tr_error** error)
bool dtr_daemon(dtr_callbacks const* cb, void* cb_arg, bool foreground, int* exit_code, tr_error** error)
{
callbacks = cb;
callback_arg = cb_arg;
@ -243,7 +243,7 @@ bool dtr_daemon(const dtr_callbacks* cb, void* cb_arg, bool foreground, int* exi
}
else
{
const SERVICE_TABLE_ENTRY service_table[] =
SERVICE_TABLE_ENTRY const service_table[] =
{
{ (LPWSTR)service_name, &service_main },
{ NULL, NULL }

View File

@ -38,11 +38,11 @@
#else
static void sd_notify(int status UNUSED, const char* str UNUSED)
static void sd_notify(int status UNUSED, char const* str UNUSED)
{
}
static void sd_notifyf(int status UNUSED, const char* fmt UNUSED, ...)
static void sd_notifyf(int status UNUSED, char const* fmt UNUSED, ...)
{
}
@ -73,7 +73,7 @@ static void sd_notifyf(int status UNUSED, const char* fmt UNUSED, ...)
#define SPEED_T_STR "TB/s"
static bool seenHUP = false;
static const char* logfileName = NULL;
static char const* logfileName = NULL;
static tr_sys_file_t logfile = TR_BAD_SYS_FILE;
static tr_session* mySession = NULL;
static tr_quark key_pidfile = 0;
@ -84,7 +84,7 @@ static struct event_base* ev_base = NULL;
**** Config File
***/
static const char* getUsage(void)
static char const* getUsage(void)
{
return "Transmission " LONG_VERSION_STRING " https://transmissionbt.com/\n"
"A fast and easy BitTorrent client\n"
@ -96,7 +96,7 @@ static const char* getUsage(void)
"Usage: " MY_NAME " [options]";
}
static const struct tr_option options[] =
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 },
@ -143,11 +143,11 @@ static const struct tr_option options[] =
{ 0, NULL, NULL, NULL, 0, NULL }
};
static bool reopen_log_file(const char* filename)
static bool reopen_log_file(char const* filename)
{
tr_error* error = NULL;
const tr_sys_file_t old_log_file = logfile;
const tr_sys_file_t new_log_file = tr_sys_file_open(filename, TR_SYS_FILE_WRITE | TR_SYS_FILE_CREATE | TR_SYS_FILE_APPEND, 0666,
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);
if (new_log_file == TR_BAD_SYS_FILE)
@ -167,12 +167,12 @@ static bool reopen_log_file(const char* filename)
return true;
}
static const char* getConfigDir(int argc, const char* const* argv)
static char const* getConfigDir(int argc, char const* const* argv)
{
int c;
const char* configDir = NULL;
const char* optarg;
const int ind = tr_optind;
char const* configDir = NULL;
char const* optarg;
int const ind = tr_optind;
while ((c = tr_getopt(getUsage(), argc, argv, options, &optarg)))
{
@ -193,7 +193,7 @@ static const char* getConfigDir(int argc, const char* const* argv)
return configDir;
}
static tr_watchdir_status onFileAdded(tr_watchdir_t dir, const char* name, void* context)
static tr_watchdir_status onFileAdded(tr_watchdir_t dir, char const* name, void* context)
{
tr_session* session = context;
@ -217,7 +217,7 @@ static tr_watchdir_status onFileAdded(tr_watchdir_t dir, const char* name, void*
else
{
bool trash = false;
const bool test = tr_ctorGetDeleteSource(ctor, &trash);
bool const test = tr_ctorGetDeleteSource(ctor, &trash);
tr_logAddInfo("Parsing .torrent file successful \"%s\"", name);
@ -252,7 +252,7 @@ static tr_watchdir_status onFileAdded(tr_watchdir_t dir, const char* name, void*
return err == TR_PARSE_ERR ? TR_WATCHDIR_RETRY : TR_WATCHDIR_ACCEPT;
}
static void printMessage(tr_sys_file_t logfile, int level, const char* name, const char* message, const char* file, int line)
static void printMessage(tr_sys_file_t logfile, int level, char const* name, char const* message, char const* file, int line)
{
if (logfile != TR_BAD_SYS_FILE)
{
@ -307,7 +307,7 @@ static void printMessage(tr_sys_file_t logfile, int level, const char* name, con
static void pumpLogMessages(tr_sys_file_t logfile)
{
const tr_log_message* l;
tr_log_message const* l;
tr_log_message* list = tr_logGetQueue();
for (l = list; l != NULL; l = l->next)
@ -325,8 +325,8 @@ static void pumpLogMessages(tr_sys_file_t logfile)
static void reportStatus(void)
{
const double up = tr_sessionGetRawSpeed_KBps(mySession, TR_UP);
const double dn = tr_sessionGetRawSpeed_KBps(mySession, TR_DOWN);
double const up = tr_sessionGetRawSpeed_KBps(mySession, TR_UP);
double const dn = tr_sessionGetRawSpeed_KBps(mySession, TR_DOWN);
if (up > 0 || dn > 0)
{
@ -355,11 +355,11 @@ static tr_rpc_callback_status on_rpc_callback(tr_session* session UNUSED, tr_rpc
return TR_RPC_OK;
}
static bool parse_args(int argc, const char** argv, tr_variant* settings, bool* paused, bool* dump_settings, bool* foreground,
static bool parse_args(int argc, char const** argv, tr_variant* settings, bool* paused, bool* dump_settings, bool* foreground,
int* exit_code)
{
int c;
const char* optarg;
char const* optarg;
*paused = false;
*dump_settings = false;
@ -560,7 +560,7 @@ static bool parse_args(int argc, const char** argv, tr_variant* settings, bool*
struct daemon_data
{
tr_variant settings;
const char* configDir;
char const* configDir;
bool paused;
};
@ -574,7 +574,7 @@ static void daemon_reconfigure(void* arg UNUSED)
else
{
tr_variant settings;
const char* configDir;
char const* configDir;
/* reopen the logfile to allow for log rotation */
if (logfileName != NULL)
@ -601,7 +601,7 @@ static void daemon_stop(void* arg UNUSED)
static int daemon_start(void* raw_arg, bool foreground)
{
bool boolVal;
const char* pid_filename;
char const* pid_filename;
bool pidfile_created = false;
tr_session* session = NULL;
struct event* status_ev = NULL;
@ -609,7 +609,7 @@ static int daemon_start(void* raw_arg, bool foreground)
struct daemon_data* const arg = raw_arg;
tr_variant* const settings = &arg->settings;
const char* const configDir = arg->configDir;
char const* const configDir = arg->configDir;
#ifndef HAVE_SYSLOG
(void)foreground;
@ -678,7 +678,7 @@ static int daemon_start(void* raw_arg, bool foreground)
/* maybe add a watchdir */
if (tr_variantDictFindBool(settings, TR_KEY_watch_dir_enabled, &boolVal) && boolVal)
{
const char* dir;
char const* dir;
bool force_generic;
if (!tr_variantDictFindBool(settings, key_watch_dir_force_generic, &force_generic))
@ -791,7 +791,7 @@ cleanup:
int tr_main(int argc, char* argv[])
{
const dtr_callbacks cb =
dtr_callbacks const cb =
{
.on_start = &daemon_start,
.on_stop = &daemon_stop,
@ -804,7 +804,7 @@ int tr_main(int argc, char* argv[])
struct daemon_data arg;
tr_variant* const settings = &arg.settings;
const char** const configDir = &arg.configDir;
char const** const configDir = &arg.configDir;
key_pidfile = tr_quark_new("pidfile", 7);
key_watch_dir_force_generic = tr_quark_new("watch-dir-force-generic", 23);
@ -812,11 +812,11 @@ int tr_main(int argc, char* argv[])
/* load settings from defaults + config file */
tr_variantInitDict(settings, 0);
tr_variantDictAddBool(settings, TR_KEY_rpc_enabled, true);
*configDir = getConfigDir(argc, (const char* const*)argv);
*configDir = getConfigDir(argc, (char const* const*)argv);
loaded = tr_sessionLoadSettings(settings, *configDir, MY_NAME);
/* overwrite settings from the comamndline */
if (!parse_args(argc, (const char**)argv, settings, &arg.paused, &dumpSettings, &foreground, &ret))
if (!parse_args(argc, (char const**)argv, settings, &arg.paused, &dumpSettings, &foreground, &ret))
{
goto cleanup;
}

View File

@ -18,4 +18,4 @@ typedef struct dtr_callbacks
}
dtr_callbacks;
bool dtr_daemon(const dtr_callbacks* cb, void* cb_arg, bool foreground, int* exit_code, struct tr_error** error);
bool dtr_daemon(dtr_callbacks const* cb, void* cb_arg, bool foreground, int* exit_code, struct tr_error** error);

View File

@ -227,7 +227,7 @@ enum
TAG_TRACKERS
};
static const char* getUsage(void)
static char const* getUsage(void)
{
return MY_NAME " " LONG_VERSION_STRING "\n"
"A fast and easy BitTorrent client\n"
@ -342,10 +342,10 @@ static void showUsage(void)
tr_getopt_usage(MY_NAME, getUsage(), opts);
}
static int numarg(const char* arg)
static int numarg(char const* arg)
{
char* end = NULL;
const long num = strtol(arg, &end, 10);
long const num = strtol(arg, &end, 10);
if (*end)
{
@ -516,7 +516,7 @@ static char* netrc = NULL;
static char* sessionId = NULL;
static bool UseSSL = false;
static char* getEncodedMetainfo(const char* filename)
static char* getEncodedMetainfo(char const* filename)
{
size_t len = 0;
char* b64 = NULL;
@ -531,7 +531,7 @@ static char* getEncodedMetainfo(const char* filename)
return b64;
}
static void addIdArg(tr_variant* args, const char* id, const char* fallback)
static void addIdArg(tr_variant* args, char const* id, char const* fallback)
{
if (!id || !*id)
{
@ -550,7 +550,7 @@ static void addIdArg(tr_variant* args, const char* id, const char* fallback)
}
else if (strcmp(id, "all") != 0)
{
const char* pch;
char const* pch;
bool isList = strchr(id, ',') || strchr(id, '-');
bool isNum = true;
@ -573,17 +573,17 @@ static void addIdArg(tr_variant* args, const char* id, const char* fallback)
}
}
static void addTime(tr_variant* args, const tr_quark key, const char* arg)
static void addTime(tr_variant* args, tr_quark const key, char const* arg)
{
int time;
bool success = false;
if (arg && (strlen(arg) == 4))
{
const char hh[3] = { arg[0], arg[1], '\0' };
const char mm[3] = { arg[2], arg[3], '\0' };
const int hour = atoi(hh);
const int min = atoi(mm);
char const hh[3] = { arg[0], arg[1], '\0' };
char const mm[3] = { arg[2], arg[3], '\0' };
int const hour = atoi(hh);
int const min = atoi(mm);
if (0 <= hour && hour < 24 && 0 <= min && min < 60)
{
@ -602,7 +602,7 @@ static void addTime(tr_variant* args, const tr_quark key, const char* arg)
}
}
static void addDays(tr_variant* args, const tr_quark key, const char* arg)
static void addDays(tr_variant* args, tr_quark const key, char const* arg)
{
int days = 0;
@ -642,7 +642,7 @@ static void addDays(tr_variant* args, const tr_quark key, const char* arg)
}
}
static void addFiles(tr_variant* args, const tr_quark key, const char* arg)
static void addFiles(tr_variant* args, tr_quark const key, char const* arg)
{
tr_variant* files = tr_variantDictAddList(args, key, 100);
@ -669,7 +669,7 @@ static void addFiles(tr_variant* args, const tr_quark key, const char* arg)
#define TR_N_ELEMENTS(ary) (sizeof(ary) / sizeof(*ary))
static const tr_quark files_keys[] =
static tr_quark const files_keys[] =
{
TR_KEY_files,
TR_KEY_name,
@ -677,7 +677,7 @@ static const tr_quark files_keys[] =
TR_KEY_wanted
};
static const tr_quark details_keys[] =
static tr_quark const details_keys[] =
{
TR_KEY_activityDate,
TR_KEY_addedDate,
@ -729,7 +729,7 @@ static const tr_quark details_keys[] =
TR_KEY_webseedsSendingToUs
};
static const tr_quark list_keys[] =
static tr_quark const list_keys[] =
{
TR_KEY_error,
TR_KEY_errorString,
@ -749,7 +749,7 @@ static const tr_quark list_keys[] =
static size_t writeFunc(void* ptr, size_t size, size_t nmemb, void* buf)
{
const size_t byteCount = size * nmemb;
size_t const byteCount = size * nmemb;
evbuffer_add(buf, ptr, byteCount);
return byteCount;
}
@ -757,15 +757,15 @@ static size_t writeFunc(void* ptr, size_t size, size_t nmemb, void* buf)
/* look for a session id in the header in case the server gives back a 409 */
static size_t parseResponseHeader(void* ptr, size_t size, size_t nmemb, void* stream UNUSED)
{
const char* line = ptr;
const size_t line_len = size * nmemb;
const char* key = TR_RPC_SESSION_ID_HEADER ": ";
const size_t key_len = strlen(key);
char const* line = ptr;
size_t const line_len = size * nmemb;
char const* key = TR_RPC_SESSION_ID_HEADER ": ";
size_t const key_len = strlen(key);
if (line_len >= key_len && memcmp(line, key, key_len) == 0)
{
const char* begin = line + key_len;
const char* end = begin;
char const* begin = line + key_len;
char const* end = begin;
while (!isspace(*end))
{
@ -779,7 +779,7 @@ static size_t parseResponseHeader(void* ptr, size_t size, size_t nmemb, void* st
return line_len;
}
static long getTimeoutSecs(const char* req)
static long getTimeoutSecs(char const* req)
{
if (strstr(req, "\"method\":\"blocklist-update\"") != NULL)
{
@ -822,7 +822,7 @@ static char* getStatusString(tr_variant* t, char* buf, size_t buflen)
case TR_STATUS_CHECK_WAIT:
case TR_STATUS_CHECK:
{
const char* str = status == TR_STATUS_CHECK_WAIT ? "Will Verify" : "Verifying";
char const* str = status == TR_STATUS_CHECK_WAIT ? "Will Verify" : "Verifying";
double percent;
if (tr_variantDictFindReal(t, TR_KEY_recheckProgress, &percent))
@ -884,7 +884,7 @@ static char* getStatusString(tr_variant* t, char* buf, size_t buflen)
return buf;
}
static const char* bandwidthPriorityNames[] =
static char const* bandwidthPriorityNames[] =
{
"Low",
"Normal",
@ -904,7 +904,7 @@ static void printDetails(tr_variant* top)
{
tr_variant* t = tr_variantListChild(torrents, ti);
tr_variant* l;
const char* str;
char const* str;
char buf[512];
char buf2[512];
int64_t i, j, k;
@ -1039,7 +1039,7 @@ static void printDetails(tr_variant* top)
if (tr_variantDictFindList(t, TR_KEY_webseeds, &l) && tr_variantDictFindInt(t, TR_KEY_webseedsSendingToUs, &i))
{
const int64_t n = tr_variantListSize(l);
int64_t const n = tr_variantListSize(l);
if (n > 0)
{
@ -1053,25 +1053,25 @@ static void printDetails(tr_variant* top)
if (tr_variantDictFindInt(t, TR_KEY_addedDate, &i) && i)
{
const time_t tt = i;
time_t const tt = i;
printf(" Date added: %s", ctime(&tt));
}
if (tr_variantDictFindInt(t, TR_KEY_doneDate, &i) && i)
{
const time_t tt = i;
time_t const tt = i;
printf(" Date finished: %s", ctime(&tt));
}
if (tr_variantDictFindInt(t, TR_KEY_startDate, &i) && i)
{
const time_t tt = i;
time_t const tt = i;
printf(" Date started: %s", ctime(&tt));
}
if (tr_variantDictFindInt(t, TR_KEY_activityDate, &i) && i)
{
const time_t tt = i;
time_t const tt = i;
printf(" Latest activity: %s", ctime(&tt));
}
@ -1091,7 +1091,7 @@ static void printDetails(tr_variant* top)
if (tr_variantDictFindInt(t, TR_KEY_dateCreated, &i) && i)
{
const time_t tt = i;
time_t const tt = i;
printf(" Date created: %s", ctime(&tt));
}
@ -1209,7 +1209,7 @@ static void printFileList(tr_variant* top)
{
tr_variant* d = tr_variantListChild(torrents, i);
tr_variant* files, * priorities, * wanteds;
const char* name;
char const* name;
if (tr_variantDictFindStr(d, TR_KEY_name, &name, NULL) && tr_variantDictFindList(d, TR_KEY_files, &files) &&
tr_variantDictFindList(d, TR_KEY_priorities, &priorities) && tr_variantDictFindList(d, TR_KEY_wanted, &wanteds))
@ -1224,7 +1224,7 @@ static void printFileList(tr_variant* top)
int64_t length;
int64_t priority;
int64_t wanted;
const char* filename;
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) &&
@ -1233,7 +1233,7 @@ static void printFileList(tr_variant* top)
{
char sizestr[64];
double percent = (double)have / length;
const char* pristr;
char const* pristr;
strlsize(sizestr, length, sizeof(sizestr));
switch (priority)
@ -1267,7 +1267,7 @@ static void printPeersImpl(tr_variant* peers)
for (i = 0, n = tr_variantListSize(peers); i < n; ++i)
{
double progress;
const char* address, * client, * flagstr;
char const* address, * client, * flagstr;
int64_t rateToClient, rateToPeer;
tr_variant* d = tr_variantListChild(peers, i);
@ -1307,7 +1307,7 @@ static void printPeers(tr_variant* top)
}
}
static void printPiecesImpl(const uint8_t* raw, size_t rawlen, size_t j)
static void printPiecesImpl(uint8_t const* raw, size_t rawlen, size_t j)
{
size_t i, k, len;
char* str = tr_base64_decode(raw, rawlen, &len);
@ -1345,7 +1345,7 @@ static void printPieces(tr_variant* top)
for (i = 0, n = tr_variantListSize(torrents); i < n; ++i)
{
int64_t j;
const uint8_t* raw;
uint8_t const* raw;
size_t rawlen;
tr_variant* torrent = tr_variantListChild(torrents, i);
@ -1397,7 +1397,7 @@ static void printTorrentList(tr_variant* top)
int64_t id, eta, status, up, down;
int64_t sizeWhenDone, leftUntilDone;
double ratio;
const char* name;
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) &&
@ -1468,16 +1468,16 @@ static void printTrackersImpl(tr_variant* trackerStats)
int64_t downloadCount;
bool hasAnnounced;
bool hasScraped;
const char* host;
char const* host;
int64_t id;
bool isBackup;
int64_t lastAnnouncePeerCount;
const char* lastAnnounceResult;
char const* lastAnnounceResult;
int64_t lastAnnounceStartTime;
bool lastAnnounceSucceeded;
int64_t lastAnnounceTime;
bool lastAnnounceTimedOut;
const char* lastScrapeResult;
char const* lastScrapeResult;
bool lastScrapeSucceeded;
int64_t lastScrapeStartTime;
int64_t lastScrapeTime;
@ -1515,7 +1515,7 @@ static void printTrackersImpl(tr_variant* trackerStats)
tr_variantDictFindInt(t, TR_KEY_seederCount, &seederCount) &&
tr_variantDictFindInt(t, TR_KEY_tier, &tier))
{
const time_t now = time(NULL);
time_t const now = time(NULL);
printf("\n");
printf(" Tracker %d: %s\n", (int)(id), host);
@ -1647,7 +1647,7 @@ static void printSession(tr_variant* top)
int64_t i;
char buf[64];
bool boolVal;
const char* str;
char const* str;
printf("VERSION\n");
@ -1890,25 +1890,25 @@ static void printSessionStats(tr_variant* top)
static char id[4096];
static int processResponse(const char* rpcurl, const void* response, size_t len)
static int processResponse(char const* rpcurl, void const* response, size_t len)
{
tr_variant top;
int status = EXIT_SUCCESS;
if (debug)
{
fprintf(stderr, "got response (len %d):\n--------\n%*.*s\n--------\n", (int)len, (int)len, (int)len, (const char*)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))
{
tr_logAddNamedError(MY_NAME, "Unable to parse response \"%*.*s\"", (int)len, (int)len, (const char*)response);
tr_logAddNamedError(MY_NAME, "Unable to parse response \"%*.*s\"", (int)len, (int)len, (char const*)response);
status |= EXIT_FAILURE;
}
else
{
int64_t tag = -1;
const char* str;
char const* str;
if (tr_variantDictFindStr(&top, TR_KEY_result, &str, NULL))
{
@ -2041,7 +2041,7 @@ static CURL* tr_curl_easy_init(struct evbuffer* writebuf)
return curl;
}
static int flush(const char* rpcurl, tr_variant** benc)
static int flush(char const* rpcurl, tr_variant** benc)
{
CURLcode res;
CURL* curl;
@ -2073,7 +2073,7 @@ static int flush(const char* rpcurl, tr_variant** benc)
switch (response)
{
case 200:
status |= processResponse(rpcurl, (const char*)evbuffer_pullup(buf, -1), evbuffer_get_length(buf));
status |= processResponse(rpcurl, (char const*)evbuffer_pullup(buf, -1), evbuffer_get_length(buf));
break;
case 409:
@ -2150,11 +2150,11 @@ static tr_variant* ensure_tset(tr_variant** tset)
return args;
}
static int processArgs(const char* rpcurl, int argc, const char* const* argv)
static int processArgs(char const* rpcurl, int argc, char const* const* argv)
{
int c;
int status = EXIT_SUCCESS;
const char* optarg;
char const* optarg;
tr_variant* sset = 0;
tr_variant* tset = 0;
tr_variant* tadd = 0;
@ -2163,7 +2163,7 @@ static int processArgs(const char* rpcurl, int argc, const char* const* argv)
while ((c = tr_getopt(getUsage(), argc, argv, opts, &optarg)))
{
const int stepMode = getOptMode(c);
int const stepMode = getOptMode(c);
if (!stepMode) /* meta commands */
{
@ -2898,8 +2898,8 @@ static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* po
if (*argv[1] != '-')
{
int i;
const char* s = argv[1];
const char* delim = strchr(s, ':');
char const* s = argv[1];
char const* delim = strchr(s, ':');
if (strncmp(s, "http://", 7) == 0) /* user passed in http rpc url */
{
@ -2918,7 +2918,7 @@ static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* po
else
{
char* end;
const int i = strtol(s, &end, 10);
int const i = strtol(s, &end, 10);
if (!*end) /* user passed in a port */
{
@ -2968,7 +2968,7 @@ int tr_main(int argc, char* argv[])
rpcurl = tr_strdup_printf("%s:%d%s", host, port, DEFAULT_URL);
}
exit_status = processArgs(rpcurl, argc, (const char* const*)argv);
exit_status = processArgs(rpcurl, argc, (char const* const*)argv);
tr_free(host);
tr_free(rpcurl);

View File

@ -43,9 +43,9 @@ static GtkRadioActionEntry sort_radio_entries[] =
static void sort_changed_cb(GtkAction* action UNUSED, GtkRadioAction* current, gpointer user_data UNUSED)
{
const tr_quark key = TR_KEY_sort_mode;
const int i = gtk_radio_action_get_current_value(current);
const char* val = sort_radio_entries[i].name;
tr_quark const key = TR_KEY_sort_mode;
int const i = gtk_radio_action_get_current_value(current);
char const* val = sort_radio_entries[i].name;
gtr_core_set_pref(myCore, key, val);
}
@ -58,8 +58,8 @@ static GtkToggleActionEntry show_toggle_entries[] =
static void toggle_pref_cb(GtkToggleAction* action, gpointer user_data UNUSED)
{
const char* key = gtk_action_get_name(GTK_ACTION(action));
const gboolean val = gtk_toggle_action_get_active(action);
char const* key = gtk_action_get_name(GTK_ACTION(action));
gboolean const val = gtk_toggle_action_get_active(action);
gtr_core_set_pref_bool(myCore, tr_quark_new(key, TR_BAD_SIZE), val);
}
@ -117,12 +117,12 @@ static GtkActionEntry entries[] =
typedef struct
{
const char* filename;
const char* name;
char const* filename;
char const* name;
}
BuiltinIconInfo;
static const BuiltinIconInfo my_fallback_icons[] =
static BuiltinIconInfo const my_fallback_icons[] =
{
{ "logo-48", WINDOW_ICON },
{ "logo-24", TRAY_ICON },
@ -137,7 +137,7 @@ static const BuiltinIconInfo my_fallback_icons[] =
static void register_my_icons(void)
{
int i;
const int n = G_N_ELEMENTS(my_fallback_icons);
int const n = G_N_ELEMENTS(my_fallback_icons);
GtkIconTheme* theme = gtk_icon_theme_get_default();
GtkIconFactory* factory = gtk_icon_factory_new();
@ -145,7 +145,7 @@ static void register_my_icons(void)
for (i = 0; i < n; ++i)
{
const char* name = my_fallback_icons[i].name;
char const* name = my_fallback_icons[i].name;
if (!gtk_icon_theme_has_icon(theme, name))
{
@ -187,8 +187,8 @@ void gtr_actions_init(GtkUIManager* ui_manager, gpointer callback_user_data)
{
int i, n;
int active;
const char* match;
const int n_entries = G_N_ELEMENTS(entries);
char const* match;
int const n_entries = G_N_ELEMENTS(entries);
GtkActionGroup* action_group;
myUIManager = ui_manager;
@ -251,7 +251,7 @@ static void ensure_action_map_loaded(GtkUIManager* uim)
for (ait = actions; ait != NULL; ait = ait->next)
{
GtkAction* action = GTK_ACTION(ait->data);
const char* name = gtk_action_get_name(action);
char const* name = gtk_action_get_name(action);
g_hash_table_insert(key_to_action, g_strdup(name), action);
}
@ -259,13 +259,13 @@ static void ensure_action_map_loaded(GtkUIManager* uim)
}
}
static GtkAction* get_action(const char* name)
static GtkAction* get_action(char const* name)
{
ensure_action_map_loaded(myUIManager);
return (GtkAction*) g_hash_table_lookup(key_to_action, name);
}
void gtr_action_activate(const char* name)
void gtr_action_activate(char const* name)
{
GtkAction* action = get_action(name);
@ -273,7 +273,7 @@ void gtr_action_activate(const char* name)
gtk_action_activate(action);
}
void gtr_action_set_sensitive(const char* name, gboolean b)
void gtr_action_set_sensitive(char const* name, gboolean b)
{
GtkAction* action = get_action(name);
@ -281,7 +281,7 @@ void gtr_action_set_sensitive(const char* name, gboolean b)
g_object_set(action, "sensitive", b, NULL);
}
void gtr_action_set_important(const char* name, gboolean b)
void gtr_action_set_important(char const* name, gboolean b)
{
GtkAction* action = get_action(name);
@ -289,14 +289,14 @@ void gtr_action_set_important(const char* name, gboolean b)
g_object_set(action, "is-important", b, NULL);
}
void gtr_action_set_toggled(const char* name, gboolean b)
void gtr_action_set_toggled(char const* name, gboolean b)
{
GtkAction* action = get_action(name);
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), b);
}
GtkWidget* gtr_action_get_widget(const char* path)
GtkWidget* gtr_action_get_widget(char const* path)
{
return gtk_ui_manager_get_widget(myUIManager, path);
}

View File

@ -17,10 +17,10 @@
void gtr_actions_init(GtkUIManager* ui_manager, gpointer callback_user_data);
void gtr_actions_set_core(TrCore* core);
void gtr_actions_handler(const char* action_name, gpointer user_data);
void gtr_actions_handler(char const* action_name, gpointer user_data);
void gtr_action_activate(const char* action_name);
void gtr_action_set_sensitive(const char* action_name, gboolean is_sensitive);
void gtr_action_set_toggled(const char* action_name, gboolean is_toggled);
void gtr_action_set_important(const char* action_name, gboolean is_important);
GtkWidget* gtr_action_get_widget(const char* path);
void gtr_action_activate(char const* action_name);
void gtr_action_set_sensitive(char const* action_name, gboolean is_sensitive);
void gtr_action_set_toggled(char const* action_name, gboolean is_toggled);
void gtr_action_set_important(char const* action_name, gboolean is_important);
GtkWidget* gtr_action_get_widget(char const* path);

View File

@ -43,7 +43,7 @@
static char* gl_confdir = NULL;
void gtr_pref_init(const char* config_dir)
void gtr_pref_init(char const* config_dir)
{
gl_confdir = g_strdup(config_dir);
}
@ -60,7 +60,7 @@ void gtr_pref_init(const char* config_dir)
*/
static void tr_prefs_init_defaults(tr_variant* d)
{
const char* dir;
char const* dir;
dir = g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD);
@ -132,26 +132,26 @@ tr_variant* gtr_pref_get_all(void)
return getPrefs();
}
int64_t gtr_pref_int_get(const tr_quark key)
int64_t gtr_pref_int_get(tr_quark const key)
{
int64_t i;
return tr_variantDictFindInt(getPrefs(), key, &i) ? i : 0;
}
void gtr_pref_int_set(const tr_quark key, int64_t value)
void gtr_pref_int_set(tr_quark const key, int64_t value)
{
tr_variantDictAddInt(getPrefs(), key, value);
}
double gtr_pref_double_get(const tr_quark key)
double gtr_pref_double_get(tr_quark const key)
{
double d;
return tr_variantDictFindReal(getPrefs(), key, &d) ? d : 0.0;
}
void gtr_pref_double_set(const tr_quark key, double value)
void gtr_pref_double_set(tr_quark const key, double value)
{
tr_variantDictAddReal(getPrefs(), key, value);
}
@ -160,14 +160,14 @@ void gtr_pref_double_set(const tr_quark key, double value)
****
***/
gboolean gtr_pref_flag_get(const tr_quark key)
gboolean gtr_pref_flag_get(tr_quark const key)
{
bool boolVal;
return tr_variantDictFindBool(getPrefs(), key, &boolVal) ? boolVal : false;
}
void gtr_pref_flag_set(const tr_quark key, gboolean value)
void gtr_pref_flag_set(tr_quark const key, gboolean value)
{
tr_variantDictAddBool(getPrefs(), key, value);
}
@ -176,14 +176,14 @@ void gtr_pref_flag_set(const tr_quark key, gboolean value)
****
***/
const char* gtr_pref_string_get(const tr_quark key)
char const* gtr_pref_string_get(tr_quark const key)
{
const char* str;
char const* str;
return tr_variantDictFindStr(getPrefs(), key, &str, NULL) ? str : NULL;
}
void gtr_pref_string_set(const tr_quark key, const char* value)
void gtr_pref_string_set(tr_quark const key, char const* value)
{
tr_variantDictAddStr(getPrefs(), key, value);
}

View File

@ -26,19 +26,19 @@
#include <libtransmission/transmission.h> /* tr_variant, tr_session */
#include <libtransmission/quark.h>
void gtr_pref_init(const char* config_dir);
void gtr_pref_init(char const* config_dir);
int64_t gtr_pref_int_get(const tr_quark key);
void gtr_pref_int_set(const tr_quark key, int64_t value);
int64_t gtr_pref_int_get(tr_quark const key);
void gtr_pref_int_set(tr_quark const key, int64_t value);
double gtr_pref_double_get(const tr_quark key);
void gtr_pref_double_set(const tr_quark key, double value);
double gtr_pref_double_get(tr_quark const key);
void gtr_pref_double_set(tr_quark const key, double value);
gboolean gtr_pref_flag_get(const tr_quark key);
void gtr_pref_flag_set(const tr_quark key, gboolean value);
gboolean gtr_pref_flag_get(tr_quark const key);
void gtr_pref_flag_set(tr_quark const key, gboolean value);
const char* gtr_pref_string_get(const tr_quark key);
void gtr_pref_string_set(const tr_quark key, const char* value);
char const* gtr_pref_string_get(tr_quark const key);
void gtr_pref_string_set(tr_quark const key, char const* value);
void gtr_pref_save(tr_session*);
struct tr_variant* gtr_pref_get_all(void);

View File

@ -108,7 +108,7 @@ static tr_torrent** getTorrents(struct DetailsImpl* d, int* setmeCount)
{
GSList* l;
int torrentCount = 0;
const int n = g_slist_length(d->ids);
int const n = g_slist_length(d->ids);
tr_torrent** torrents = g_new(tr_torrent*, n);
for (l = d->ids; l != NULL; l = l->next)
@ -132,7 +132,7 @@ static tr_torrent** getTorrents(struct DetailsImpl* d, int* setmeCount)
static void set_togglebutton_if_different(GtkWidget* w, gulong tag, gboolean value)
{
GtkToggleButton* toggle = GTK_TOGGLE_BUTTON(w);
const gboolean currentValue = gtk_toggle_button_get_active(toggle);
gboolean const currentValue = gtk_toggle_button_get_active(toggle);
if (currentValue != value)
{
@ -145,7 +145,7 @@ static void set_togglebutton_if_different(GtkWidget* w, gulong tag, gboolean val
static void set_int_spin_if_different(GtkWidget* w, gulong tag, int value)
{
GtkSpinButton* spin = GTK_SPIN_BUTTON(w);
const int currentValue = gtk_spin_button_get_value_as_int(spin);
int const currentValue = gtk_spin_button_get_value_as_int(spin);
if (currentValue != value)
{
@ -158,7 +158,7 @@ static void set_int_spin_if_different(GtkWidget* w, gulong tag, int value)
static void set_double_spin_if_different(GtkWidget* w, gulong tag, double value)
{
GtkSpinButton* spin = GTK_SPIN_BUTTON(w);
const double currentValue = gtk_spin_button_get_value(spin);
double const currentValue = gtk_spin_button_get_value(spin);
if (((int)(currentValue * 100) != (int)(value * 100)))
{
@ -187,7 +187,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (n)
{
int i;
const bool baseline = tr_torrentUsesSessionLimits(torrents[0]);
bool const baseline = tr_torrentUsesSessionLimits(torrents[0]);
for (i = 1; i < n; ++i)
{
@ -207,7 +207,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (n)
{
int i;
const bool baseline = tr_torrentUsesSpeedLimit(torrents[0], TR_DOWN);
bool const baseline = tr_torrentUsesSpeedLimit(torrents[0], TR_DOWN);
for (i = 1; i < n; ++i)
{
@ -227,7 +227,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (n)
{
int i;
const unsigned int baseline = tr_torrentGetSpeedLimit_KBps(torrents[0], TR_DOWN);
unsigned const int baseline = tr_torrentGetSpeedLimit_KBps(torrents[0], TR_DOWN);
for (i = 1; i < n; ++i)
{
@ -247,7 +247,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (n)
{
int i;
const bool baseline = tr_torrentUsesSpeedLimit(torrents[0], TR_UP);
bool const baseline = tr_torrentUsesSpeedLimit(torrents[0], TR_UP);
for (i = 1; i < n; ++i)
{
@ -267,7 +267,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (n)
{
int i;
const unsigned int baseline = tr_torrentGetSpeedLimit_KBps(torrents[0], TR_UP);
unsigned int const baseline = tr_torrentGetSpeedLimit_KBps(torrents[0], TR_UP);
for (i = 1; i < n; ++i)
{
@ -287,7 +287,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (n)
{
int i;
const int baseline = tr_torrentGetPriority(torrents[0]);
int const baseline = tr_torrentGetPriority(torrents[0]);
for (i = 1; i < n; ++i)
{
@ -314,7 +314,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (n)
{
int i;
const int baseline = tr_torrentGetRatioMode(torrents[0]);
int const baseline = tr_torrentGetRatioMode(torrents[0]);
for (i = 1; i < n; ++i)
{
@ -337,7 +337,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
/* ratio_spin */
if (n)
{
const double baseline = tr_torrentGetRatioLimit(torrents[0]);
double const baseline = tr_torrentGetRatioLimit(torrents[0]);
set_double_spin_if_different(di->ratio_spin, di->ratio_spin_tag, baseline);
}
@ -345,7 +345,7 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
if (n)
{
int i;
const int baseline = tr_torrentGetIdleMode(torrents[0]);
int const baseline = tr_torrentGetIdleMode(torrents[0]);
for (i = 1; i < n; ++i)
{
@ -368,19 +368,19 @@ static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
/* idle_spin */
if (n)
{
const int baseline = tr_torrentGetIdleLimit(torrents[0]);
int const baseline = tr_torrentGetIdleLimit(torrents[0]);
set_int_spin_if_different(di->idle_spin, di->idle_spin_tag, baseline);
}
/* max_peers_spin */
if (n)
{
const int baseline = tr_torrentGetPeerLimit(torrents[0]);
int const baseline = tr_torrentGetPeerLimit(torrents[0]);
set_int_spin_if_different(di->max_peers_spin, di->max_peers_spin_tag, baseline);
}
}
static void torrent_set_bool(struct DetailsImpl* di, const tr_quark key, gboolean value)
static void torrent_set_bool(struct DetailsImpl* di, tr_quark const key, gboolean value)
{
GSList* l;
tr_variant top, *args, *ids;
@ -400,7 +400,7 @@ static void torrent_set_bool(struct DetailsImpl* di, const tr_quark key, gboolea
tr_variantFree(&top);
}
static void torrent_set_int(struct DetailsImpl* di, const tr_quark key, int value)
static void torrent_set_int(struct DetailsImpl* di, tr_quark const key, int value)
{
GSList* l;
tr_variant top, *args, *ids;
@ -420,7 +420,7 @@ static void torrent_set_int(struct DetailsImpl* di, const tr_quark key, int valu
tr_variantFree(&top);
}
static void torrent_set_real(struct DetailsImpl* di, const tr_quark key, double value)
static void torrent_set_real(struct DetailsImpl* di, tr_quark const key, double value)
{
GSList* l;
tr_variant top, *args, *ids;
@ -482,7 +482,7 @@ static void max_peers_spun_cb(GtkSpinButton* s, struct DetailsImpl* di)
static void onPriorityChanged(GtkComboBox* combo_box, struct DetailsImpl* di)
{
const tr_priority_t priority = gtr_priority_combo_get_value(combo_box);
tr_priority_t const priority = gtr_priority_combo_get_value(combo_box);
torrent_set_int(di, TR_KEY_bandwidthPriority, priority);
}
@ -497,7 +497,7 @@ static void refresh(struct DetailsImpl* di);
static void onComboEnumChanged(GtkComboBox* combo_box, struct DetailsImpl* di)
{
const tr_quark key = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(combo_box), ARG_KEY));
tr_quark const key = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(combo_box), ARG_KEY));
torrent_set_int(di, key, gtr_combo_box_get_active_enum(combo_box));
refresh(di);
}
@ -609,7 +609,7 @@ static GtkWidget* options_page_new(struct DetailsImpl* d)
*****
****/
static const char* activityString(int activity, bool finished)
static char const* activityString(int activity, bool finished)
{
switch (activity)
{
@ -640,7 +640,7 @@ static const char* activityString(int activity, bool finished)
/* Only call gtk_text_buffer_set_text () if the new text differs from the old.
* This way if the user has text selected, refreshing won't deselect it */
static void gtr_text_buffer_set_text(GtkTextBuffer* b, const char* str)
static void gtr_text_buffer_set_text(GtkTextBuffer* b, char const* str)
{
char* old_str;
GtkTextIter start, end;
@ -679,14 +679,14 @@ static char* get_short_date_string(time_t t)
static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
{
int i;
const char* str;
const char* mixed = _("Mixed");
const char* no_torrent = _("No Torrents Selected");
const char* stateString;
char const* str;
char const* mixed = _("Mixed");
char const* no_torrent = _("No Torrents Selected");
char const* stateString;
char buf[512];
uint64_t sizeWhenDone = 0;
const tr_stat** stats = g_new(const tr_stat*, n);
const tr_info** infos = g_new(const tr_info*, n);
tr_stat const** stats = g_new(tr_stat const*, n);
tr_info const** infos = g_new(tr_info const*, n);
for (i = 0; i < n; ++i)
{
@ -701,7 +701,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const bool baseline = infos[0]->isPrivate;
bool const baseline = infos[0]->isPrivate;
for (i = 1; i < n; ++i)
{
@ -735,8 +735,8 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const char* creator = infos[0]->creator ? infos[0]->creator : "";
const time_t date = infos[0]->dateCreated;
char const* creator = infos[0]->creator ? infos[0]->creator : "";
time_t const date = infos[0]->dateCreated;
char* datestr = get_short_date_string(date);
gboolean mixed_creator = FALSE;
gboolean mixed_date = FALSE;
@ -747,8 +747,8 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
mixed_date |= (date != infos[i]->dateCreated);
}
const gboolean empty_creator = !*creator;
const gboolean empty_date = date == 0;
gboolean const empty_creator = !*creator;
gboolean const empty_date = date == 0;
if (mixed_date || mixed_creator)
{
@ -789,7 +789,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const char* baseline = infos[0]->comment ? infos[0]->comment : "";
char const* baseline = infos[0]->comment ? infos[0]->comment : "";
for (i = 1; i < n; ++i)
{
@ -818,7 +818,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const char* baseline = tr_torrentGetDownloadDir(torrents[0]);
char const* baseline = tr_torrentGetDownloadDir(torrents[0]);
for (i = 1; i < n; ++i)
{
@ -847,7 +847,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const tr_torrent_activity activity = stats[0]->activity;
tr_torrent_activity const activity = stats[0]->activity;
bool allFinished = stats[0]->finished;
for (i = 1; i < n; ++i)
@ -877,7 +877,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const time_t baseline = stats[0]->startDate;
time_t const baseline = stats[0]->startDate;
for (i = 1; i < n; ++i)
{
@ -911,7 +911,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const int baseline = stats[0]->eta;
int const baseline = stats[0]->eta;
for (i = 1; i < n; ++i)
{
@ -998,7 +998,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
for (i = 0; i < n; ++i)
{
const tr_stat* st = stats[i];
tr_stat const* st = stats[i];
haveUnchecked += st->haveUnchecked;
haveValid += st->haveValid;
sizeWhenDone += st->sizeWhenDone;
@ -1008,8 +1008,8 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
{
char buf2[32], unver[64], total[64], avail[32];
const double d = sizeWhenDone ? (100.0 * available) / sizeWhenDone : 0;
const double ratio = 100.0 * (sizeWhenDone ? (haveValid + haveUnchecked) / (double)sizeWhenDone : 1);
double const d = sizeWhenDone ? (100.0 * available) / sizeWhenDone : 0;
double const ratio = 100.0 * (sizeWhenDone ? (haveValid + haveUnchecked) / (double)sizeWhenDone : 1);
tr_strlpercent(avail, d, sizeof(avail));
tr_strlpercent(buf2, ratio, sizeof(buf2));
@ -1118,7 +1118,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const char* baseline = stats[0]->errorString;
char const* baseline = stats[0]->errorString;
for (i = 1; i < n; ++i)
{
@ -1169,7 +1169,7 @@ static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
}
else
{
const int period = time(NULL) - latest;
int const period = time(NULL) - latest;
if (period < 5)
{
@ -1305,7 +1305,7 @@ enum
N_WEBSEED_COLS
};
static const char* getWebseedColumnNames(int column)
static char const* getWebseedColumnNames(int column)
{
switch (column)
{
@ -1361,7 +1361,7 @@ enum
N_PEER_COLS
};
static const char* getPeerColumnName(int column)
static char const* getPeerColumnName(int column)
{
switch (column)
{
@ -1444,12 +1444,12 @@ static GtkListStore* peer_store_new(void)
G_TYPE_STRING); /* torrent name */
}
static void initPeerRow(GtkListStore* store, GtkTreeIter* iter, const char* key, const char* torrentName,
const tr_peer_stat* peer)
static void initPeerRow(GtkListStore* store, GtkTreeIter* iter, char const* key, char const* torrentName,
tr_peer_stat const* peer)
{
int q[4];
char collated_name[128];
const char* client = peer->client;
char const* client = peer->client;
if (client == NULL || g_strcmp0(client, "Unknown Client") == 0)
{
@ -1475,7 +1475,7 @@ static void initPeerRow(GtkListStore* store, GtkTreeIter* iter, const char* key,
-1);
}
static void refreshPeerRow(GtkListStore* store, GtkTreeIter* iter, const tr_peer_stat* peer)
static void refreshPeerRow(GtkListStore* store, GtkTreeIter* iter, tr_peer_stat const* peer)
{
char up_speed[64] = { '\0' };
char down_speed[64] = { '\0' };
@ -1584,12 +1584,12 @@ static void refreshPeerList(struct DetailsImpl* di, tr_torrent** torrents, int n
for (i = 0; i < n; ++i)
{
int j;
const tr_torrent* tor = torrents[i];
tr_torrent const* tor = torrents[i];
for (j = 0; j < peerCount[i]; ++j)
{
char key[128];
const tr_peer_stat* s = &peers[i][j];
tr_peer_stat const* s = &peers[i][j];
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), s->addr);
@ -1609,14 +1609,14 @@ static void refreshPeerList(struct DetailsImpl* di, tr_torrent** torrents, int n
for (i = 0; i < n; ++i)
{
int j;
const tr_torrent* tor = torrents[i];
tr_torrent const* tor = torrents[i];
for (j = 0; j < peerCount[i]; ++j)
{
char key[128];
GtkTreePath* p;
GtkTreeRowReference* ref;
const tr_peer_stat* s = &peers[i][j];
tr_peer_stat const* s = &peers[i][j];
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), s->addr);
ref = g_hash_table_lookup(hash, key);
@ -1687,15 +1687,15 @@ static void refreshWebseedList(struct DetailsImpl* di, tr_torrent** torrents, in
for (i = 0; i < n; ++i)
{
unsigned int j;
const tr_torrent* tor = torrents[i];
const tr_info* inf = tr_torrentInfo(tor);
tr_torrent const* tor = torrents[i];
tr_info const* inf = tr_torrentInfo(tor);
total += inf->webseedCount;
for (j = 0; j < inf->webseedCount; ++j)
{
char key[256];
const char* url = inf->webseeds[j];
char const* url = inf->webseeds[j];
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), url);
if (g_hash_table_lookup(hash, key) == NULL)
@ -1718,7 +1718,7 @@ static void refreshWebseedList(struct DetailsImpl* di, tr_torrent** torrents, in
{
unsigned int j;
tr_torrent* tor = torrents[i];
const tr_info* inf = tr_torrentInfo(tor);
tr_info const* inf = tr_torrentInfo(tor);
double* speeds_KBps = tr_torrentWebSpeeds_KBps(tor);
for (j = 0; j < inf->webseedCount; ++j)
@ -1727,7 +1727,7 @@ static void refreshWebseedList(struct DetailsImpl* di, tr_torrent** torrents, in
char key[256];
GtkTreePath* p;
GtkTreeRowReference* ref;
const char* url = inf->webseeds[j];
char const* url = inf->webseeds[j];
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), url);
ref = g_hash_table_lookup(hash, key);
@ -1805,7 +1805,7 @@ static gboolean onPeerViewQueryTooltip(GtkWidget* widget, gint x, gint y, gboole
if (gtk_tree_view_get_tooltip_context(GTK_TREE_VIEW(widget), &x, &y, keyboard_tip, &model, NULL, &iter))
{
const char* pch;
char const* pch;
char* name = NULL;
char* addr = NULL;
char* markup = NULL;
@ -1826,7 +1826,7 @@ static gboolean onPeerViewQueryTooltip(GtkWidget* widget, gint x, gint y, gboole
for (pch = flagstr; pch && *pch; ++pch)
{
const char* s = NULL;
char const* s = NULL;
switch (*pch)
{
@ -1908,7 +1908,7 @@ static void setPeerViewColumns(GtkTreeView* peer_view)
int view_columns[32];
GtkCellRenderer* r;
GtkTreeViewColumn* c;
const bool more = gtr_pref_flag_get(TR_KEY_show_extra_peer_details);
bool const more = gtr_pref_flag_get(TR_KEY_show_extra_peer_details);
n = 0;
view_columns[n++] = PEER_COL_ENCRYPTION_STOCK_ID;
@ -1959,8 +1959,8 @@ static void setPeerViewColumns(GtkTreeView* peer_view)
for (i = 0; i < n; ++i)
{
const int col = view_columns[i];
const char* t = getPeerColumnName(col);
int const col = view_columns[i];
char const* t = getPeerColumnName(col);
int sort_col = col;
switch (col)
@ -2067,8 +2067,8 @@ static void setPeerViewColumns(GtkTreeView* peer_view)
static void onMorePeerInfoToggled(GtkToggleButton* button, struct DetailsImpl* di)
{
const tr_quark key = TR_KEY_show_extra_peer_details;
const gboolean value = gtk_toggle_button_get_active(button);
tr_quark const key = TR_KEY_show_extra_peer_details;
gboolean const value = gtk_toggle_button_get_active(button);
gtr_core_set_pref_bool(di->core, key, value);
setPeerViewColumns(GTK_TREE_VIEW(di->peer_view));
}
@ -2076,7 +2076,7 @@ static void onMorePeerInfoToggled(GtkToggleButton* button, struct DetailsImpl* d
static GtkWidget* peer_page_new(struct DetailsImpl* di)
{
gboolean b;
const char* str;
char const* str;
GtkListStore* store;
GtkWidget* v, *w, *ret, *sw, *vbox;
GtkWidget* webtree = NULL;
@ -2176,17 +2176,17 @@ static void tr_strltime_rounded(char* buf, time_t t, size_t buflen)
tr_strltime(buf, t, buflen);
}
static void buildTrackerSummary(GString* gstr, const char* key, const tr_tracker_stat* st, gboolean showScrape)
static void buildTrackerSummary(GString* gstr, char const* key, tr_tracker_stat const* st, gboolean showScrape)
{
char* str;
char timebuf[256];
const time_t now = time(NULL);
const char* err_markup_begin = "<span color=\"red\">";
const char* err_markup_end = "</span>";
const char* timeout_markup_begin = "<span color=\"#224466\">";
const char* timeout_markup_end = "</span>";
const char* success_markup_begin = "<span color=\"#008B00\">";
const char* success_markup_end = "</span>";
time_t const now = time(NULL);
char const* err_markup_begin = "<span color=\"red\">";
char const* err_markup_end = "</span>";
char const* timeout_markup_begin = "<span color=\"#224466\">";
char const* timeout_markup_end = "</span>";
char const* success_markup_begin = "<span color=\"#008B00\">";
char const* success_markup_end = "</span>";
/* hostname */
{
@ -2359,7 +2359,7 @@ static int tracker_list_get_current_torrent_id(struct DetailsImpl* di)
static tr_torrent* tracker_list_get_current_torrent(struct DetailsImpl* di)
{
const int torrent_id = tracker_list_get_current_torrent_id(di);
int const torrent_id = tracker_list_get_current_torrent_id(di);
return gtr_core_find_torrent(di->core, torrent_id);
}
@ -2396,7 +2396,7 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
GHashTable* hash = di->tracker_hash;
GtkListStore* store = di->tracker_store;
tr_session* session = gtr_core_session(di->core);
const gboolean showScrape = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(di->scrape_check));
gboolean const showScrape = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(di->scrape_check));
/* step 1: get all the trackers */
statCount = g_new0(int, n);
@ -2423,13 +2423,13 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
for (i = 0; i < n; ++i)
{
int j;
const int jn = statCount[i];
int const jn = statCount[i];
for (j = 0; j < jn; ++j)
{
const tr_torrent* tor = torrents[i];
const tr_tracker_stat* st = &stats[i][j];
const int torrent_id = tr_torrentId(tor);
tr_torrent const* tor = torrents[i];
tr_tracker_stat const* st = &stats[i][j];
int const torrent_id = tr_torrentId(tor);
/* build the key to find the row */
g_string_truncate(gstr, 0);
@ -2461,14 +2461,14 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
for (i = 0; i < n; ++i)
{
int j;
const tr_torrent* tor = torrents[i];
const char* summary_name = n > 1 ? tr_torrentName(tor) : NULL;
tr_torrent const* tor = torrents[i];
char const* summary_name = n > 1 ? tr_torrentName(tor) : NULL;
for (j = 0; j < statCount[i]; ++j)
{
GtkTreePath* p;
GtkTreeRowReference* ref;
const tr_tracker_stat* st = &stats[i][j];
tr_tracker_stat const* st = &stats[i][j];
/* build the key to find the row */
g_string_truncate(gstr, 0);
@ -2531,16 +2531,16 @@ static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
static void onScrapeToggled(GtkToggleButton* button, struct DetailsImpl* di)
{
const tr_quark key = TR_KEY_show_tracker_scrapes;
const gboolean value = gtk_toggle_button_get_active(button);
tr_quark const key = TR_KEY_show_tracker_scrapes;
gboolean const value = gtk_toggle_button_get_active(button);
gtr_core_set_pref_bool(di->core, key, value);
refresh(di);
}
static void onBackupToggled(GtkToggleButton* button, struct DetailsImpl* di)
{
const tr_quark key = TR_KEY_show_backup_trackers;
const gboolean value = gtk_toggle_button_get_active(button);
tr_quark const key = TR_KEY_show_backup_trackers;
gboolean const value = gtk_toggle_button_get_active(button);
gtr_core_set_pref_bool(di->core, key, value);
refresh(di);
}
@ -2555,7 +2555,7 @@ static void on_edit_trackers_response(GtkDialog* dialog, int response, gpointer
int i, n;
int tier;
GtkTextIter start, end;
const int torrent_id = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(dialog), TORRENT_ID_KEY));
int const torrent_id = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(dialog), TORRENT_ID_KEY));
GtkTextBuffer* text_buffer = g_object_get_qdata(G_OBJECT(dialog), TEXT_BUFFER_KEY);
tr_torrent* tor = gtr_core_find_torrent(di->core, torrent_id);
@ -2579,7 +2579,7 @@ static void on_edit_trackers_response(GtkDialog* dialog, int response, gpointer
for (i = n = tier = 0; tracker_strings[i]; ++i)
{
const char* str = tracker_strings[i];
char const* str = tracker_strings[i];
if (!*str)
{
@ -2601,7 +2601,7 @@ static void on_edit_trackers_response(GtkDialog* dialog, int response, gpointer
else
{
GtkWidget* w;
const char* text = _("List contains invalid URLs");
char const* text = _("List contains invalid URLs");
w = gtk_message_dialog_new(GTK_WINDOW(dialog),
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
@ -2625,15 +2625,15 @@ static void on_edit_trackers_response(GtkDialog* dialog, int response, gpointer
}
}
static void get_editable_tracker_list(GString* gstr, const tr_torrent* tor)
static void get_editable_tracker_list(GString* gstr, tr_torrent const* tor)
{
unsigned int i;
int tier = 0;
const tr_info* inf = tr_torrentInfo(tor);
tr_info const* inf = tr_torrentInfo(tor);
for (i = 0; i < inf->trackerCount; ++i)
{
const tr_tracker_info* t = &inf->trackers[i];
tr_tracker_info const* t = &inf->trackers[i];
if (tier != t->tier)
{
@ -2661,7 +2661,7 @@ static void on_edit_trackers(GtkButton* button, gpointer data)
GtkWidget* w, *d, *fr, *t, *l, *sw;
GtkWindow* win = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button)));
GString* gstr = di->gstr; /* buffer for temporary strings */
const int torrent_id = tr_torrentId(tor);
int const torrent_id = tr_torrentId(tor);
g_string_truncate(gstr, 0);
g_string_append_printf(gstr, _("%s - Edit Trackers"), tr_torrentName(tor));
@ -2704,7 +2704,7 @@ static void on_edit_trackers(GtkButton* button, gpointer data)
static void on_tracker_list_selection_changed(GtkTreeSelection* sel, gpointer gdi)
{
struct DetailsImpl* di = gdi;
const int n = gtk_tree_selection_count_selected_rows(sel);
int const n = gtk_tree_selection_count_selected_rows(sel);
tr_torrent* tor = tracker_list_get_current_torrent(di);
gtk_widget_set_sensitive(di->remove_tracker_button, n > 0);
@ -2720,7 +2720,7 @@ static void on_add_tracker_response(GtkDialog* dialog, int response, gpointer gd
{
struct DetailsImpl* di = gdi;
GtkWidget* e = GTK_WIDGET(g_object_get_qdata(G_OBJECT(dialog), URL_ENTRY_KEY));
const int torrent_id = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(dialog), TORRENT_ID_KEY));
int const torrent_id = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(dialog), TORRENT_ID_KEY));
char* url = g_strdup(gtk_entry_get_text(GTK_ENTRY(e)));
g_strstrip(url);
@ -2832,7 +2832,7 @@ static GtkWidget* tracker_page_new(struct DetailsImpl* di)
GtkTreeViewColumn* c;
GtkTreeSelection* sel;
GtkWidget* vbox, *sw, *w, *v, *hbox;
const int pad = (GUI_PAD + GUI_PAD_BIG) / 2;
int const pad = (GUI_PAD + GUI_PAD_BIG) / 2;
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, GUI_PAD);
gtk_container_set_border_width(GTK_CONTAINER(vbox), GUI_PAD_BIG);
@ -3029,7 +3029,7 @@ GtkWidget* gtr_torrent_details_dialog_new(GtkWindow* parent, TrCore* core)
void gtr_torrent_details_dialog_set_torrents(GtkWidget* w, GSList* ids)
{
char title[256];
const int len = g_slist_length(ids);
int const len = g_slist_length(ids);
struct DetailsImpl* di = g_object_get_qdata(G_OBJECT(w), DETAILS_KEY);
g_slist_free(di->ids);
@ -3037,9 +3037,9 @@ void gtr_torrent_details_dialog_set_torrents(GtkWidget* w, GSList* ids)
if (len == 1)
{
const int id = GPOINTER_TO_INT(ids->data);
int const id = GPOINTER_TO_INT(ids->data);
tr_torrent* tor = gtr_core_find_torrent(di->core, id);
const tr_info* inf = tr_torrentInfo(tor);
tr_info const* inf = tr_torrentInfo(tor);
g_snprintf(title, sizeof(title), _("%s Properties"), inf->name);
gtr_file_list_set_torrent(di->file_list, id);

View File

@ -66,7 +66,7 @@ void gtr_confirm_remove(GtkWindow* parent, TrCore* core, GSList* torrent_ids, gb
struct delete_data* dd;
int connected = 0;
int incomplete = 0;
const int count = g_slist_length(torrent_ids);
int const count = g_slist_length(torrent_ids);
if (!count)
{
@ -80,9 +80,9 @@ void gtr_confirm_remove(GtkWindow* parent, TrCore* core, GSList* torrent_ids, gb
for (l = torrent_ids; l != NULL; l = l->next)
{
const int id = GPOINTER_TO_INT(l->data);
int const id = GPOINTER_TO_INT(l->data);
tr_torrent* tor = gtr_core_find_torrent(core, id);
const tr_stat* stat = tr_torrentStat(tor);
tr_stat const* stat = tr_torrentStat(tor);
if (stat->leftUntilDone)
{

View File

@ -16,7 +16,7 @@
#include "util.h" /* gtr_get_host_from_url () */
#define IMAGE_TYPES 4
static const char* image_types[IMAGE_TYPES] = { "ico", "png", "gif", "jpg" };
static char const* image_types[IMAGE_TYPES] = { "ico", "png", "gif", "jpg" };
struct favicon_data
{
@ -29,7 +29,7 @@ struct favicon_data
int type;
};
static char* get_url(const char* host, int image_type)
static char* get_url(char const* host, int image_type)
{
return g_strdup_printf("http://%s/favicon.%s", host, image_types[image_type]);
}
@ -47,19 +47,19 @@ static char* favicon_get_cache_dir(void)
return dir;
}
static char* favicon_get_cache_filename(const char* host)
static char* favicon_get_cache_filename(char const* host)
{
return g_build_filename(favicon_get_cache_dir(), host, NULL);
}
static void favicon_save_to_cache(const char* host, const void* data, size_t len)
static void favicon_save_to_cache(char const* host, void const* data, size_t len)
{
char* filename = favicon_get_cache_filename(host);
g_file_set_contents(filename, data, len, NULL);
g_free(filename);
}
static GdkPixbuf* favicon_load_from_cache(const char* host)
static GdkPixbuf* favicon_load_from_cache(char const* host)
{
char* filename = favicon_get_cache_filename(host);
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, 16, 16, NULL);
@ -73,7 +73,7 @@ static GdkPixbuf* favicon_load_from_cache(const char* host)
return pixbuf;
}
static void favicon_web_done_cb(tr_session*, bool, bool, long, const void*, size_t, void*);
static void favicon_web_done_cb(tr_session*, bool, bool, long, void const*, size_t, void*);
static gboolean favicon_web_done_idle_cb(gpointer vfav)
{
@ -119,7 +119,7 @@ static gboolean favicon_web_done_idle_cb(gpointer vfav)
}
static void favicon_web_done_cb(tr_session* session UNUSED, bool did_connect UNUSED, bool did_timeout UNUSED, long code UNUSED,
const void* data, size_t len, void* vfav)
void const* data, size_t len, void* vfav)
{
struct favicon_data* fav = vfav;
fav->contents = g_memdup(data, len);
@ -128,7 +128,7 @@ static void favicon_web_done_cb(tr_session* session UNUSED, bool did_connect UNU
gdk_threads_add_idle(favicon_web_done_idle_cb, fav);
}
void gtr_get_favicon(tr_session* session, const char* host, GFunc pixbuf_ready_func, gpointer pixbuf_ready_func_data)
void gtr_get_favicon(tr_session* session, char const* host, GFunc pixbuf_ready_func, gpointer pixbuf_ready_func_data)
{
GdkPixbuf* pixbuf = favicon_load_from_cache(host);
@ -153,7 +153,7 @@ void gtr_get_favicon(tr_session* session, const char* host, GFunc pixbuf_ready_f
}
}
void gtr_get_favicon_from_url(tr_session* session, const char* url, GFunc pixbuf_ready_func, gpointer pixbuf_ready_func_data)
void gtr_get_favicon_from_url(tr_session* session, char const* url, GFunc pixbuf_ready_func, gpointer pixbuf_ready_func_data)
{
char host[1024];
gtr_get_host_from_url(host, sizeof(host), url);

View File

@ -11,6 +11,6 @@
#include <gtk/gtk.h>
#include <libtransmission/transmission.h>
void gtr_get_favicon(tr_session* session, const char* host, GFunc pixbuf_ready_func, gpointer pixbuf_ready_func_data);
void gtr_get_favicon(tr_session* session, char const* host, GFunc pixbuf_ready_func, gpointer pixbuf_ready_func_data);
void gtr_get_favicon_from_url(tr_session* session, const char* url, GFunc pixbuf_ready_func, gpointer pixbuf_ready_func_data);
void gtr_get_favicon_from_url(tr_session* session, char const* url, GFunc pixbuf_ready_func, gpointer pixbuf_ready_func_data);

View File

@ -103,7 +103,7 @@ static gboolean refreshFilesForeach(GtkTreeModel* model, GtkTreePath* path UNUSE
int old_prog;
int old_priority;
int old_enabled;
const gboolean is_file = !gtk_tree_model_iter_has_child(model, iter);
gboolean const is_file = !gtk_tree_model_iter_has_child(model, iter);
gtk_tree_model_get(model, iter,
FC_ENABLED, &old_enabled,
@ -117,11 +117,11 @@ static gboolean refreshFilesForeach(GtkTreeModel* model, GtkTreePath* path UNUSE
if (is_file)
{
tr_torrent* tor = refresh_data->tor;
const tr_info* inf = tr_torrentInfo(tor);
const int enabled = !inf->files[index].dnd;
const int priority = inf->files[index].priority;
const uint64_t have = refresh_data->refresh_file_stat[index].bytesCompleted;
const int prog = size ? (int)((100.0 * have) / size) : 1;
tr_info const* inf = tr_torrentInfo(tor);
int const enabled = !inf->files[index].dnd;
int const priority = inf->files[index].priority;
uint64_t const have = refresh_data->refresh_file_stat[index].bytesCompleted;
int const prog = size ? (int)((100.0 * have) / size) : 1;
if ((priority != old_priority) || (enabled != old_enabled) || (have != old_have) || (prog != old_prog))
{
@ -309,7 +309,7 @@ struct ActiveData
static gboolean getSelectedFilesForeach(GtkTreeModel* model, GtkTreePath* path UNUSED, GtkTreeIter* iter, gpointer gdata)
{
const gboolean is_file = !gtk_tree_model_iter_has_child(model, iter);
gboolean const is_file = !gtk_tree_model_iter_has_child(model, iter);
if (is_file)
{
@ -359,7 +359,7 @@ struct SubtreeForeachData
static gboolean getSubtreeForeach(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, gpointer gdata)
{
const gboolean is_file = !gtk_tree_model_iter_has_child(model, iter);
gboolean const is_file = !gtk_tree_model_iter_has_child(model, iter);
if (is_file)
{
@ -438,13 +438,13 @@ static void buildTree(GNode* node, gpointer gdata)
GtkTreeIter child_iter;
struct build_data* build = gdata;
struct row_struct* child_data = node->data;
const gboolean isLeaf = node->children == NULL;
gboolean const isLeaf = node->children == NULL;
const char* mime_type = isLeaf ? gtr_get_mime_type_from_filename(child_data->name) : DIRECTORY_MIME_TYPE;
char const* mime_type = isLeaf ? gtr_get_mime_type_from_filename(child_data->name) : DIRECTORY_MIME_TYPE;
GdkPixbuf* icon = gtr_get_mime_type_icon(mime_type, GTK_ICON_SIZE_MENU, build->w);
const tr_info* inf = tr_torrentInfo(build->tor);
const int priority = isLeaf ? inf->files[ child_data->index ].priority : 0;
const gboolean enabled = isLeaf ? !inf->files[ child_data->index ].dnd : TRUE;
tr_info const* inf = tr_torrentInfo(build->tor);
int const priority = isLeaf ? inf->files[ child_data->index ].priority : 0;
gboolean const enabled = isLeaf ? !inf->files[ child_data->index ].dnd : TRUE;
char* name_esc = g_markup_escape_text(child_data->name, -1);
tr_strlsize(size_str, child_data->length, sizeof size_str);
@ -475,13 +475,13 @@ static void buildTree(GNode* node, gpointer gdata)
g_free(child_data);
}
static GNode* find_child(GNode* parent, const char* name)
static GNode* find_child(GNode* parent, char const* name)
{
GNode* child = parent->children;
while (child)
{
const struct row_struct* child_data = child->data;
struct row_struct const* child_data = child->data;
if (*child_data->name == *name && g_strcmp0(child_data->name, name) == 0)
{
@ -527,7 +527,7 @@ void gtr_file_list_set_torrent(GtkWidget* w, int torrentId)
if (tor != NULL)
{
tr_file_index_t i;
const tr_info* inf = tr_torrentInfo(tor);
tr_info const* inf = tr_torrentInfo(tor);
struct row_struct* root_data;
GNode* root;
struct build_data build;
@ -543,13 +543,13 @@ void gtr_file_list_set_torrent(GtkWidget* w, int torrentId)
{
int j;
GNode* parent = root;
const tr_file* file = &inf->files[i];
tr_file const* file = &inf->files[i];
char** tokens = g_strsplit(file->name, G_DIR_SEPARATOR_S, 0);
for (j = 0; tokens[j]; ++j)
{
const gboolean isLeaf = tokens[j + 1] == NULL;
const char* name = tokens[j];
gboolean const isLeaf = tokens[j + 1] == NULL;
char const* name = tokens[j];
GNode* node = find_child(parent, name);
if (node == NULL)
@ -606,7 +606,7 @@ static void renderPriority(GtkTreeViewColumn* column UNUSED, GtkCellRenderer* re
gpointer data UNUSED)
{
int priority;
const char* text;
char const* text;
gtk_tree_model_get(model, iter, FC_PRIORITY, &priority, -1);
switch (priority)
@ -815,8 +815,8 @@ static int on_rename_done_idle(struct rename_data* data)
if (gtk_tree_model_get_iter_from_string(data->file_data->model, &iter, data->path_string))
{
const gboolean isLeaf = !gtk_tree_model_iter_has_child(data->file_data->model, &iter);
const char* mime_type = isLeaf ? gtr_get_mime_type_from_filename(data->newname) : DIRECTORY_MIME_TYPE;
gboolean const isLeaf = !gtk_tree_model_iter_has_child(data->file_data->model, &iter);
char const* mime_type = isLeaf ? gtr_get_mime_type_from_filename(data->newname) : DIRECTORY_MIME_TYPE;
GdkPixbuf* icon = gtr_get_mime_type_icon(mime_type, GTK_ICON_SIZE_MENU, data->file_data->view);
gtk_tree_store_set(data->file_data->store, &iter, FC_LABEL, data->newname, FC_ICON, icon, -1);
@ -845,7 +845,7 @@ static int on_rename_done_idle(struct rename_data* data)
return G_SOURCE_REMOVE;
}
static void on_rename_done(tr_torrent* tor G_GNUC_UNUSED, const char* oldpath G_GNUC_UNUSED, const char* newname G_GNUC_UNUSED,
static void on_rename_done(tr_torrent* tor G_GNUC_UNUSED, char const* oldpath G_GNUC_UNUSED, char const* newname G_GNUC_UNUSED,
int error, struct rename_data* rename_data)
{
rename_data->error = error;
@ -915,7 +915,7 @@ GtkWidget* gtr_file_list_new(TrCore* core, int torrentId)
GtkTreeSelection* sel;
GtkTreeViewColumn* col;
GtkTreeView* tree_view;
const char* title;
char const* title;
PangoLayout* pango_layout;
PangoContext* pango_context;
PangoFontDescription* pango_font_description;

View File

@ -48,16 +48,16 @@ enum
TRACKER_FILTER_N_COLS
};
static int pstrcmp(const void* a, const void* b)
static int pstrcmp(void const* a, void const* b)
{
return g_strcmp0(* (const char* const*)a, * (const char* const*)b);
return g_strcmp0(* (char const* const*)a, * (char const* const*)b);
}
/* human-readable name; ie, Legaltorrents */
static char* get_name_from_host(const char* host)
static char* get_name_from_host(char const* host)
{
char* name;
const char* dot = strrchr(host, '.');
char const* dot = strrchr(host, '.');
if (tr_addressIsIP(host))
{
@ -125,7 +125,7 @@ static gboolean tracker_filter_model_update(gpointer gstore)
GStringChunk* strings = g_string_chunk_new(4096);
GHashTable* hosts_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
GtkTreeModel* tmodel = GTK_TREE_MODEL(g_object_get_qdata(o, TORRENT_MODEL_KEY));
const int first_tracker_pos = 2; /* offset past the "All" and the separator */
int const first_tracker_pos = 2; /* offset past the "All" and the separator */
g_object_steal_qdata(o, DIRTY_KEY);
@ -137,7 +137,7 @@ static gboolean tracker_filter_model_update(gpointer gstore)
do
{
tr_torrent* tor;
const tr_info* inf;
tr_info const* inf;
int keyCount;
char** keys;
@ -204,8 +204,8 @@ static gboolean tracker_filter_model_update(gpointer gstore)
for (i = 0, n = hosts->len ; ;)
{
const gboolean new_hosts_done = i >= n;
const gboolean old_hosts_done = !gtk_tree_model_iter_nth_child(model, &iter, NULL, store_pos);
gboolean const new_hosts_done = i >= n;
gboolean const old_hosts_done = !gtk_tree_model_iter_nth_child(model, &iter, NULL, store_pos);
gboolean remove_row = FALSE;
gboolean insert_row = FALSE;
@ -255,9 +255,9 @@ static gboolean tracker_filter_model_update(gpointer gstore)
GtkTreePath* path;
GtkTreeRowReference* reference;
tr_session* session = g_object_get_qdata(G_OBJECT(store), SESSION_KEY);
const char* host = hosts->pdata[i];
char const* host = hosts->pdata[i];
char* name = get_name_from_host(host);
const int count = * (int*)g_hash_table_lookup(hosts_hash, host);
int const count = * (int*)g_hash_table_lookup(hosts_hash, host);
gtk_tree_store_insert_with_values(store, &add, NULL, store_pos,
TRACKER_FILTER_COL_HOST, host,
TRACKER_FILTER_COL_NAME, name,
@ -274,8 +274,8 @@ static gboolean tracker_filter_model_update(gpointer gstore)
}
else /* update row */
{
const char* host = hosts->pdata[i];
const int count = * (int*)g_hash_table_lookup(hosts_hash, host);
char const* host = hosts->pdata[i];
int const count = * (int*)g_hash_table_lookup(hosts_hash, host);
tracker_model_update_count(store, &iter, count);
++store_pos;
++i;
@ -321,7 +321,7 @@ static gboolean is_it_a_separator(GtkTreeModel* m, GtkTreeIter* iter, gpointer d
static void tracker_model_update_idle(gpointer tracker_model)
{
GObject* o = G_OBJECT(tracker_model);
const gboolean pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
if (!pending)
{
@ -426,7 +426,7 @@ static GtkWidget* tracker_combo_box_new(GtkTreeModel* tmodel)
return c;
}
static gboolean test_tracker(tr_torrent* tor, int active_tracker_type, const char* host)
static gboolean test_tracker(tr_torrent* tor, int active_tracker_type, char const* host)
{
gboolean matches = TRUE;
@ -434,7 +434,7 @@ static gboolean test_tracker(tr_torrent* tor, int active_tracker_type, const cha
{
unsigned int i;
char tmp[1024];
const tr_info* const inf = tr_torrentInfo(tor);
tr_info const* const inf = tr_torrentInfo(tor);
for (i = 0; i < inf->trackerCount; ++i)
{
@ -489,7 +489,7 @@ static gboolean activity_is_it_a_separator(GtkTreeModel* m, GtkTreeIter* i, gpoi
static gboolean test_torrent_activity(tr_torrent* tor, int type)
{
const tr_stat* st = tr_torrentStatCached(tor);
tr_stat const* st = tr_torrentStatCached(tor);
switch (type)
{
@ -583,9 +583,9 @@ static GtkTreeModel* activity_filter_model_new(GtkTreeModel* tmodel)
struct
{
int type;
const char* context;
const char* name;
const char* stock_id;
char const* context;
char const* name;
char const* stock_id;
}
types[] =
{
@ -608,7 +608,7 @@ static GtkTreeModel* activity_filter_model_new(GtkTreeModel* tmodel)
for (i = 0, n = G_N_ELEMENTS(types); i < n; ++i)
{
const char* name = types[i].context ? g_dpgettext2(NULL, types[i].context, types[i].name) : _(types[i].name);
char const* name = types[i].context ? g_dpgettext2(NULL, types[i].context, types[i].name) : _(types[i].name);
gtk_list_store_insert_with_values(store, NULL, -1,
ACTIVITY_FILTER_COL_NAME, name,
ACTIVITY_FILTER_COL_TYPE, types[i].type,
@ -638,7 +638,7 @@ static void render_activity_pixbuf_func(GtkCellLayout* cell_layout UNUSED, GtkCe
static void activity_model_update_idle(gpointer activity_model)
{
GObject* o = G_OBJECT(activity_model);
const gboolean pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
if (!pending)
{
@ -708,7 +708,7 @@ static GtkWidget* activity_combo_box_new(GtkTreeModel* tmodel)
*****
****/
static gboolean testText(const tr_torrent* tor, const char* key)
static gboolean testText(tr_torrent const* tor, char const* key)
{
gboolean ret = FALSE;
@ -719,7 +719,7 @@ static gboolean testText(const tr_torrent* tor, const char* key)
else
{
tr_file_index_t i;
const tr_info* inf = tr_torrentInfo(tor);
tr_info const* inf = tr_torrentInfo(tor);
/* test the torrent name... */
{
@ -779,14 +779,14 @@ struct filter_data
static gboolean is_row_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer vdata)
{
const char* text;
char const* text;
tr_torrent* tor;
struct filter_data* data = vdata;
GObject* o = G_OBJECT(data->filter_model);
gtk_tree_model_get(model, iter, MC_TORRENT, &tor, -1);
text = (const char*)g_object_get_qdata(o, TEXT_KEY);
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);
@ -903,7 +903,7 @@ static gboolean update_count_label(gpointer gdata)
static void update_count_label_idle(struct filter_data* data)
{
GObject* o = G_OBJECT(data->show_lb);
const gboolean pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
gboolean const pending = g_object_get_qdata(o, DIRTY_KEY) != NULL;
if (!pending)
{

View File

@ -36,7 +36,7 @@ void hig_workarea_add_section_title_widget(GtkWidget* t, guint* row, GtkWidget*
++*row;
}
void hig_workarea_add_section_title(GtkWidget* t, guint* row, const char* section_title)
void hig_workarea_add_section_title(GtkWidget* t, guint* row, char const* section_title)
{
char buf[512];
GtkWidget* l;
@ -62,7 +62,7 @@ void hig_workarea_add_wide_tall_control(GtkWidget* t, guint* row, GtkWidget* w)
hig_workarea_add_wide_control(t, row, w);
}
GtkWidget* hig_workarea_add_wide_checkbutton(GtkWidget* t, guint* row, const char* mnemonic_string, gboolean is_active)
GtkWidget* hig_workarea_add_wide_checkbutton(GtkWidget* t, guint* row, char const* mnemonic_string, gboolean is_active)
{
GtkWidget* w = gtk_check_button_new_with_mnemonic(mnemonic_string);
@ -123,7 +123,7 @@ void hig_workarea_add_row_w(GtkWidget* t, guint* row, GtkWidget* label, GtkWidge
++*row;
}
GtkWidget* hig_workarea_add_row(GtkWidget* t, guint* row, const char* mnemonic_string, GtkWidget* control, GtkWidget* mnemonic)
GtkWidget* hig_workarea_add_row(GtkWidget* t, guint* row, char const* mnemonic_string, GtkWidget* control, GtkWidget* mnemonic)
{
GtkWidget* l = gtk_label_new_with_mnemonic(mnemonic_string);
@ -131,7 +131,7 @@ GtkWidget* hig_workarea_add_row(GtkWidget* t, guint* row, const char* mnemonic_s
return l;
}
GtkWidget* hig_workarea_add_tall_row(GtkWidget* table, guint* row, const char* mnemonic_string, GtkWidget* control,
GtkWidget* hig_workarea_add_tall_row(GtkWidget* table, guint* row, char const* mnemonic_string, GtkWidget* control,
GtkWidget* mnemonic)
{
GtkWidget* l = gtk_label_new_with_mnemonic(mnemonic_string);

View File

@ -21,20 +21,20 @@ void hig_workarea_add_section_divider(GtkWidget* table, guint* row);
void hig_workarea_add_section_title_widget(GtkWidget* t, guint* row, GtkWidget* w);
void hig_workarea_add_section_title(GtkWidget* table, guint* row, const char* section_title);
void hig_workarea_add_section_title(GtkWidget* table, guint* row, char const* section_title);
void hig_workarea_add_wide_tall_control(GtkWidget* table, guint* row, GtkWidget* w);
void hig_workarea_add_wide_control(GtkWidget* table, guint* row, GtkWidget* w);
GtkWidget* hig_workarea_add_wide_checkbutton(GtkWidget* table, guint* row, const char* mnemonic_string, gboolean is_active);
GtkWidget* hig_workarea_add_wide_checkbutton(GtkWidget* table, guint* row, char const* mnemonic_string, gboolean is_active);
void hig_workarea_add_label_w(GtkWidget* table, guint row, GtkWidget* label_widget);
GtkWidget* hig_workarea_add_tall_row(GtkWidget* table, guint* row, const char* mnemonic_string, GtkWidget* control,
GtkWidget* hig_workarea_add_tall_row(GtkWidget* table, guint* row, char const* mnemonic_string, GtkWidget* control,
GtkWidget* mnemonic_or_null_for_control);
GtkWidget* hig_workarea_add_row(GtkWidget* table, guint* row, const char* mnemonic_string, GtkWidget* control,
GtkWidget* hig_workarea_add_row(GtkWidget* table, guint* row, char const* mnemonic_string, GtkWidget* control,
GtkWidget* mnemonic_or_null_for_control);
void hig_workarea_add_row_w(GtkWidget* table, guint* row, GtkWidget* label, GtkWidget* control,

View File

@ -12,7 +12,7 @@
#define VOID_PIXBUF_KEY "void-pixbuf"
static const char* get_static_string(const char* s)
static char const* get_static_string(char const* s)
{
static GStringChunk* static_strings = NULL;
@ -73,9 +73,9 @@ static IconCache* icon_cache_new(GtkWidget* for_widget, int icon_size)
return icon_cache;
}
static const char* _icon_cache_get_icon_key(GIcon* icon)
static char const* _icon_cache_get_icon_key(GIcon* icon)
{
const char* key = NULL;
char const* key = NULL;
if (G_IS_THEMED_ICON(icon))
{
@ -116,7 +116,7 @@ static GdkPixbuf* get_themed_icon_pixbuf(GThemedIcon* icon, int size, GtkIconThe
g_object_get(icon, "names", &icon_names, NULL);
icon_info = gtk_icon_theme_choose_icon(icon_theme, (const char**)icon_names, size, 0);
icon_info = gtk_icon_theme_choose_icon(icon_theme, (char const**)icon_names, size, 0);
if (icon_info == NULL)
{
@ -181,10 +181,10 @@ static GdkPixbuf* _get_icon_pixbuf(GIcon* icon, int size, GtkIconTheme* theme)
return NULL;
}
static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icon_cache, const char* mime_type)
static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icon_cache, char const* mime_type)
{
GIcon* icon;
const char* key = NULL;
char const* key = NULL;
GdkPixbuf* pixbuf;
icon = g_content_type_get_icon(mime_type);
@ -216,7 +216,7 @@ static GdkPixbuf* icon_cache_get_mime_type_icon(IconCache* icon_cache, const cha
return pixbuf;
}
GdkPixbuf* gtr_get_mime_type_icon(const char* mime_type, GtkIconSize icon_size, GtkWidget* for_widget)
GdkPixbuf* gtr_get_mime_type_icon(char const* mime_type, GtkIconSize icon_size, GtkWidget* for_widget)
{
int n;
@ -259,10 +259,10 @@ GdkPixbuf* gtr_get_mime_type_icon(const char* mime_type, GtkIconSize icon_size,
return icon_cache_get_mime_type_icon(icon_cache[n], mime_type);
}
const char* gtr_get_mime_type_from_filename(const char* file)
char const* gtr_get_mime_type_from_filename(char const* file)
{
char* tmp = g_content_type_guess(file, NULL, 0, NULL);
const char* ret = get_static_string(tmp);
char const* ret = get_static_string(tmp);
g_free(tmp);
return ret;
}

View File

@ -10,6 +10,6 @@
#define DIRECTORY_MIME_TYPE "folder"
#define UNKNOWN_MIME_TYPE "unknown"
const char* gtr_get_mime_type_from_filename(const char* file);
char const* gtr_get_mime_type_from_filename(char const* file);
GdkPixbuf* gtr_get_mime_type_icon(const char* mime_type, GtkIconSize icon_size, GtkWidget* for_widget);
GdkPixbuf* gtr_get_mime_type_icon(char const* mime_type, GtkIconSize icon_size, GtkWidget* for_widget);

View File

@ -58,7 +58,7 @@
#define MY_READABLE_NAME "transmission-gtk"
#define SHOW_LICENSE
static const char* LICENSE =
static char const* LICENSE =
"Copyright 2005-2016. All code is copyrighted by the respective authors.\n"
"\n"
"Transmission can be redistributed and/or modified under the terms of the "
@ -237,9 +237,9 @@ static gboolean refresh_actions(gpointer gdata)
{
int canUpdate;
struct counts_data sel_counts;
const size_t total = gtr_core_get_torrent_count(data->core);
const size_t active = gtr_core_get_active_torrent_count(data->core);
const int torrent_count = gtk_tree_model_iter_n_children(gtr_core_model(data->core), NULL);
size_t const total = gtr_core_get_torrent_count(data->core);
size_t const active = gtr_core_get_active_torrent_count(data->core);
int const torrent_count = gtk_tree_model_iter_n_children(gtr_core_model(data->core), NULL);
bool has_selection;
get_selected_torrent_counts(data, &sel_counts);
@ -296,7 +296,7 @@ static void on_selection_changed(GtkTreeSelection* s UNUSED, gpointer gdata)
static gboolean has_magnet_link_handler(void)
{
GAppInfo* app_info = g_app_info_get_default_for_uri_scheme("magnet");
const gboolean has_handler = app_info != NULL;
gboolean const has_handler = app_info != NULL;
g_clear_object(&app_info);
return has_handler;
}
@ -305,7 +305,7 @@ static void register_magnet_link_handler(void)
{
GError* error;
GAppInfo* app;
const char* const content_type = "x-scheme-handler/magnet";
char const* const content_type = "x-scheme-handler/magnet";
error = NULL;
app = g_app_info_create_from_commandline("transmission-gtk", "transmission-gtk", G_APP_INFO_CREATE_SUPPORTS_URIS, &error);
@ -330,7 +330,7 @@ static void ensure_magnet_handler_exists(void)
static void on_main_window_size_allocated(GtkWidget* gtk_window, GtkAllocation* alloc UNUSED, gpointer gdata UNUSED)
{
GdkWindow* gdk_window = gtk_widget_get_window(gtk_window);
const gboolean isMaximized = (gdk_window != NULL) && (gdk_window_get_state(gdk_window) & GDK_WINDOW_STATE_MAXIMIZED);
gboolean const isMaximized = (gdk_window != NULL) && (gdk_window_get_state(gdk_window) & GDK_WINDOW_STATE_MAXIMIZED);
gtr_pref_int_set(TR_KEY_main_window_is_maximized, isMaximized);
@ -492,7 +492,7 @@ static void app_setup(GtkWindow* wind, struct cbdata* cbdata);
static void on_startup(GApplication* application, gpointer user_data)
{
GError* error;
const char* str;
char const* str;
GtkWindow* win;
GtkUIManager* ui_manager;
tr_session* session;
@ -542,9 +542,9 @@ static void on_startup(GApplication* application, gpointer user_data)
{
if (gtr_pref_flag_get(TR_KEY_blocklist_updates_enabled))
{
const int64_t last_time = gtr_pref_int_get(TR_KEY_blocklist_date);
const int SECONDS_IN_A_WEEK = 7 * 24 * 60 * 60;
const time_t now = time(NULL);
int64_t const last_time = gtr_pref_int_get(TR_KEY_blocklist_date);
int const SECONDS_IN_A_WEEK = 7 * 24 * 60 * 60;
time_t const now = time(NULL);
if (last_time + SECONDS_IN_A_WEEK < now)
{
@ -575,9 +575,9 @@ static void on_activate(GApplication* app UNUSED, struct cbdata* cbdata)
static void open_files(GSList* files, gpointer gdata)
{
struct cbdata* cbdata = gdata;
const gboolean do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents) && !cbdata->start_paused;
const gboolean do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
const gboolean do_notify = TRUE;
gboolean const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents) && !cbdata->start_paused;
gboolean const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
gboolean const do_notify = TRUE;
gtr_core_add_files(cbdata->core, files, do_start, do_prompt, do_notify);
}
@ -692,9 +692,9 @@ static void on_core_busy(TrCore* core UNUSED, gboolean busy, struct cbdata* c)
gtr_window_set_busy(c->wind, busy);
}
static void on_core_error(TrCore*, guint, const char*, struct cbdata*);
static void on_core_error(TrCore*, guint, char const*, struct cbdata*);
static void on_add_torrent(TrCore*, tr_ctor*, gpointer);
static void on_prefs_changed(TrCore* core, const tr_quark key, gpointer);
static void on_prefs_changed(TrCore* core, tr_quark const key, gpointer);
static void main_window_setup(struct cbdata* cbdata, GtkWindow* wind);
static gboolean update_model_loop(gpointer gdata);
static gboolean update_model_once(gpointer gdata);
@ -837,7 +837,7 @@ static void on_drag_data_received(GtkWidget* widget UNUSED, GdkDragContext* drag
{
guint i;
char** uris = gtk_selection_data_get_uris(selection_data);
const guint file_count = g_strv_length(uris);
guint const file_count = g_strv_length(uris);
GSList* files = NULL;
for (i = 0; i < file_count; ++i)
@ -1010,16 +1010,16 @@ static void on_app_exit(gpointer vdata)
g_thread_new("shutdown-thread", session_close_threadfunc, session_close_data);
}
static void show_torrent_errors(GtkWindow* window, const char* primary, GSList** files)
static void show_torrent_errors(GtkWindow* window, char const* primary, GSList** files)
{
GSList* l;
GtkWidget* w;
GString* s = g_string_new(NULL);
const char* leader = g_slist_length(*files) > 1 ? gtr_get_unicode_string(GTR_UNICODE_BULLET) : "";
char const* leader = g_slist_length(*files) > 1 ? gtr_get_unicode_string(GTR_UNICODE_BULLET) : "";
for (l = *files; l != NULL; l = l->next)
{
g_string_append_printf(s, "%s %s\n", leader, (const char*)l->data);
g_string_append_printf(s, "%s %s\n", leader, (char const*)l->data);
}
w = gtk_message_dialog_new(window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", primary);
@ -1048,7 +1048,7 @@ static void flush_torrent_errors(struct cbdata* cbdata)
}
}
static void on_core_error(TrCore* core UNUSED, guint code, const char* msg, struct cbdata* c)
static void on_core_error(TrCore* core UNUSED, guint code, char const* msg, struct cbdata* c)
{
switch (code)
{
@ -1097,7 +1097,7 @@ static void on_add_torrent(TrCore* core, tr_ctor* ctor, gpointer gdata)
gtk_widget_show(w);
}
static void on_prefs_changed(TrCore* core UNUSED, const tr_quark key, gpointer data)
static void on_prefs_changed(TrCore* core UNUSED, tr_quark const key, gpointer data)
{
struct cbdata* cbdata = data;
tr_session* tr = gtr_core_session(cbdata->core);
@ -1130,7 +1130,7 @@ static void on_prefs_changed(TrCore* core UNUSED, const tr_quark key, gpointer d
case TR_KEY_show_notification_area_icon:
{
const bool show = gtr_pref_flag_get(key);
bool const show = gtr_pref_flag_get(key);
if (show && !cbdata->icon)
{
@ -1246,7 +1246,7 @@ static void on_prefs_changed(TrCore* core UNUSED, const tr_quark key, gpointer d
case TR_KEY_alt_speed_enabled:
{
const bool b = gtr_pref_flag_get(key);
bool const b = gtr_pref_flag_get(key);
tr_sessionUseAltSpeed(tr, b);
gtr_action_set_toggled(tr_quark_get_string(key, NULL), b);
break;
@ -1339,7 +1339,7 @@ static void update_model_soon(gpointer gdata)
static gboolean update_model_loop(gpointer gdata)
{
const gboolean done = global_sigcount;
gboolean const done = global_sigcount;
if (!done)
{
@ -1351,8 +1351,8 @@ static gboolean update_model_loop(gpointer gdata)
static void show_about_dialog(GtkWindow* parent)
{
const char* uri = "https://transmissionbt.com/";
const char* authors[] =
char const* uri = "https://transmissionbt.com/";
char const* authors[] =
{
"Jordan Lee (Backend; GTK+)",
"Mitchell Livingston (Backend; OS X)",
@ -1387,7 +1387,7 @@ static void append_id_to_benc_list(GtkTreeModel* m, GtkTreePath* path UNUSED, Gt
tr_variantListAddInt(list, tr_torrentId(tor));
}
static gboolean call_rpc_for_selected_torrents(struct cbdata* data, const char* method)
static gboolean call_rpc_for_selected_torrents(struct cbdata* data, char const* method)
{
tr_variant top, *args, *ids;
gboolean invoked = FALSE;
@ -1509,7 +1509,7 @@ static void copy_magnet_link_to_clipboard(GtkWidget* w, tr_torrent* tor)
tr_free(magnet);
}
void gtr_actions_handler(const char* action_name, gpointer user_data)
void gtr_actions_handler(char const* action_name, gpointer user_data)
{
gboolean changed = FALSE;
struct cbdata* data = user_data;

View File

@ -58,10 +58,10 @@ static gboolean onProgressDialogRefresh(gpointer data)
{
char* str = NULL;
MakeMetaUI* ui = data;
const tr_metainfo_builder* b = ui->builder;
tr_metainfo_builder const* b = ui->builder;
GtkDialog* d = GTK_DIALOG(ui->progress_dialog);
GtkProgressBar* p = GTK_PROGRESS_BAR(ui->progress_bar);
const double fraction = b->pieceCount ? ((double)b->pieceIndex / b->pieceCount) : 0;
double const fraction = b->pieceCount ? ((double)b->pieceIndex / b->pieceCount) : 0;
char* base = g_path_get_basename(b->top);
/* progress label */
@ -135,7 +135,7 @@ static void onProgressDialogDestroyed(gpointer data, GObject* dead UNUSED)
static void addTorrent(MakeMetaUI* ui)
{
char* path;
const tr_metainfo_builder* b = ui->builder;
tr_metainfo_builder const* b = ui->builder;
tr_ctor* ctor = tr_ctorNew(gtr_core_session(ui->core));
tr_ctorSetMetainfoFromFile(ctor, ui->target);
@ -224,9 +224,9 @@ static void onResponse(GtkDialog* d, int response, gpointer user_data)
GtkEntry* c_entry = GTK_ENTRY(ui->comment_entry);
GtkToggleButton* p_check = GTK_TOGGLE_BUTTON(ui->private_check);
GtkToggleButton* c_check = GTK_TOGGLE_BUTTON(ui->comment_check);
const char* comment = gtk_entry_get_text(c_entry);
const gboolean isPrivate = gtk_toggle_button_get_active(p_check);
const gboolean useComment = gtk_toggle_button_get_active(c_check);
char const* comment = gtk_entry_get_text(c_entry);
gboolean const isPrivate = gtk_toggle_button_get_active(p_check);
gboolean const useComment = gtk_toggle_button_get_active(c_check);
tr_tracker_info* trackers;
/* destination file */
@ -249,7 +249,7 @@ static void onResponse(GtkDialog* d, int response, gpointer user_data)
for (i = n = tier = 0; tracker_strings[i]; ++i)
{
const char* str = tracker_strings[i];
char const* str = tracker_strings[i];
if (!*str)
{
@ -292,8 +292,8 @@ static void onSourceToggled(GtkToggleButton* tb, gpointer user_data)
static void updatePiecesLabel(MakeMetaUI* ui)
{
const tr_metainfo_builder* builder = ui->builder;
const char* filename = builder ? builder->top : NULL;
tr_metainfo_builder const* builder = ui->builder;
char const* filename = builder ? builder->top : NULL;
GString* gstr = g_string_new(NULL);
g_string_append(gstr, "<i>");
@ -319,7 +319,7 @@ static void updatePiecesLabel(MakeMetaUI* ui)
g_string_free(gstr, TRUE);
}
static void setFilename(MakeMetaUI* ui, const char* filename)
static void setFilename(MakeMetaUI* ui, char const* filename)
{
if (ui->builder != NULL)
{
@ -374,7 +374,7 @@ static void onFileToggled(GtkToggleButton* tb, gpointer data)
onSourceToggled2(tb, ui->file_chooser, ui);
}
static const char* getDefaultSavePath(void)
static char const* getDefaultSavePath(void)
{
return g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP);
}
@ -388,7 +388,7 @@ static void on_drag_data_received(GtkWidget* widget UNUSED, GdkDragContext* drag
if (uris && uris[0])
{
const char* uri = uris[ 0 ];
char const* uri = uris[ 0 ];
gchar* filename = g_filename_from_uri(uri, NULL, NULL);
if (g_file_test(filename, G_FILE_TEST_IS_DIR))
@ -415,7 +415,7 @@ static void on_drag_data_received(GtkWidget* widget UNUSED, GdkDragContext* drag
GtkWidget* gtr_torrent_creation_dialog_new(GtkWindow* parent, TrCore* core)
{
const char* str;
char const* str;
GtkWidget* d, *t, *w, *l, *fr, *sw, *v;
GSList* slist;
guint row = 0;

View File

@ -67,7 +67,7 @@ static gboolean is_pinned_to_new(struct MsgData* data)
if (gtk_tree_view_get_visible_range(data->view, NULL, &last_visible))
{
GtkTreeIter iter;
const int row_count = gtk_tree_model_iter_n_children(data->sort, NULL);
int const row_count = gtk_tree_model_iter_n_children(data->sort, NULL);
if (gtk_tree_model_iter_nth_child(data->sort, &iter, NULL, row_count - 1))
{
@ -88,7 +88,7 @@ static void scroll_to_bottom(struct MsgData* data)
if (data->sort != NULL)
{
GtkTreeIter iter;
const int row_count = gtk_tree_model_iter_n_children(data->sort, NULL);
int const row_count = gtk_tree_model_iter_n_children(data->sort, NULL);
if (gtk_tree_model_iter_nth_child(data->sort, &iter, NULL, row_count - 1))
{
@ -106,8 +106,8 @@ static void scroll_to_bottom(struct MsgData* data)
static void level_combo_changed_cb(GtkComboBox* combo_box, gpointer gdata)
{
struct MsgData* data = gdata;
const int level = gtr_combo_box_get_active_enum(combo_box);
const gboolean pinned_to_new = is_pinned_to_new(data);
int const level = gtr_combo_box_get_active_enum(combo_box);
gboolean const pinned_to_new = is_pinned_to_new(data);
tr_logSetLevel(level);
gtr_core_set_pref_int(data->core, TR_KEY_message_level, level);
@ -124,7 +124,7 @@ static void level_combo_changed_cb(GtkComboBox* combo_box, gpointer gdata)
static char* gtr_localtime(time_t time)
{
char buf[256], *eoln;
const struct tm tm = *localtime(&time);
struct tm const tm = *localtime(&time);
g_strlcpy(buf, asctime(&tm), sizeof(buf));
@ -136,7 +136,7 @@ static char* gtr_localtime(time_t time)
return g_locale_to_utf8(buf, -1, NULL, NULL, NULL);
}
static void doSave(GtkWindow* parent, struct MsgData* data, const char* filename)
static void doSave(GtkWindow* parent, struct MsgData* data, char const* filename)
{
FILE* fp = fopen(filename, "w+");
@ -157,8 +157,8 @@ static void doSave(GtkWindow* parent, struct MsgData* data, const char* filename
do
{
char* date;
const char* levelStr;
const struct tr_log_message* node;
char const* levelStr;
struct tr_log_message const* node;
gtk_tree_model_get(model, &iter, COL_TR_MSG, &node, -1);
date = gtr_localtime(node->when);
@ -227,7 +227,7 @@ static void onPauseToggled(GtkToggleToolButton* w, gpointer gdata)
data->isPaused = gtk_toggle_tool_button_get_active(w);
}
static const char* getForegroundColor(int msgLevel)
static char const* getForegroundColor(int msgLevel)
{
switch (msgLevel)
{
@ -249,9 +249,9 @@ static const char* getForegroundColor(int msgLevel)
static void renderText(GtkTreeViewColumn* column UNUSED, GtkCellRenderer* renderer, GtkTreeModel* tree_model, GtkTreeIter* iter,
gpointer gcol)
{
const int col = GPOINTER_TO_INT(gcol);
int const col = GPOINTER_TO_INT(gcol);
char* str = NULL;
const struct tr_log_message* node;
struct tr_log_message const* node;
gtk_tree_model_get(tree_model, iter, col, &str, COL_TR_MSG, &node, -1);
g_object_set(renderer, "text", str, "foreground", getForegroundColor(node->level), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
@ -262,7 +262,7 @@ static void renderTime(GtkTreeViewColumn* column UNUSED, GtkCellRenderer* render
{
struct tm tm;
char buf[16];
const struct tr_log_message* node;
struct tr_log_message const* node;
gtk_tree_model_get(tree_model, iter, COL_TR_MSG, &node, -1);
tm = *localtime(&node->when);
@ -274,7 +274,7 @@ static void appendColumn(GtkTreeView* view, int col)
{
GtkCellRenderer* r;
GtkTreeViewColumn* c;
const char* title = NULL;
char const* title = NULL;
switch (col)
{
@ -333,8 +333,8 @@ static void appendColumn(GtkTreeView* view, int col)
static gboolean isRowVisible(GtkTreeModel* model, GtkTreeIter* iter, gpointer gdata)
{
const struct tr_log_message* node;
const struct MsgData* data = gdata;
struct tr_log_message const* node;
struct MsgData const* data = gdata;
gtk_tree_model_get(model, iter, COL_TR_MSG, &node, -1);
@ -354,11 +354,11 @@ static tr_log_message* addMessages(GtkListStore* store, struct tr_log_message* h
{
tr_log_message* i;
static unsigned int sequence = 0;
const char* default_name = g_get_application_name();
char const* default_name = g_get_application_name();
for (i = head; i && i->next; i = i->next)
{
const char* name = i->name ? i->name : default_name;
char const* name = i->name ? i->name : default_name;
gtk_list_store_insert_with_values(store, NULL, 0,
COL_TR_MSG, i,
@ -389,7 +389,7 @@ static tr_log_message* addMessages(GtkListStore* store, struct tr_log_message* h
static gboolean onRefresh(gpointer gdata)
{
struct MsgData* data = gdata;
const gboolean pinned_to_new = is_pinned_to_new(data);
gboolean const pinned_to_new = is_pinned_to_new(data);
if (!data->isPaused)
{

View File

@ -115,8 +115,8 @@ static void g_signal_callback(GDBusProxy* proxy UNUSED, char* sender_name UNUSED
}
else if (g_strcmp0(action, "file") == 0)
{
const tr_info* inf = tr_torrentInfo(tor);
const char* dir = tr_torrentGetDownloadDir(tor);
tr_info const* inf = tr_torrentInfo(tor);
char const* dir = tr_torrentGetDownloadDir(tor);
char* path = g_build_filename(dir, inf->files[0].name, NULL);
gtr_open_file(path);
g_free(path);
@ -175,7 +175,7 @@ void gtr_notify_torrent_completed(TrCore* core, int torrent_id)
GVariantBuilder actions_builder;
TrNotification* n;
tr_torrent* tor;
const char* cmd = gtr_pref_string_get(TR_KEY_torrent_complete_sound_command);
char const* cmd = gtr_pref_string_get(TR_KEY_torrent_complete_sound_command);
if (gtr_pref_flag_get(TR_KEY_torrent_complete_sound_enabled))
{
@ -199,7 +199,7 @@ void gtr_notify_torrent_completed(TrCore* core, int torrent_id)
if (server_supports_actions)
{
const tr_info* inf = tr_torrentInfo(tor);
tr_info const* inf = tr_torrentInfo(tor);
if (inf->fileCount == 1)
{
@ -217,7 +217,7 @@ void gtr_notify_torrent_completed(TrCore* core, int torrent_id)
_("Torrent Complete"), tr_torrentName(tor), &actions_builder, NULL, -1), G_DBUS_CALL_FLAGS_NONE, -1, NULL, notify_callback, n);
}
void gtr_notify_torrent_added(const char* name)
void gtr_notify_torrent_added(char const* name)
{
TrNotification* n;

View File

@ -12,6 +12,6 @@
void gtr_notify_init(void);
void gtr_notify_torrent_added(const char* name);
void gtr_notify_torrent_added(char const* name);
void gtr_notify_torrent_completed(TrCore* core, int torrent_id);

View File

@ -35,7 +35,7 @@ static GSList* get_recent_destinations(void)
for (i = 0; i < N_RECENT; ++i)
{
char key[64];
const char* val;
char const* val;
g_snprintf(key, sizeof(key), "recent-download-dir-%d", i + 1);
if ((val = gtr_pref_string_get(tr_quark_new(key, TR_BAD_SIZE))))
@ -47,7 +47,7 @@ static GSList* get_recent_destinations(void)
return list;
}
static void save_recent_destination(TrCore* core, const char* dir)
static void save_recent_destination(TrCore* core, char const* dir)
{
int i;
GSList* l;
@ -156,7 +156,7 @@ static void addResponseCB(GtkDialog* dialog, gint response, gpointer gdata)
static void updateTorrent(struct OpenData* o)
{
const gboolean isLocalFile = tr_ctorGetSourceFile(o->ctor) != NULL;
gboolean const isLocalFile = tr_ctorGetSourceFile(o->ctor) != NULL;
gtk_widget_set_sensitive(o->trash_check, isLocalFile);
if (!o->tor)
@ -270,7 +270,7 @@ static void addTorrentFilters(GtkFileChooser* chooser)
GtkWidget* gtr_torrent_options_dialog_new(GtkWindow* parent, TrCore* core, tr_ctor* ctor)
{
const char* str;
char const* str;
GtkWidget* w;
GtkWidget* d;
GtkGrid* grid;
@ -436,9 +436,9 @@ static void onOpenDialogResponse(GtkDialog* dialog, int response, gpointer core)
GtkFileChooser* chooser = GTK_FILE_CHOOSER(dialog);
GtkWidget* w = gtk_file_chooser_get_extra_widget(chooser);
GtkToggleButton* tb = GTK_TOGGLE_BUTTON(w);
const gboolean do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
const gboolean do_prompt = gtk_toggle_button_get_active(tb);
const gboolean do_notify = FALSE;
gboolean const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
gboolean const do_prompt = gtk_toggle_button_get_active(tb);
gboolean const do_notify = FALSE;
GSList* files = gtk_file_chooser_get_files(chooser);
gtr_core_add_files(core, files, do_start, do_prompt, do_notify);
@ -453,7 +453,7 @@ GtkWidget* gtr_torrent_open_from_file_dialog_new(GtkWindow* parent, TrCore* core
{
GtkWidget* w;
GtkWidget* c;
const char* folder;
char const* folder;
w = gtk_file_chooser_dialog_new(_("Open a Torrent"), parent, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);

View File

@ -46,7 +46,7 @@ static void data_free(gpointer gdata)
static void startMovingNextTorrent(struct relocate_dialog_data* data)
{
char* str;
const int id = GPOINTER_TO_INT(data->torrent_ids->data);
int const id = GPOINTER_TO_INT(data->torrent_ids->data);
tr_torrent* tor = gtr_core_find_torrent(data->core, id);
@ -67,11 +67,11 @@ static void startMovingNextTorrent(struct relocate_dialog_data* data)
static gboolean onTimer(gpointer gdata)
{
struct relocate_dialog_data* data = gdata;
const int done = data->done;
int const done = data->done;
if (done == TR_LOC_ERROR)
{
const int flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
int const flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
GtkWidget* w = gtk_message_dialog_new(GTK_WINDOW(data->message_dialog), flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s",
_("Couldn't move torrent"));
gtk_dialog_run(GTK_DIALOG(w));

View File

@ -36,7 +36,7 @@ struct stat_ui
TrCore* core;
};
static void setLabel(GtkLabel* l, const char* str)
static void setLabel(GtkLabel* l, char const* str)
{
gtr_label_set_text(l, str);
}
@ -52,9 +52,9 @@ static void setLabelFromRatio(GtkLabel* l, double d)
static gboolean updateStats(gpointer gdata)
{
char buf[128];
const char* fmt;
char const* fmt;
tr_session_stats one, all;
const size_t buflen = sizeof(buf);
size_t const buflen = sizeof(buf);
struct stat_ui* ui = gdata;
tr_sessionGetStats(gtr_core_session(ui->core), &one);
@ -87,10 +87,10 @@ static void dialogResponse(GtkDialog* dialog, gint response, gpointer gdata)
if (response == TR_RESPONSE_RESET)
{
const char* primary = _("Reset your statistics?");
const char* secondary = _("These statistics are for your information only. "
char const* primary = _("Reset your statistics?");
char const* secondary = _("These statistics are for your information only. "
"Resetting them doesn't affect the statistics logged by your BitTorrent trackers.");
const int flags = GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL;
int const flags = GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL;
GtkWidget* w = gtk_message_dialog_new(GTK_WINDOW(dialog), flags, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", primary);
gtk_dialog_add_buttons(GTK_DIALOG(w), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("_Reset"), TR_RESPONSE_RESET, NULL);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(w), "%s", secondary);

View File

@ -36,14 +36,14 @@ enum
****
***/
static void getProgressString(GString* gstr, const tr_torrent* tor, const tr_info* info, const tr_stat* st)
static void getProgressString(GString* gstr, tr_torrent const* tor, tr_info const* info, tr_stat const* st)
{
const int isDone = st->leftUntilDone == 0;
const uint64_t haveTotal = st->haveUnchecked + st->haveValid;
const int isSeed = st->haveValid >= info->totalSize;
int const isDone = st->leftUntilDone == 0;
uint64_t const haveTotal = st->haveUnchecked + st->haveValid;
int const isSeed = st->haveValid >= info->totalSize;
char buf1[32], buf2[32], buf3[32], buf4[32], buf5[32], buf6[32];
double seedRatio;
const gboolean hasSeedRatio = tr_torrentGetSeedRatio(tor, &seedRatio);
gboolean const hasSeedRatio = tr_torrentGetSeedRatio(tor, &seedRatio);
if (!isDone) /* downloading */
{
@ -122,7 +122,7 @@ static void getProgressString(GString* gstr, const tr_torrent* tor, const tr_inf
/* add time when downloading */
if ((st->activity == TR_STATUS_DOWNLOAD) || (hasSeedRatio && (st->activity == TR_STATUS_SEED)))
{
const int eta = st->eta;
int const eta = st->eta;
g_string_append(gstr, " - ");
if (eta < 0)
@ -139,12 +139,12 @@ static void getProgressString(GString* gstr, const tr_torrent* tor, const tr_inf
}
}
static char* getShortTransferString(const tr_torrent* tor, const tr_stat* st, double uploadSpeed_KBps,
static char* getShortTransferString(tr_torrent const* tor, tr_stat const* st, double uploadSpeed_KBps,
double downloadSpeed_KBps, char* buf, size_t buflen)
{
const int haveMeta = tr_torrentHasMetadata(tor);
const int haveUp = haveMeta && st->peersGettingFromUs > 0;
const int haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0));
int const haveMeta = tr_torrentHasMetadata(tor);
int const haveUp = haveMeta && st->peersGettingFromUs > 0;
int const haveDown = haveMeta && ((st->peersSendingToUs > 0) || (st->webseedsSendingToUs > 0));
if (haveDown)
{
@ -176,7 +176,7 @@ static char* getShortTransferString(const tr_torrent* tor, const tr_stat* st, do
return buf;
}
static void getShortStatusString(GString* gstr, const tr_torrent* tor, const tr_stat* st, double uploadSpeed_KBps,
static void getShortStatusString(GString* gstr, tr_torrent const* tor, tr_stat const* st, double uploadSpeed_KBps,
double downloadSpeed_KBps)
{
switch (st->activity)
@ -219,12 +219,12 @@ static void getShortStatusString(GString* gstr, const tr_torrent* tor, const tr_
}
}
static void getStatusString(GString* gstr, const tr_torrent* tor, const tr_stat* st, const double uploadSpeed_KBps,
const double downloadSpeed_KBps)
static void getStatusString(GString* gstr, tr_torrent const* tor, tr_stat const* st, double const uploadSpeed_KBps,
double const downloadSpeed_KBps)
{
if (st->error)
{
const char* fmt[] =
char const* fmt[] =
{
NULL,
N_("Tracker gave a warning: \"%s\""),
@ -327,10 +327,10 @@ struct TorrentCellRendererPrivate
****
***/
static GdkPixbuf* get_icon(const tr_torrent* tor, GtkIconSize icon_size, GtkWidget* for_widget)
static GdkPixbuf* get_icon(tr_torrent const* tor, GtkIconSize icon_size, GtkWidget* for_widget)
{
const char* mime_type;
const tr_info* info = tr_torrentInfo(tor);
char const* mime_type;
tr_info const* info = tr_torrentInfo(tor);
if (info->fileCount == 0)
{
@ -368,12 +368,12 @@ static void get_size_compact(TorrentCellRenderer* cell, GtkWidget* widget, gint*
GtkRequisition icon_size;
GtkRequisition name_size;
GtkRequisition stat_size;
const char* name;
char const* name;
GdkPixbuf* icon;
struct TorrentCellRendererPrivate* p = cell->priv;
const tr_torrent* tor = p->tor;
const tr_stat* st = tr_torrentStatCached((tr_torrent*)tor);
tr_torrent const* tor = p->tor;
tr_stat const* st = tr_torrentStatCached((tr_torrent*)tor);
GString* gstr_stat = p->gstr1;
icon = get_icon(tor, COMPACT_ICON_SIZE, widget);
@ -419,13 +419,13 @@ static void get_size_full(TorrentCellRenderer* cell, GtkWidget* widget, gint* wi
GtkRequisition name_size;
GtkRequisition stat_size;
GtkRequisition prog_size;
const char* name;
char const* name;
GdkPixbuf* icon;
struct TorrentCellRendererPrivate* p = cell->priv;
const tr_torrent* tor = p->tor;
const tr_stat* st = tr_torrentStatCached((tr_torrent*)tor);
const tr_info* inf = tr_torrentInfo(tor);
tr_torrent const* tor = p->tor;
tr_stat const* st = tr_torrentStatCached((tr_torrent*)tor);
tr_info const* inf = tr_torrentInfo(tor);
GString* gstr_prog = p->gstr1;
GString* gstr_stat = p->gstr2;
@ -466,7 +466,7 @@ static void get_size_full(TorrentCellRenderer* cell, GtkWidget* widget, gint* wi
g_object_unref(icon);
}
static void torrent_cell_renderer_get_size(GtkCellRenderer* cell, GtkWidget* widget, const GdkRectangle* cell_area,
static void torrent_cell_renderer_get_size(GtkCellRenderer* cell, GtkWidget* widget, GdkRectangle const* cell_area,
gint* x_offset, gint* y_offset, gint* width, gint* height)
{
TorrentCellRenderer* self = TORRENT_CELL_RENDERER(cell);
@ -512,9 +512,9 @@ static void torrent_cell_renderer_get_size(GtkCellRenderer* cell, GtkWidget* wid
typedef GdkRGBA GtrColor;
#define FOREGROUND_COLOR_KEY "foreground-rgba"
static void get_text_color(GtkWidget* w, const tr_stat* st, GtrColor* setme)
static void get_text_color(GtkWidget* w, tr_stat const* st, GtrColor* setme)
{
static const GdkRGBA red = { 1.0, 0, 0, 0 };
static GdkRGBA const red = { 1.0, 0, 0, 0 };
if (st->error)
{
@ -531,7 +531,7 @@ static void get_text_color(GtkWidget* w, const tr_stat* st, GtrColor* setme)
}
static double get_percent_done(const tr_torrent* tor, const tr_stat* st, bool* seed)
static double get_percent_done(tr_torrent const* tor, tr_stat const* st, bool* seed)
{
double d;
@ -552,13 +552,13 @@ static double get_percent_done(const tr_torrent* tor, const tr_stat* st, bool* s
typedef cairo_t GtrDrawable;
static void gtr_cell_renderer_render(GtkCellRenderer* renderer, GtrDrawable* drawable, GtkWidget* widget,
const GdkRectangle* area, GtkCellRendererState flags)
GdkRectangle const* area, GtkCellRendererState flags)
{
gtk_cell_renderer_render(renderer, drawable, widget, area, area, flags);
}
static void render_compact(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidget* widget,
const GdkRectangle* background_area, const GdkRectangle* cell_area UNUSED, GtkCellRendererState flags)
GdkRectangle const* background_area, GdkRectangle const* cell_area UNUSED, GtkCellRendererState flags)
{
int xpad, ypad;
GtkRequisition size;
@ -567,18 +567,18 @@ static void render_compact(TorrentCellRenderer* cell, GtrDrawable* window, GtkWi
GdkRectangle stat_area;
GdkRectangle prog_area;
GdkRectangle fill_area;
const char* name;
char const* name;
GdkPixbuf* icon;
GtrColor text_color;
bool seed;
struct TorrentCellRendererPrivate* p = cell->priv;
const tr_torrent* tor = p->tor;
const tr_stat* st = tr_torrentStatCached((tr_torrent*)tor);
const gboolean active = (st->activity != TR_STATUS_STOPPED) && (st->activity != TR_STATUS_DOWNLOAD_WAIT) &&
tr_torrent const* tor = p->tor;
tr_stat const* st = tr_torrentStatCached((tr_torrent*)tor);
gboolean const active = (st->activity != TR_STATUS_STOPPED) && (st->activity != TR_STATUS_DOWNLOAD_WAIT) &&
(st->activity != TR_STATUS_SEED_WAIT);
const double percentDone = get_percent_done(tor, st, &seed);
const gboolean sensitive = active || st->error;
double const percentDone = get_percent_done(tor, st, &seed);
gboolean const sensitive = active || st->error;
GString* gstr_stat = p->gstr1;
icon = get_icon(tor, COMPACT_ICON_SIZE, widget);
@ -631,8 +631,8 @@ static void render_compact(TorrentCellRenderer* cell, GtrDrawable* window, GtkWi
g_object_unref(icon);
}
static void render_full(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidget* widget, const GdkRectangle* background_area,
const GdkRectangle* cell_area UNUSED, GtkCellRendererState flags)
static void render_full(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidget* widget, GdkRectangle const* background_area,
GdkRectangle const* cell_area UNUSED, GtkCellRendererState flags)
{
int xpad, ypad;
GtkRequisition size;
@ -642,19 +642,19 @@ static void render_full(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidge
GdkRectangle stat_area;
GdkRectangle prog_area;
GdkRectangle prct_area;
const char* name;
char const* name;
GdkPixbuf* icon;
GtrColor text_color;
bool seed;
struct TorrentCellRendererPrivate* p = cell->priv;
const tr_torrent* tor = p->tor;
const tr_stat* st = tr_torrentStatCached((tr_torrent*)tor);
const tr_info* inf = tr_torrentInfo(tor);
const gboolean active = (st->activity != TR_STATUS_STOPPED) && (st->activity != TR_STATUS_DOWNLOAD_WAIT) &&
tr_torrent const* tor = p->tor;
tr_stat const* st = tr_torrentStatCached((tr_torrent*)tor);
tr_info const* inf = tr_torrentInfo(tor);
gboolean const active = (st->activity != TR_STATUS_STOPPED) && (st->activity != TR_STATUS_DOWNLOAD_WAIT) &&
(st->activity != TR_STATUS_SEED_WAIT);
const double percentDone = get_percent_done(tor, st, &seed);
const gboolean sensitive = active || st->error;
double const percentDone = get_percent_done(tor, st, &seed);
gboolean const sensitive = active || st->error;
GString* gstr_prog = p->gstr1;
GString* gstr_stat = p->gstr2;
@ -742,7 +742,7 @@ static void render_full(TorrentCellRenderer* cell, GtrDrawable* window, GtkWidge
}
static void torrent_cell_renderer_render(GtkCellRenderer* cell, GtrDrawable* window, GtkWidget* widget,
const GdkRectangle* background_area, const GdkRectangle* cell_area, GtkCellRendererState flags)
GdkRectangle const* background_area, GdkRectangle const* cell_area, GtkCellRendererState flags)
{
TorrentCellRenderer* self = TORRENT_CELL_RENDERER(cell);
@ -770,7 +770,7 @@ static void torrent_cell_renderer_render(GtkCellRenderer* cell, GtrDrawable* win
#endif
}
static void torrent_cell_renderer_set_property(GObject* object, guint property_id, const GValue* v, GParamSpec* pspec)
static void torrent_cell_renderer_set_property(GObject* object, guint property_id, GValue const* v, GParamSpec* pspec)
{
TorrentCellRenderer* self = TORRENT_CELL_RENDERER(object);
struct TorrentCellRendererPrivate* p = self->priv;
@ -805,7 +805,7 @@ static void torrent_cell_renderer_set_property(GObject* object, guint property_i
static void torrent_cell_renderer_get_property(GObject* object, guint property_id, GValue* v, GParamSpec* pspec)
{
const TorrentCellRenderer* self = TORRENT_CELL_RENDERER(object);
TorrentCellRenderer const* self = TORRENT_CELL_RENDERER(object);
struct TorrentCellRendererPrivate* p = self->priv;
switch (property_id)

View File

@ -82,7 +82,7 @@ struct TrCorePrivate
GStringChunk* string_chunk;
};
static int core_is_disposed(const TrCore* core)
static int core_is_disposed(TrCore const* core)
{
return !core || !core->priv->sorted_model;
}
@ -195,7 +195,7 @@ static inline void core_emit_port_tested(TrCore* core, gboolean is_open)
g_signal_emit(core, signals[PORT_SIGNAL], 0, is_open);
}
static inline void core_emit_err(TrCore* core, enum tr_core_err type, const char* msg)
static inline void core_emit_err(TrCore* core, enum tr_core_err type, char const* msg)
{
g_signal_emit(core, signals[ADD_ERROR_SIGNAL], 0, type, msg);
}
@ -205,7 +205,7 @@ static inline void core_emit_busy(TrCore* core, gboolean is_busy)
g_signal_emit(core, signals[BUSY_SIGNAL], 0, is_busy);
}
void gtr_core_pref_changed(TrCore* core, const tr_quark key)
void gtr_core_pref_changed(TrCore* core, tr_quark const key)
{
g_signal_emit(core, signals[PREFS_SIGNAL], 0, key);
}
@ -240,7 +240,7 @@ static bool core_is_busy(TrCore* core)
static void core_add_to_busy(TrCore* core, int addMe)
{
const bool wasBusy = core_is_busy(core);
bool const wasBusy = core_is_busy(core);
core->priv->busy_count += addMe;
@ -274,8 +274,8 @@ static int compare_eta(int a, int b)
{
int ret;
const gboolean a_valid = is_valid_eta(a);
const gboolean b_valid = is_valid_eta(b);
gboolean const a_valid = is_valid_eta(a);
gboolean const b_valid = is_valid_eta(b);
if (!a_valid && !b_valid)
{
@ -403,7 +403,7 @@ static int compare_time(time_t a, time_t b)
static int compare_by_name(GtkTreeModel* m, GtkTreeIter* a, GtkTreeIter* b, gpointer user_data UNUSED)
{
const char* ca, *cb;
char const* ca, *cb;
gtk_tree_model_get(m, a, MC_NAME_COLLATED, &ca, -1);
gtk_tree_model_get(m, b, MC_NAME_COLLATED, &cb, -1);
return g_strcmp0(ca, cb);
@ -412,7 +412,7 @@ static int compare_by_name(GtkTreeModel* m, GtkTreeIter* a, GtkTreeIter* b, gpoi
static int compare_by_queue(GtkTreeModel* m, GtkTreeIter* a, GtkTreeIter* b, gpointer user_data UNUSED)
{
tr_torrent* ta, *tb;
const tr_stat* sa, *sb;
tr_stat const* sa, *sb;
gtk_tree_model_get(m, a, MC_TORRENT, &ta, -1);
sa = tr_torrentStatCached(ta);
@ -426,7 +426,7 @@ static int compare_by_ratio(GtkTreeModel* m, GtkTreeIter* a, GtkTreeIter* b, gpo
{
int ret = 0;
tr_torrent* ta, *tb;
const tr_stat* sa, *sb;
tr_stat const* sa, *sb;
gtk_tree_model_get(m, a, MC_TORRENT, &ta, -1);
sa = tr_torrentStatCached(ta);
@ -459,8 +459,8 @@ static int compare_by_activity(GtkTreeModel* m, GtkTreeIter* a, GtkTreeIter* b,
if (!ret)
{
const tr_stat* const sa = tr_torrentStatCached(ta);
const tr_stat* const sb = tr_torrentStatCached(tb);
tr_stat const* const sa = tr_torrentStatCached(ta);
tr_stat const* const sb = tr_torrentStatCached(tb);
ret = compare_uint64(sa->peersSendingToUs + sa->peersGettingFromUs, sb->peersSendingToUs + sb->peersGettingFromUs);
}
@ -497,7 +497,7 @@ static int compare_by_size(GtkTreeModel* m, GtkTreeIter* a, GtkTreeIter* b, gpoi
{
int ret = 0;
tr_torrent* t;
const tr_info* ia, *ib;
tr_info const* ia, *ib;
gtk_tree_model_get(m, a, MC_TORRENT, &t, -1);
ia = tr_torrentInfo(t);
@ -521,7 +521,7 @@ static int compare_by_progress(GtkTreeModel* m, GtkTreeIter* a, GtkTreeIter* b,
{
int ret = 0;
tr_torrent* t;
const tr_stat* sa, *sb;
tr_stat const* sa, *sb;
gtk_tree_model_get(m, a, MC_TORRENT, &t, -1);
sa = tr_torrentStatCached(t);
@ -589,9 +589,9 @@ static int compare_by_state(GtkTreeModel* m, GtkTreeIter* a, GtkTreeIter* b, gpo
return ret;
}
static void core_set_sort_mode(TrCore* core, const char* mode, gboolean is_reversed)
static void core_set_sort_mode(TrCore* core, char const* mode, gboolean is_reversed)
{
const int col = MC_TORRENT;
int const col = MC_TORRENT;
GtkTreeIterCompareFunc sort_func;
GtkSortType type = is_reversed ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING;
GtkTreeSortable* sortable = GTK_TREE_SORTABLE(gtr_core_model(core));
@ -669,7 +669,7 @@ static void rename_torrent_and_unref_file(GFile* file)
if (info != NULL)
{
GError* error = NULL;
const char* old_name;
char const* old_name;
char* new_name;
GFile* new_file;
@ -701,14 +701,14 @@ static gboolean core_watchdir_idle(gpointer gcore)
GSList* changing = NULL;
GSList* unchanging = NULL;
TrCore* core = TR_CORE(gcore);
const time_t now = tr_time();
time_t const now = tr_time();
struct TrCorePrivate* p = core->priv;
/* separate the files into two lists: changing and unchanging */
for (l = p->monitor_files; l != NULL; l = l->next)
{
GFile* file = l->data;
const time_t mtime = get_file_mtime(file);
time_t const mtime = get_file_mtime(file);
if (mtime + 2 >= now)
{
@ -723,8 +723,8 @@ static gboolean core_watchdir_idle(gpointer gcore)
/* add the files that have stopped changing */
if (unchanging != NULL)
{
const gboolean do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
const gboolean do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
gboolean const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
gboolean const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
core->priv->adding_from_watch_dir = TRUE;
gtr_core_add_files(core, unchanging, do_start, do_prompt, TRUE);
@ -751,7 +751,7 @@ static gboolean core_watchdir_idle(gpointer gcore)
static void core_watchdir_monitor_file(TrCore* core, GFile* file)
{
char* filename = g_file_get_path(file);
const gboolean is_torrent = g_str_has_suffix(filename, ".torrent");
gboolean const is_torrent = g_str_has_suffix(filename, ".torrent");
if (is_torrent)
{
@ -795,12 +795,12 @@ static void on_file_changed_in_watchdir(GFileMonitor* monitor UNUSED, GFile* fil
/* walk through the pre-existing files in the watchdir */
static void core_watchdir_scan(TrCore* core)
{
const char* dirname = gtr_pref_string_get(TR_KEY_watch_dir);
char const* dirname = gtr_pref_string_get(TR_KEY_watch_dir);
GDir* dir = g_dir_open(dirname, 0, NULL);
if (dir != NULL)
{
const char* name;
char const* name;
while ((name = g_dir_read_name(dir)))
{
@ -817,7 +817,7 @@ static void core_watchdir_scan(TrCore* core)
static void core_watchdir_update(TrCore* core)
{
const gboolean is_enabled = gtr_pref_flag_get(TR_KEY_watch_dir_enabled);
gboolean const is_enabled = gtr_pref_flag_get(TR_KEY_watch_dir_enabled);
GFile* dir = g_file_new_for_path(gtr_pref_string_get(TR_KEY_watch_dir));
struct TrCorePrivate* p = core->priv;
@ -851,15 +851,15 @@ static void core_watchdir_update(TrCore* core)
****
***/
static void on_pref_changed(TrCore* core, const tr_quark key, gpointer data UNUSED)
static void on_pref_changed(TrCore* core, tr_quark const key, gpointer data UNUSED)
{
switch (key)
{
case TR_KEY_sort_mode:
case TR_KEY_sort_reversed:
{
const char* mode = gtr_pref_string_get(TR_KEY_sort_mode);
const gboolean is_reversed = gtr_pref_flag_get(TR_KEY_sort_reversed);
char const* mode = gtr_pref_string_get(TR_KEY_sort_mode);
gboolean const is_reversed = gtr_pref_flag_get(TR_KEY_sort_reversed);
core_set_sort_mode(core, mode, is_reversed);
break;
}
@ -957,12 +957,12 @@ static void on_torrent_completeness_changed(tr_torrent* tor, tr_completeness com
**** METADATA CALLBACK
***/
static const char* get_collated_name(TrCore* core, const tr_torrent* tor)
static char const* get_collated_name(TrCore* core, tr_torrent const* tor)
{
char buf[2048];
const char* name = tr_torrentName(tor);
char const* name = tr_torrentName(tor);
char* down = g_utf8_strdown(name ? name : "", -1);
const tr_info* inf = tr_torrentInfo(tor);
tr_info const* inf = tr_torrentInfo(tor);
g_snprintf(buf, sizeof(buf), "%s\t%s", down, inf->hashString);
g_free(down);
return g_string_chunk_insert_const(core->priv->string_chunk, buf);
@ -1012,7 +1012,7 @@ static gboolean on_torrent_metadata_changed_idle(gpointer gdata)
if (find_row_from_torrent_id(model, data->torrent_id, &iter))
{
const char* collated = get_collated_name(data->core, tor);
char const* collated = get_collated_name(data->core, tor);
GtkListStore* store = GTK_LIST_STORE(model);
gtk_list_store_set(store, &iter, MC_NAME_COLLATED, collated, -1);
}
@ -1044,9 +1044,9 @@ static void on_torrent_metadata_changed(tr_torrent* tor, void* gcore)
static unsigned int build_torrent_trackers_hash(tr_torrent* tor)
{
unsigned int i;
const char* pch;
char const* pch;
uint64_t hash = 0;
const tr_info* const inf = tr_torrentInfo(tor);
tr_info const* const inf = tr_torrentInfo(tor);
for (i = 0; i < inf->trackerCount; ++i)
{
@ -1060,7 +1060,7 @@ static unsigned int build_torrent_trackers_hash(tr_torrent* tor)
}
static gboolean
is_torrent_active(const tr_stat* st)
is_torrent_active(tr_stat const* st)
{
return (st->peersSendingToUs > 0) || (st->peersGettingFromUs > 0) || (st->activity == TR_STATUS_CHECK);
}
@ -1070,9 +1070,9 @@ void gtr_core_add_torrent(TrCore* core, tr_torrent* tor, gboolean do_notify)
if (tor != NULL)
{
GtkTreeIter unused;
const tr_stat* st = tr_torrentStat(tor);
const char* collated = get_collated_name(core, tor);
const unsigned int trackers_hash = build_torrent_trackers_hash(tor);
tr_stat const* st = tr_torrentStat(tor);
char const* collated = get_collated_name(core, tor);
unsigned int const trackers_hash = build_torrent_trackers_hash(tor);
GtkListStore* store = GTK_LIST_STORE(core_raw_model(core));
gtk_list_store_insert_with_values(store, &unused, 0,
@ -1116,13 +1116,13 @@ static tr_torrent* core_create_new_torrent(TrCore* core, tr_ctor* ctor)
if (tor && do_trash)
{
const char* config = tr_sessionGetConfigDir(session);
const char* source = tr_ctorGetSourceFile(ctor);
char const* config = tr_sessionGetConfigDir(session);
char const* source = tr_ctorGetSourceFile(ctor);
if (source != NULL)
{
/* #1294: don't delete the .torrent file if it's our internal copy */
const int is_internal = (strstr(source, config) == source);
int const is_internal = (strstr(source, config) == source);
if (!is_internal)
{
@ -1201,8 +1201,8 @@ static void core_apply_defaults(tr_ctor* ctor)
void gtr_core_add_ctor(TrCore* core, tr_ctor* ctor)
{
const gboolean do_notify = FALSE;
const gboolean do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
gboolean const do_notify = FALSE;
gboolean const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
core_apply_defaults(ctor);
core_add_ctor(core, ctor, do_prompt, do_notify);
}
@ -1231,7 +1231,7 @@ static void add_file_async_callback(GObject* file, GAsyncResult* result, gpointe
g_message(_("Couldn't read \"%s\": %s"), g_file_get_parse_name(G_FILE(file)), error->message);
g_error_free(error);
}
else if (!tr_ctorSetMetainfo(data->ctor, (const uint8_t*)contents, length))
else if (!tr_ctorSetMetainfo(data->ctor, (uint8_t const*)contents, length))
{
core_add_ctor(data->core, data->ctor, data->do_prompt, data->do_notify);
}
@ -1330,12 +1330,12 @@ static bool add_file(TrCore* core, GFile* file, gboolean do_start, gboolean do_p
return handled;
}
bool gtr_core_add_from_url(TrCore* core, const char* uri)
bool gtr_core_add_from_url(TrCore* core, char const* uri)
{
bool handled;
const bool do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
const bool do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
const bool do_notify = false;
bool const do_start = gtr_pref_flag_get(TR_KEY_start_added_torrents);
bool const do_prompt = gtr_pref_flag_get(TR_KEY_show_options_window);
bool const do_notify = false;
GFile* file = g_file_new_for_uri(uri);
handled = add_file(core, file, do_start, do_prompt, do_notify);
@ -1431,11 +1431,11 @@ void gtr_core_clear(TrCore* self)
****
***/
static int gtr_compare_double(const double a, const double b, int decimal_places)
static int gtr_compare_double(double const a, double const b, int decimal_places)
{
int ret;
const int64_t ia = (int64_t)(a * pow(10, decimal_places));
const int64_t ib = (int64_t)(b * pow(10, decimal_places));
int64_t const ia = (int64_t)(a * pow(10, decimal_places));
int64_t const ib = (int64_t)(b * pow(10, decimal_places));
if (ia < ib)
{
@ -1468,7 +1468,7 @@ static void update_foreach(GtkTreeModel* model, GtkTreeIter* iter)
double oldDownSpeed, newDownSpeed;
double oldRecheckProgress, newRecheckProgress;
gboolean oldActive, newActive;
const tr_stat* st;
tr_stat const* st;
tr_torrent* tor;
/* get the old states */
@ -1566,10 +1566,10 @@ static gboolean gtr_inhibit_hibernation(guint* cookie)
GVariant* response;
GDBusConnection* connection;
GError* err = NULL;
const char* application = "Transmission BitTorrent Client";
const char* reason = "BitTorrent Activity";
const int toplevel_xid = 0;
const int flags = 4; /* Inhibit suspending the session or computer */
char const* application = "Transmission BitTorrent Client";
char const* reason = "BitTorrent Activity";
int const toplevel_xid = 0;
int const flags = 4; /* Inhibit suspending the session or computer */
connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &err);
@ -1667,7 +1667,7 @@ static void core_maybe_inhibit_hibernation(TrCore* core)
/* hibernation is allowed if EITHER
* (a) the "inhibit" pref is turned off OR
* (b) there aren't any active torrents */
const gboolean hibernation_allowed = !gtr_pref_flag_get(TR_KEY_inhibit_desktop_hibernation) ||
gboolean const hibernation_allowed = !gtr_pref_flag_get(TR_KEY_inhibit_desktop_hibernation) ||
!gtr_core_get_active_torrent_count(core);
gtr_core_set_hibernation_allowed(core, hibernation_allowed);
}
@ -1676,13 +1676,13 @@ static void core_maybe_inhibit_hibernation(TrCore* core)
*** Prefs
**/
static void core_commit_prefs_change(TrCore* core, const tr_quark key)
static void core_commit_prefs_change(TrCore* core, tr_quark const key)
{
gtr_core_pref_changed(core, key);
gtr_pref_save(gtr_core_session(core));
}
void gtr_core_set_pref(TrCore* self, const tr_quark key, const char* newval)
void gtr_core_set_pref(TrCore* self, tr_quark const key, char const* newval)
{
if (g_strcmp0(newval, gtr_pref_string_get(key)) != 0)
{
@ -1691,7 +1691,7 @@ void gtr_core_set_pref(TrCore* self, const tr_quark key, const char* newval)
}
}
void gtr_core_set_pref_bool(TrCore* self, const tr_quark key, gboolean newval)
void gtr_core_set_pref_bool(TrCore* self, tr_quark const key, gboolean newval)
{
if (newval != gtr_pref_flag_get(key))
{
@ -1700,7 +1700,7 @@ void gtr_core_set_pref_bool(TrCore* self, const tr_quark key, gboolean newval)
}
}
void gtr_core_set_pref_int(TrCore* self, const tr_quark key, int newval)
void gtr_core_set_pref_int(TrCore* self, tr_quark const key, int newval)
{
if (newval != gtr_pref_int_get(key))
{
@ -1709,7 +1709,7 @@ void gtr_core_set_pref_int(TrCore* self, const tr_quark key, int newval)
}
}
void gtr_core_set_pref_double(TrCore* self, const tr_quark key, double newval)
void gtr_core_set_pref_double(TrCore* self, tr_quark const key, double newval)
{
if (gtr_compare_double(newval, gtr_pref_double_get(key), 4))
{
@ -1746,7 +1746,7 @@ static gboolean core_read_rpc_response_idle(void* vresponse)
if (tr_variantDictFindInt(response, TR_KEY_tag, &intVal))
{
const int tag = (int)intVal;
int const tag = (int)intVal;
struct pending_request_data* data = g_hash_table_lookup(pendingRequests, &tag);
if (data)
@ -1775,7 +1775,7 @@ static void core_read_rpc_response(tr_session* session UNUSED, tr_variant* respo
gdk_threads_add_idle(core_read_rpc_response_idle, response_copy);
}
static void core_send_rpc_request(TrCore* core, const tr_variant* request, int tag, server_response_func* response_func,
static void core_send_rpc_request(TrCore* core, tr_variant const* request, int tag, server_response_func* response_func,
void* response_func_user_data)
{
tr_session* session = gtr_core_session(core);
@ -1803,7 +1803,7 @@ static void core_send_rpc_request(TrCore* core, const tr_variant* request, int t
#ifdef DEBUG_RPC
{
struct evbuffer* buf = tr_variantToBuf(request, TR_VARIANT_FMT_JSON_LEAN);
const size_t buf_len = evbuffer_get_length(buf);
size_t const buf_len = evbuffer_get_length(buf);
g_message("request: [%*.*s]", (int) buf_len, (int) buf_len, evbuffer_pullup(buf, -1));
evbuffer_free(buf);
}
@ -1833,7 +1833,7 @@ static void on_port_test_response(TrCore* core, tr_variant* response, gpointer u
void gtr_core_port_test(TrCore* core)
{
const int tag = nextTag++;
int const tag = nextTag++;
tr_variant request;
tr_variantInitDict(&request, 2);
@ -1868,7 +1868,7 @@ static void on_blocklist_response(TrCore* core, tr_variant* response, gpointer d
void gtr_core_blocklist_update(TrCore* core)
{
const int tag = nextTag++;
int const tag = nextTag++;
tr_variant request;
tr_variantInitDict(&request, 2);
@ -1882,9 +1882,9 @@ void gtr_core_blocklist_update(TrCore* core)
****
***/
void gtr_core_exec(TrCore* core, const tr_variant* top)
void gtr_core_exec(TrCore* core, tr_variant const* top)
{
const int tag = nextTag++;
int const tag = nextTag++;
core_send_rpc_request(core, top, tag, NULL, NULL);
}
@ -1936,12 +1936,12 @@ tr_torrent* gtr_core_find_torrent(TrCore* core, int id)
void gtr_core_open_folder(TrCore* core, int torrent_id)
{
const tr_torrent* tor = gtr_core_find_torrent(core, torrent_id);
tr_torrent const* tor = gtr_core_find_torrent(core, torrent_id);
if (tor != NULL)
{
const gboolean single = tr_torrentInfo(tor)->fileCount == 1;
const char* currentDir = tr_torrentGetCurrentDir(tor);
gboolean const single = tr_torrentInfo(tor)->fileCount == 1;
char const* currentDir = tr_torrentGetCurrentDir(tor);
if (single)
{

View File

@ -30,7 +30,7 @@
G_BEGIN_DECLS
#define TR_CORE_TYPE (tr_core_get_type())
#define TR_CORE(o)(G_TYPE_CHECK_INSTANCE_CAST((o), TR_CORE_TYPE, TrCore))
#define TR_CORE(o) (G_TYPE_CHECK_INSTANCE_CAST((o), TR_CORE_TYPE, TrCore))
#define TR_RESOURCE_PATH "/com/transmissionbt/transmission/"
@ -54,11 +54,11 @@ typedef struct _TrCoreClass
{
GObjectClass parent_class;
void (*add_error)(TrCore*, enum tr_core_err, const char* name);
void (*add_error)(TrCore*, enum tr_core_err, char const* name);
void (*add_prompt)(TrCore*, gpointer ctor);
void (*blocklist_updated)(TrCore*, int ruleCount);
void (*busy)(TrCore*, gboolean is_busy);
void (*prefs_changed)(TrCore*, const tr_quark key);
void (*prefs_changed)(TrCore*, tr_quark const key);
void (*port_tested)(TrCore*, gboolean is_open);
void (*quit)(TrCore*);
}
@ -83,7 +83,7 @@ size_t gtr_core_get_torrent_count(TrCore* self);
tr_torrent* gtr_core_find_torrent(TrCore* core, int id);
void gtr_core_pref_changed(TrCore* core, const tr_quark key);
void gtr_core_pref_changed(TrCore* core, tr_quark const key);
/******
@ -106,7 +106,7 @@ void gtr_core_load(TrCore* self, gboolean forcepaused);
void gtr_core_add_files(TrCore* core, GSList* files, gboolean do_start, gboolean do_prompt, gboolean do_notify);
/** @brief Add a torrent from a URL */
bool gtr_core_add_from_url(TrCore* core, const char* url);
bool gtr_core_add_from_url(TrCore* core, char const* url);
/** @brief Add a torrent.
@param ctor this function assumes ownership of the ctor */
@ -137,10 +137,10 @@ void gtr_core_update(TrCore* self);
*** Set a preference value, save the prefs file, and emit the "prefs-changed" signal
**/
void gtr_core_set_pref(TrCore* self, const tr_quark key, const char* val);
void gtr_core_set_pref_bool(TrCore* self, const tr_quark key, gboolean val);
void gtr_core_set_pref_int(TrCore* self, const tr_quark key, int val);
void gtr_core_set_pref_double(TrCore* self, const tr_quark key, double val);
void gtr_core_set_pref(TrCore* self, tr_quark const key, char const* val);
void gtr_core_set_pref_bool(TrCore* self, tr_quark const key, gboolean val);
void gtr_core_set_pref_int(TrCore* self, tr_quark const key, int val);
void gtr_core_set_pref_double(TrCore* self, tr_quark const key, double val);
/**
***
@ -150,7 +150,7 @@ void gtr_core_port_test(TrCore* core);
void gtr_core_blocklist_update(TrCore* core);
void gtr_core_exec(TrCore* core, const tr_variant* benc);
void gtr_core_exec(TrCore* core, tr_variant const* benc);
void gtr_core_open_folder(TrCore* core, int torrent_id);

View File

@ -10,7 +10,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#ifdef HAVE_LIBAPPINDICATOR
#include <libappindicator/app-indicator.h>
#include <libappindicator/app-indicator.h>
#endif
#include <libtransmission/transmission.h>
#include <libtransmission/utils.h>
@ -51,7 +51,7 @@ void gtr_icon_refresh(gpointer vicon)
char down[64];
char downLimit[64];
char tip[1024];
const char* idle = _("Idle");
char const* idle = _("Idle");
GtkStatusIcon* icon = GTK_STATUS_ICON(vicon);
tr_session* session = gtr_core_session(g_object_get_qdata(G_OBJECT(icon), core_quark()));
@ -110,9 +110,9 @@ void gtr_icon_refresh(gpointer vicon)
#endif
static const char* getIconName(void)
static char const* getIconName(void)
{
const char* icon_name;
char const* icon_name;
GtkIconTheme* theme = gtk_icon_theme_get_default();
@ -125,7 +125,7 @@ static const char* getIconName(void)
else
{
GtkIconInfo* icon_info = gtk_icon_theme_lookup_icon(theme, TRAY_ICON, 48, GTK_ICON_LOOKUP_USE_BUILTIN);
const gboolean icon_is_builtin = gtk_icon_info_get_filename(icon_info) == NULL;
gboolean const icon_is_builtin = gtk_icon_info_get_filename(icon_info) == NULL;
#if GTK_CHECK_VERSION(3, 8, 0)
g_object_unref(icon_info);
@ -144,7 +144,7 @@ gpointer gtr_icon_new(TrCore* core)
#ifdef HAVE_LIBAPPINDICATOR
GtkWidget* w;
const char* icon_name = getIconName();
char const* icon_name = getIconName();
AppIndicator* indicator = app_indicator_new(ICON_NAME, icon_name, APP_INDICATOR_CATEGORY_SYSTEM_SERVICES);
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
w = gtr_action_get_widget("/icon-popup");
@ -155,7 +155,7 @@ gpointer gtr_icon_new(TrCore* core)
#else
const char* icon_name = getIconName();
char const* icon_name = getIconName();
GtkStatusIcon* icon = gtk_status_icon_new_from_icon_name(icon_name);
g_signal_connect(icon, "activate", G_CALLBACK(activated), NULL);
g_signal_connect(icon, "popup-menu", G_CALLBACK(popup), NULL);

View File

@ -60,13 +60,13 @@ static void response_cb(GtkDialog* dialog, int response, gpointer unused UNUSED)
static void toggled_cb(GtkToggleButton* w, gpointer core)
{
const tr_quark key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), PREF_KEY));
const gboolean flag = gtk_toggle_button_get_active(w);
tr_quark const key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), PREF_KEY));
gboolean const flag = gtk_toggle_button_get_active(w);
gtr_core_set_pref_bool(TR_CORE(core), key, flag);
}
static GtkWidget* new_check_button(const char* mnemonic, const tr_quark key, gpointer core)
static GtkWidget* new_check_button(char const* mnemonic, tr_quark const key, gpointer core)
{
GtkWidget* w = gtk_check_button_new_with_mnemonic(mnemonic);
g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
@ -102,16 +102,16 @@ static gboolean spun_cb_idle(gpointer spin)
if (g_timer_elapsed(data->last_change, NULL) > 0.33f)
{
/* update the core */
const tr_quark key = GPOINTER_TO_INT(g_object_get_data(o, PREF_KEY));
tr_quark const key = GPOINTER_TO_INT(g_object_get_data(o, PREF_KEY));
if (data->isDouble)
{
const double value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
double const value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
gtr_core_set_pref_double(TR_CORE(data->core), key, value);
}
else
{
const int value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
int const value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
gtr_core_set_pref_int(TR_CORE(data->core), key, value);
}
@ -155,7 +155,7 @@ static void spun_cb_double(GtkSpinButton* w, gpointer core)
spun_cb(w, core, TRUE);
}
static GtkWidget* new_spin_button(const tr_quark key, gpointer core, int low, int high, int step)
static GtkWidget* new_spin_button(tr_quark const key, gpointer core, int low, int high, int step)
{
GtkWidget* w = gtk_spin_button_new_with_range(low, high, step);
g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
@ -165,7 +165,7 @@ static GtkWidget* new_spin_button(const tr_quark key, gpointer core, int low, i
return w;
}
static GtkWidget* new_spin_button_double(const tr_quark key, gpointer core, double low, double high, double step)
static GtkWidget* new_spin_button_double(tr_quark const key, gpointer core, double low, double high, double step)
{
GtkWidget* w = gtk_spin_button_new_with_range(low, high, step);
g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
@ -177,16 +177,16 @@ static GtkWidget* new_spin_button_double(const tr_quark key, gpointer core, dou
static void entry_changed_cb(GtkEntry* w, gpointer core)
{
const tr_quark key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), PREF_KEY));
const char* value = gtk_entry_get_text(w);
tr_quark const key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), PREF_KEY));
char const* value = gtk_entry_get_text(w);
gtr_core_set_pref(TR_CORE(core), key, value);
}
static GtkWidget* new_entry(const tr_quark key, gpointer core)
static GtkWidget* new_entry(tr_quark const key, gpointer core)
{
GtkWidget* w = gtk_entry_new();
const char* value = gtr_pref_string_get(key);
char const* value = gtr_pref_string_get(key);
if (value)
{
@ -200,16 +200,16 @@ static GtkWidget* new_entry(const tr_quark key, gpointer core)
static void chosen_cb(GtkFileChooser* w, gpointer core)
{
const tr_quark key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), PREF_KEY));
tr_quark const key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), PREF_KEY));
char* value = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(w));
gtr_core_set_pref(TR_CORE(core), key, value);
g_free(value);
}
static GtkWidget* new_path_chooser_button(const tr_quark key, gpointer core)
static GtkWidget* new_path_chooser_button(tr_quark const key, gpointer core)
{
GtkWidget* w = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
const char* path = gtr_pref_string_get(key);
GtkWidget* w = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
char const* path = gtr_pref_string_get(key);
g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
if (path != NULL)
@ -221,10 +221,10 @@ static GtkWidget* new_path_chooser_button(const tr_quark key, gpointer core)
return w;
}
static GtkWidget* new_file_chooser_button(const tr_quark key, gpointer core)
static GtkWidget* new_file_chooser_button(tr_quark const key, gpointer core)
{
GtkWidget* w = gtk_file_chooser_button_new(NULL, GTK_FILE_CHOOSER_ACTION_OPEN);
const char* path = gtr_pref_string_get(key);
char const* path = gtr_pref_string_get(key);
g_object_set_data(G_OBJECT(w), PREF_KEY, GINT_TO_POINTER(key));
if (path != NULL)
@ -238,7 +238,7 @@ static GtkWidget* new_file_chooser_button(const tr_quark key, gpointer core)
static void target_cb(GtkWidget* tb, gpointer target)
{
const gboolean b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tb));
gboolean const b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tb));
gtk_widget_set_sensitive(GTK_WIDGET(target), b);
}
@ -252,7 +252,7 @@ static GtkWidget* downloadingPage(GObject* core, struct prefs_dialog_data* data)
GtkWidget* t;
GtkWidget* w;
GtkWidget* l;
const char* s;
char const* s;
guint row = 0;
t = hig_workarea_create();
@ -328,7 +328,7 @@ static GtkWidget* seedingPage(GObject* core)
GtkWidget* t;
GtkWidget* w;
GtkWidget* w2;
const char* s;
char const* s;
guint row = 0;
t = hig_workarea_create();
@ -359,7 +359,7 @@ static GtkWidget* desktopPage(GObject* core)
{
GtkWidget* t;
GtkWidget* w;
const char* s;
char const* s;
guint row = 0;
t = hig_workarea_create();
@ -409,7 +409,7 @@ static void updateBlocklistText(GtkWidget* w, TrCore* core)
{
char buf1[512];
char buf2[512];
const int n = tr_blocklistGetRuleCount(gtr_core_session(core));
int const n = tr_blocklistGetRuleCount(gtr_core_session(core));
g_snprintf(buf1, sizeof(buf1), ngettext("Blocklist contains %'d rule", "Blocklist contains %'d rules", n), n);
g_snprintf(buf2, sizeof(buf2), "<i>%s</i>", buf1);
gtk_label_set_markup(GTK_LABEL(w), buf2);
@ -442,9 +442,9 @@ static void onBlocklistUpdateResponse(GtkDialog* dialog, gint response UNUSED, g
/* core says the blocklist was updated */
static void onBlocklistUpdated(TrCore* core, int n, gpointer gdata)
{
const bool success = n >= 0;
const int count = n >= 0 ? n : tr_blocklistGetRuleCount(gtr_core_session(core));
const char* s = ngettext("Blocklist has %'d rule.", "Blocklist has %'d rules.", count);
bool const success = n >= 0;
int const count = n >= 0 ? n : tr_blocklistGetRuleCount(gtr_core_session(core));
char const* s = ngettext("Blocklist has %'d rule.", "Blocklist has %'d rules.", count);
struct blocklist_data* data = gdata;
GtkMessageDialog* d = GTK_MESSAGE_DIALOG(data->updateBlocklistDialog);
gtk_widget_set_sensitive(data->updateBlocklistButton, TRUE);
@ -472,19 +472,19 @@ static void onBlocklistUpdate(GtkButton* w, gpointer gdata)
static void on_blocklist_url_changed(GtkEditable* e, gpointer gbutton)
{
gchar* url = gtk_editable_get_chars(e, 0, -1);
const gboolean is_url_valid = tr_urlParse(url, TR_BAD_SIZE, NULL, NULL, NULL, NULL);
gboolean const is_url_valid = tr_urlParse(url, TR_BAD_SIZE, NULL, NULL, NULL, NULL);
gtk_widget_set_sensitive(GTK_WIDGET(gbutton), is_url_valid);
g_free(url);
}
static void onIntComboChanged(GtkComboBox* combo_box, gpointer core)
{
const int val = gtr_combo_box_get_active_enum(combo_box);
const tr_quark key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(combo_box), PREF_KEY));
int const val = gtr_combo_box_get_active_enum(combo_box);
tr_quark const key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(combo_box), PREF_KEY));
gtr_core_set_pref_int(TR_CORE(core), key, val);
}
static GtkWidget* new_encryption_combo(GObject* core, const tr_quark key)
static GtkWidget* new_encryption_combo(GObject* core, tr_quark const key)
{
GtkWidget* w = gtr_combo_box_new_enum(_("Allow encryption"), TR_CLEAR_PREFERRED, _("Prefer encryption"),
TR_ENCRYPTION_PREFERRED, _("Require encryption"), TR_ENCRYPTION_REQUIRED, NULL);
@ -496,7 +496,7 @@ static GtkWidget* new_encryption_combo(GObject* core, const tr_quark key)
static GtkWidget* privacyPage(GObject* core)
{
const char* s;
char const* s;
GtkWidget* t;
GtkWidget* w;
GtkWidget* b;
@ -564,7 +564,7 @@ enum
N_COLS
};
static GtkTreeModel* whitelist_tree_model_new(const char* whitelist)
static GtkTreeModel* whitelist_tree_model_new(char const* whitelist)
{
int i;
char** rules;
@ -577,7 +577,7 @@ static GtkTreeModel* whitelist_tree_model_new(const char* whitelist)
for (i = 0; rules && rules[i]; ++i)
{
GtkTreeIter iter;
const char* s = rules[i];
char const* s = rules[i];
while (isspace(*s))
{
@ -678,12 +678,12 @@ static void onRemoveWhitelistClicked(GtkButton* b UNUSED, gpointer gpage)
static void refreshRPCSensitivity(struct remote_page* page)
{
GSList* l;
const int rpc_active = gtk_toggle_button_get_active(page->rpc_tb);
const int auth_active = gtk_toggle_button_get_active(page->auth_tb);
const int whitelist_active = gtk_toggle_button_get_active(page->whitelist_tb);
int const rpc_active = gtk_toggle_button_get_active(page->rpc_tb);
int const auth_active = gtk_toggle_button_get_active(page->auth_tb);
int const whitelist_active = gtk_toggle_button_get_active(page->whitelist_tb);
GtkTreeSelection* sel = gtk_tree_view_get_selection(page->view);
const int have_addr = gtk_tree_selection_get_selected(sel, NULL, NULL);
const int n_rules = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(page->store), NULL);
int const have_addr = gtk_tree_selection_get_selected(sel, NULL, NULL);
int const n_rules = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(page->store), NULL);
for (l = page->widgets; l != NULL; l = l->next)
{
@ -716,7 +716,7 @@ static void onWhitelistSelectionChanged(GtkTreeSelection* sel UNUSED, gpointer p
static void onLaunchClutchCB(GtkButton* w UNUSED, gpointer data UNUSED)
{
char* uri;
const int port = gtr_pref_int_get(TR_KEY_rpc_port);
int const port = gtr_pref_int_get(TR_KEY_rpc_port);
uri = g_strdup_printf("http://localhost:%d/", port);
gtr_open_uri(uri);
@ -738,7 +738,7 @@ static GtkWidget* remotePage(GObject* core)
GtkWidget* t;
GtkWidget* w;
GtkWidget* h;
const char* s;
char const* s;
guint row = 0;
struct remote_page* page = g_new0(struct remote_page, 1);
@ -801,7 +801,7 @@ static GtkWidget* remotePage(GObject* core)
/* access control list */
{
const char* val = gtr_pref_string_get(TR_KEY_rpc_whitelist);
char const* val = gtr_pref_string_get(TR_KEY_rpc_whitelist);
GtkTreeModel* m = whitelist_tree_model_new(val);
GtkTreeViewColumn* c;
GtkCellRenderer* r;
@ -874,7 +874,7 @@ struct BandwidthPage
static void refreshSchedSensitivity(struct BandwidthPage* p)
{
GSList* l;
const gboolean sched_enabled = gtr_pref_flag_get(TR_KEY_alt_speed_time_enabled);
gboolean const sched_enabled = gtr_pref_flag_get(TR_KEY_alt_speed_time_enabled);
for (l = p->sched_widgets; l != NULL; l = l->next)
{
@ -894,13 +894,13 @@ static void onTimeComboChanged(GtkComboBox* w, gpointer core)
if (gtk_combo_box_get_active_iter(w, &iter))
{
int val = 0;
const tr_quark key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), PREF_KEY));
tr_quark const key = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), PREF_KEY));
gtk_tree_model_get(gtk_combo_box_get_model(w), &iter, 0, &val, -1);
gtr_core_set_pref_int(TR_CORE(core), key, val);
}
}
static GtkWidget* new_time_combo(GObject* core, const tr_quark key)
static GtkWidget* new_time_combo(GObject* core, tr_quark const key)
{
int val;
int i;
@ -936,7 +936,7 @@ static GtkWidget* new_time_combo(GObject* core, const tr_quark key)
return w;
}
static GtkWidget* new_week_combo(GObject* core, const tr_quark key)
static GtkWidget* new_week_combo(GObject* core, tr_quark const key)
{
GtkWidget* w = gtr_combo_box_new_enum(
_("Every Day"), TR_SCHED_ALL,
@ -966,7 +966,7 @@ static void speedPageFree(gpointer gpage)
static GtkWidget* speedPage(GObject* core)
{
const char* s;
char const* s;
GtkWidget* t;
GtkWidget* l;
GtkWidget* w, * w2, * h;
@ -1061,7 +1061,7 @@ struct network_page_data
gulong prefsTag;
};
static void onCorePrefsChanged(TrCore* core UNUSED, const tr_quark key, gpointer gdata)
static void onCorePrefsChanged(TrCore* core UNUSED, tr_quark const key, gpointer gdata)
{
if (key == TR_KEY_peer_port)
{
@ -1092,7 +1092,7 @@ static void networkPageDestroyed(gpointer gdata, GObject* dead UNUSED)
static void onPortTested(TrCore* core UNUSED, gboolean isOpen, gpointer vdata)
{
struct network_page_data* data = vdata;
const char* markup = isOpen ? _("Port is <b>open</b>") : _("Port is <b>closed</b>");
char const* markup = isOpen ? _("Port is <b>open</b>") : _("Port is <b>closed</b>");
//gdk_threads_enter ();
gtk_label_set_markup(GTK_LABEL(data->portLabel), markup);
@ -1122,7 +1122,7 @@ static GtkWidget* networkPage(GObject* core)
GtkWidget* w;
GtkWidget* h;
GtkWidget* l;
const char* s;
char const* s;
struct network_page_data* data;
guint row = 0;
@ -1213,7 +1213,7 @@ static void on_prefs_dialog_destroyed(gpointer gdata, GObject* dead_dialog G_GNU
g_free(data);
}
static void on_core_prefs_changed(TrCore* core, const tr_quark key, gpointer gdata)
static void on_core_prefs_changed(TrCore* core, tr_quark const key, gpointer gdata)
{
struct prefs_dialog_data* data = gdata;
@ -1230,7 +1230,7 @@ static void on_core_prefs_changed(TrCore* core, const tr_quark key, gpointer gda
if (key == TR_KEY_download_dir)
{
const char* downloadDir = tr_sessionGetDownloadDir(gtr_core_session(core));
char const* downloadDir = tr_sessionGetDownloadDir(gtr_core_session(core));
gtr_freespace_label_set_dir(data->freespace_label, downloadDir);
}
}
@ -1241,7 +1241,7 @@ GtkWidget* gtr_prefs_dialog_new(GtkWindow* parent, GObject* core)
GtkWidget* d;
GtkWidget* n;
struct prefs_dialog_data* data;
const tr_quark prefs_quarks[] = { TR_KEY_peer_port, TR_KEY_download_dir };
tr_quark const prefs_quarks[] = { TR_KEY_peer_port, TR_KEY_download_dir };
data = g_new0(struct prefs_dialog_data, 1);
data->core = TR_CORE(core);

View File

@ -88,12 +88,12 @@ static void view_row_activated(GtkTreeView* tree_view UNUSED, GtkTreePath* path
gtr_action_activate("show-torrent-properties");
}
static gboolean tree_view_search_equal_func(GtkTreeModel* model, gint column UNUSED, const gchar* key, GtkTreeIter* iter,
static gboolean tree_view_search_equal_func(GtkTreeModel* model, gint column UNUSED, gchar const* key, GtkTreeIter* iter,
gpointer search_data UNUSED)
{
gboolean match;
char* lower;
const char* name = NULL;
char const* name = NULL;
lower = g_strstrip(g_utf8_strdown(key, -1));
gtk_tree_model_get(model, iter, MC_NAME_COLLATED, &name, -1);
@ -149,7 +149,7 @@ static GtkWidget* makeview(PrivateData* p)
static void syncAltSpeedButton(PrivateData* p);
static void prefsChanged(TrCore* core UNUSED, const tr_quark key, gpointer wind)
static void prefsChanged(TrCore* core UNUSED, tr_quark const key, gpointer wind)
{
gboolean isEnabled;
PrivateData* p = get_private_data(GTK_WINDOW(wind));
@ -212,7 +212,7 @@ static void onYinYangReleased(GtkWidget* w UNUSED, gpointer vprivate)
static struct
{
const char* val, *i18n;
char const* val, *i18n;
}
stats_modes[] =
{
@ -227,7 +227,7 @@ static void status_menu_toggled_cb(GtkCheckMenuItem* menu_item, gpointer vprivat
if (gtk_check_menu_item_get_active(menu_item))
{
PrivateData* p = vprivate;
const char* val = g_object_get_data(G_OBJECT(menu_item), STATS_MODE);
char const* val = g_object_get_data(G_OBJECT(menu_item), STATS_MODE);
gtr_core_set_pref(p->core, TR_KEY_statusbar_stats, val);
}
}
@ -237,9 +237,9 @@ static void syncAltSpeedButton(PrivateData* p)
char u[32];
char d[32];
char* str;
const char* fmt;
const gboolean b = gtr_pref_flag_get(TR_KEY_alt_speed_enabled);
const char* stock = b ? "alt-speed-on" : "alt-speed-off";
char const* fmt;
gboolean const b = gtr_pref_flag_get(TR_KEY_alt_speed_enabled);
char const* stock = b ? "alt-speed-on" : "alt-speed-off";
GtkWidget* w = p->alt_speed_button;
tr_formatter_speed_KBps(u, gtr_pref_int_get(TR_KEY_alt_speed_up), sizeof(u));
@ -259,7 +259,7 @@ static void syncAltSpeedButton(PrivateData* p)
static void alt_speed_toggled_cb(GtkToggleButton* button, gpointer vprivate)
{
PrivateData* p = vprivate;
const gboolean b = gtk_toggle_button_get_active(button);
gboolean const b = gtk_toggle_button_get_active(button);
gtr_core_set_pref_bool(p->core, TR_KEY_alt_speed_enabled, b);
}
@ -270,7 +270,7 @@ static void alt_speed_toggled_cb(GtkToggleButton* button, gpointer vprivate)
static void findMaxAnnounceTime(GtkTreeModel* model, GtkTreePath* path UNUSED, GtkTreeIter* iter, gpointer gmaxTime)
{
tr_torrent* tor;
const tr_stat* torStat;
tr_stat const* torStat;
time_t* maxTime = gmaxTime;
gtk_tree_model_get(model, iter, MC_TORRENT, &tor, -1);
@ -284,7 +284,7 @@ static gboolean onAskTrackerQueryTooltip(GtkWidget* widget UNUSED, gint x UNUSED
gboolean handled;
time_t maxTime = 0;
PrivateData* p = gdata;
const time_t now = time(NULL);
time_t const now = time(NULL);
gtk_tree_selection_selected_foreach(p->selection, findMaxAnnounceTime, &maxTime);
@ -296,7 +296,7 @@ static gboolean onAskTrackerQueryTooltip(GtkWidget* widget UNUSED, gint x UNUSED
{
char buf[512];
char timebuf[64];
const int seconds = maxTime - now;
int const seconds = maxTime - now;
tr_strltime(timebuf, seconds, sizeof(timebuf));
g_snprintf(buf, sizeof(buf), _("Tracker will allow requests in %s"), timebuf);
@ -335,7 +335,7 @@ static void onSpeedToggled(GtkCheckMenuItem* check, gpointer vp)
GObject* o = G_OBJECT(check);
gboolean isEnabled = g_object_get_data(o, ENABLED_KEY) != 0;
tr_direction dir = GPOINTER_TO_INT(g_object_get_data(o, DIRECTION_KEY));
const tr_quark key = dir == TR_UP ? TR_KEY_speed_limit_up_enabled : TR_KEY_speed_limit_down_enabled;
tr_quark const key = dir == TR_UP ? TR_KEY_speed_limit_up_enabled : TR_KEY_speed_limit_down_enabled;
if (gtk_check_menu_item_get_active(check))
{
@ -348,7 +348,7 @@ static void onSpeedSet(GtkCheckMenuItem* check, gpointer vp)
tr_quark key;
PrivateData* p = vp;
GObject* o = G_OBJECT(check);
const int KBps = GPOINTER_TO_INT(g_object_get_data(o, SPEED_KEY));
int const KBps = GPOINTER_TO_INT(g_object_get_data(o, SPEED_KEY));
tr_direction dir = GPOINTER_TO_INT(g_object_get_data(o, DIRECTION_KEY));
key = dir == TR_UP ? TR_KEY_speed_limit_up : TR_KEY_speed_limit_down;
@ -365,7 +365,7 @@ static GtkWidget* createSpeedMenu(PrivateData* p, tr_direction dir)
GtkWidget* w;
GtkWidget* m;
GtkMenuShell* menu_shell;
const int speeds_KBps[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
int const speeds_KBps[] = { 5, 10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 500, 750 };
m = gtk_menu_new();
menu_shell = GTK_MENU_SHELL(m);
@ -410,7 +410,7 @@ static GtkWidget* createSpeedMenu(PrivateData* p, tr_direction dir)
#define RATIO_KEY "stock-ratio-index"
static const double stockRatios[] = { 0.25, 0.5, 0.75, 1, 1.5, 2, 3 };
static double const stockRatios[] = { 0.25, 0.5, 0.75, 1, 1.5, 2, 3 };
static void onRatioToggled(GtkCheckMenuItem* check, gpointer vp)
{
@ -426,7 +426,7 @@ static void onRatioSet(GtkCheckMenuItem* check, gpointer vp)
{
PrivateData* p = vp;
int i = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(check), RATIO_KEY));
const double ratio = stockRatios[i];
double const ratio = stockRatios[i];
gtr_core_set_pref_double(p->core, TR_KEY_ratio_limit, ratio);
gtr_core_set_pref_bool(p->core, TR_KEY_ratio_limit_enabled, TRUE);
}
@ -538,7 +538,7 @@ static void onOptionsClicked(GtkButton* button UNUSED, gpointer vp)
GtkWidget* gtr_window_new(GtkApplication* app, GtkUIManager* ui_mgr, TrCore* core)
{
int i, n;
const char* pch, * style;
char const* pch, * style;
PrivateData* p;
GtkWidget* sibling = NULL;
GtkWidget* ul_lb, * dl_lb;
@ -601,7 +601,7 @@ GtkWidget* gtr_window_new(GtkApplication* app, GtkUIManager* ui_mgr, TrCore* cor
for (i = 0, n = G_N_ELEMENTS(stats_modes); i < n; ++i)
{
const char* val = stats_modes[i].val;
char const* val = stats_modes[i].val;
w = gtk_radio_menu_item_new_with_label(l, _(stats_modes[i].i18n));
l = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(w));
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), g_strcmp0(val, pch) == 0);
@ -723,7 +723,7 @@ GtkWidget* gtr_window_new(GtkApplication* app, GtkUIManager* ui_mgr, TrCore* cor
static void updateStats(PrivateData* p)
{
const char* pch;
char const* pch;
char up[32];
char down[32];
char ratio[32];

View File

@ -32,29 +32,29 @@
**** UNITS
***/
const int mem_K = 1024;
const char* mem_K_str = N_("KiB");
const char* mem_M_str = N_("MiB");
const char* mem_G_str = N_("GiB");
const char* mem_T_str = N_("TiB");
int const mem_K = 1024;
char const* mem_K_str = N_("KiB");
char const* mem_M_str = N_("MiB");
char const* mem_G_str = N_("GiB");
char const* mem_T_str = N_("TiB");
const int disk_K = 1000;
const char* disk_K_str = N_("kB");
const char* disk_M_str = N_("MB");
const char* disk_G_str = N_("GB");
const char* disk_T_str = N_("TB");
int const disk_K = 1000;
char const* disk_K_str = N_("kB");
char const* disk_M_str = N_("MB");
char const* disk_G_str = N_("GB");
char const* disk_T_str = N_("TB");
const int speed_K = 1000;
const char* speed_K_str = N_("kB/s");
const char* speed_M_str = N_("MB/s");
const char* speed_G_str = N_("GB/s");
const char* speed_T_str = N_("TB/s");
int const speed_K = 1000;
char const* speed_K_str = N_("kB/s");
char const* speed_M_str = N_("MB/s");
char const* speed_G_str = N_("GB/s");
char const* speed_T_str = N_("TB/s");
/***
****
***/
const char* gtr_get_unicode_string(int i)
char const* gtr_get_unicode_string(int i)
{
switch (i)
{
@ -161,15 +161,15 @@ char* tr_strltime(char* buf, int seconds, size_t buflen)
}
/* pattern-matching text; ie, legaltorrents.com */
void gtr_get_host_from_url(char* buf, size_t buflen, const char* url)
void gtr_get_host_from_url(char* buf, size_t buflen, char const* url)
{
char host[1024];
const char* pch;
char const* pch;
if ((pch = strstr(url, "://")))
{
const size_t hostlen = strcspn(pch + 3, ":/");
const size_t copylen = MIN(hostlen, sizeof(host) - 1);
size_t const hostlen = strcspn(pch + 3, ":/");
size_t const copylen = MIN(hostlen, sizeof(host) - 1);
memcpy(host, pch + 3, copylen);
host[copylen] = '\0';
}
@ -184,8 +184,8 @@ void gtr_get_host_from_url(char* buf, size_t buflen, const char* url)
}
else
{
const char* first_dot = strchr(host, '.');
const char* last_dot = strrchr(host, '.');
char const* first_dot = strchr(host, '.');
char const* last_dot = strrchr(host, '.');
if ((first_dot) && (last_dot) && (first_dot != last_dot))
{
@ -198,18 +198,18 @@ void gtr_get_host_from_url(char* buf, size_t buflen, const char* url)
}
}
static gboolean gtr_is_supported_url(const char* str)
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://")));
}
gboolean gtr_is_magnet_link(const char* str)
gboolean gtr_is_magnet_link(char const* str)
{
return (str != NULL) && (g_str_has_prefix(str, "magnet:?"));
}
gboolean gtr_is_hex_hashcode(const char* str)
gboolean gtr_is_hex_hashcode(char const* str)
{
int i;
@ -244,7 +244,7 @@ static GtkWindow* getWindow(GtkWidget* w)
return GTK_WINDOW(gtk_widget_get_ancestor(w, GTK_TYPE_WINDOW));
}
void gtr_add_torrent_error_dialog(GtkWidget* child, int err, tr_torrent* duplicate_torrent, const char* filename)
void gtr_add_torrent_error_dialog(GtkWidget* child, int err, tr_torrent* duplicate_torrent, char const* filename)
{
char* secondary;
GtkWidget* w;
@ -323,7 +323,7 @@ gboolean on_tree_view_button_released(GtkWidget* view, GdkEventButton* event, gp
return FALSE;
}
bool gtr_file_trash_or_remove(const char* filename, tr_error** error)
bool gtr_file_trash_or_remove(char const* filename, tr_error** error)
{
GFile* file;
gboolean trashed = FALSE;
@ -365,20 +365,20 @@ bool gtr_file_trash_or_remove(const char* filename, tr_error** error)
return result;
}
const char* gtr_get_help_uri(void)
char const* gtr_get_help_uri(void)
{
static char* uri = NULL;
if (!uri)
{
const char* fmt = "https://transmissionbt.com/help/gtk/%d.%dx";
char const* fmt = "https://transmissionbt.com/help/gtk/%d.%dx";
uri = g_strdup_printf(fmt, MAJOR_VERSION, MINOR_VERSION / 10);
}
return uri;
}
void gtr_open_file(const char* path)
void gtr_open_file(char const* path)
{
GFile* file = g_file_new_for_path(path);
gchar* uri = g_file_get_uri(file);
@ -387,7 +387,7 @@ void gtr_open_file(const char* path)
g_object_unref(file);
}
void gtr_open_uri(const char* uri)
void gtr_open_uri(char const* uri)
{
if (uri)
{
@ -424,7 +424,7 @@ void gtr_combo_box_set_active_enum(GtkComboBox* combo_box, int value)
{
int i;
int currentValue;
const int column = 0;
int const column = 0;
GtkTreeIter iter;
GtkTreeModel* model = gtk_combo_box_get_model(combo_box);
@ -455,12 +455,12 @@ void gtr_combo_box_set_active_enum(GtkComboBox* combo_box, int value)
}
GtkWidget* gtr_combo_box_new_enum(const char* text_1, ...)
GtkWidget* gtr_combo_box_new_enum(char const* text_1, ...)
{
GtkWidget* w;
GtkCellRenderer* r;
GtkListStore* store;
const char* text;
char const* text;
store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
@ -474,9 +474,9 @@ GtkWidget* gtr_combo_box_new_enum(const char* text_1, ...)
do
{
const int val = va_arg(vl, int);
int const val = va_arg(vl, int);
gtk_list_store_insert_with_values(store, NULL, INT_MAX, 0, val, 1, text, -1);
text = va_arg(vl, const char*);
text = va_arg(vl, char const*);
}
while (text != NULL);
@ -576,7 +576,7 @@ void gtr_dialog_set_content(GtkDialog* dialog, GtkWidget* content)
****
***/
void gtr_http_failure_dialog(GtkWidget* parent, const char* url, long response_code)
void gtr_http_failure_dialog(GtkWidget* parent, char const* url, long response_code)
{
GtkWindow* window = getWindow(parent);
@ -589,9 +589,9 @@ void gtr_http_failure_dialog(GtkWidget* parent, const char* url, long response_c
gtk_widget_show(w);
}
void gtr_unrecognized_url_dialog(GtkWidget* parent, const char* url)
void gtr_unrecognized_url_dialog(GtkWidget* parent, char const* url)
{
const char* xt = "xt=urn:btih";
char const* xt = "xt=urn:btih";
GtkWindow* window = getWindow(parent);
@ -650,9 +650,9 @@ void gtr_paste_clipboard_url_into_entry(GtkWidget* e)
****
***/
void gtr_label_set_text(GtkLabel* lb, const char* newstr)
void gtr_label_set_text(GtkLabel* lb, char const* newstr)
{
const char* oldstr = gtk_label_get_text(lb);
char const* oldstr = gtk_label_get_text(lb);
if (g_strcmp0(oldstr, newstr) != 0)
{
@ -738,7 +738,7 @@ static gboolean on_freespace_timer(gpointer gdata)
return G_SOURCE_CONTINUE;
}
GtkWidget* gtr_freespace_label_new(struct _TrCore* core, const char* dir)
GtkWidget* gtr_freespace_label_new(struct _TrCore* core, char const* dir)
{
struct freespace_label_data* data;
@ -757,7 +757,7 @@ GtkWidget* gtr_freespace_label_new(struct _TrCore* core, const char* dir)
return GTK_WIDGET(data->label);
}
void gtr_freespace_label_set_dir(GtkWidget* label, const char* dir)
void gtr_freespace_label_set_dir(GtkWidget* label, char const* dir)
{
struct freespace_label_data* data;

View File

@ -14,23 +14,23 @@
#include <libtransmission/transmission.h>
extern const int mem_K;
extern const char* mem_K_str;
extern const char* mem_M_str;
extern const char* mem_G_str;
extern const char* mem_T_str;
extern int const mem_K;
extern char const* mem_K_str;
extern char const* mem_M_str;
extern char const* mem_G_str;
extern char const* mem_T_str;
extern const int disk_K;
extern const char* disk_K_str;
extern const char* disk_M_str;
extern const char* disk_G_str;
extern const char* disk_T_str;
extern int const disk_K;
extern char const* disk_K_str;
extern char const* disk_M_str;
extern char const* disk_G_str;
extern char const* disk_T_str;
extern const int speed_K;
extern const char* speed_K_str;
extern const char* speed_M_str;
extern const char* speed_G_str;
extern const char* speed_T_str;
extern int const speed_K;
extern char const* speed_K_str;
extern char const* speed_M_str;
extern char const* speed_G_str;
extern char const* speed_T_str;
#if GLIB_CHECK_VERSION(2, 33, 12)
@ -66,7 +66,7 @@ enum
GTR_UNICODE_BULLET
};
const char* gtr_get_unicode_string(int);
char const* gtr_get_unicode_string(int);
/* return a percent formatted string of either x.xx, xx.x or xxx */
char* tr_strlpercent(char* buf, double x, size_t buflen);
@ -85,21 +85,21 @@ char* tr_strltime(char* buf, int secs, size_t buflen);
***/
/* http://www.legaltorrents.com/some/announce/url --> legaltorrents.com */
void gtr_get_host_from_url(char* buf, size_t buflen, const char* url);
void gtr_get_host_from_url(char* buf, size_t buflen, char const* url);
gboolean gtr_is_magnet_link(const char* str);
gboolean gtr_is_magnet_link(char const* str);
gboolean gtr_is_hex_hashcode(const char* str);
gboolean gtr_is_hex_hashcode(char const* str);
/***
****
***/
void gtr_open_uri(const char* uri);
void gtr_open_uri(char const* uri);
void gtr_open_file(const char* path);
void gtr_open_file(char const* path);
const char* gtr_get_help_uri(void);
char const* gtr_get_help_uri(void);
/***
****
@ -118,7 +118,7 @@ GtkWidget* gtr_priority_combo_new(void);
#define gtr_priority_combo_get_value(w) gtr_combo_box_get_active_enum(w)
#define gtr_priority_combo_set_value(w,val) gtr_combo_box_set_active_enum(w,val)
GtkWidget* gtr_combo_box_new_enum(const char* text_1, ...);
GtkWidget* gtr_combo_box_new_enum(char const* text_1, ...);
int gtr_combo_box_get_active_enum(GtkComboBox*);
void gtr_combo_box_set_active_enum(GtkComboBox*, int value);
@ -128,19 +128,19 @@ void gtr_combo_box_set_active_enum(GtkComboBox*, int value);
struct _TrCore;
GtkWidget* gtr_freespace_label_new(struct _TrCore* core, const char* dir);
GtkWidget* gtr_freespace_label_new(struct _TrCore* core, char const* dir);
void gtr_freespace_label_set_dir(GtkWidget* label, const char* dir);
void gtr_freespace_label_set_dir(GtkWidget* label, char const* dir);
/***
****
***/
void gtr_unrecognized_url_dialog(GtkWidget* parent, const char* url);
void gtr_unrecognized_url_dialog(GtkWidget* parent, char const* url);
void gtr_http_failure_dialog(GtkWidget* parent, const char* url, long response_code);
void gtr_http_failure_dialog(GtkWidget* parent, char const* url, long response_code);
void gtr_add_torrent_error_dialog(GtkWidget* window_or_child, int err, tr_torrent* duplicate_torrent, const char* filename);
void gtr_add_torrent_error_dialog(GtkWidget* window_or_child, int err, tr_torrent* duplicate_torrent, char const* filename);
/* pop up the context menu if a user right-clicks.
if the row they right-click on isn't selected, select it. */
@ -150,11 +150,11 @@ gboolean on_tree_view_button_pressed(GtkWidget* view, GdkEventButton* event, gpo
gboolean on_tree_view_button_released(GtkWidget* view, GdkEventButton* event, gpointer unused);
/* move a file to the trashcan if GIO is available; otherwise, delete it */
bool gtr_file_trash_or_remove(const char* filename, struct tr_error** error);
bool gtr_file_trash_or_remove(char const* filename, struct tr_error** error);
void gtr_paste_clipboard_url_into_entry(GtkWidget* entry);
/* Only call gtk_label_set_text () if the new text differs from the old.
* This prevents the label from having to recalculate its size
* and prevents selected text in the label from being deselected */
void gtr_label_set_text(GtkLabel* lb, const char* text);
void gtr_label_set_text(GtkLabel* lb, char const* text);

View File

@ -91,12 +91,12 @@ typedef struct
}
tr_scrape_response;
typedef void (* tr_scrape_response_func)(const tr_scrape_response* response, void* user_data);
typedef void (* tr_scrape_response_func)(tr_scrape_response const* response, void* user_data);
void tr_tracker_http_scrape(tr_session* session, const tr_scrape_request* req, tr_scrape_response_func response_func,
void tr_tracker_http_scrape(tr_session* session, tr_scrape_request const* req, tr_scrape_response_func response_func,
void* user_data);
void tr_tracker_udp_scrape(tr_session* session, const tr_scrape_request* req, tr_scrape_response_func response_func,
void tr_tracker_udp_scrape(tr_session* session, tr_scrape_request const* req, tr_scrape_response_func response_func,
void* user_data);
/***
@ -112,7 +112,7 @@ typedef enum
}
tr_announce_event;
const char* tr_announce_event_get_string(tr_announce_event);
char const* tr_announce_event_get_string(tr_announce_event);
typedef struct
{
@ -213,12 +213,12 @@ typedef struct
}
tr_announce_response;
typedef void (* tr_announce_response_func)(const tr_announce_response* response, void* userdata);
typedef void (* tr_announce_response_func)(tr_announce_response const* response, void* userdata);
void tr_tracker_http_announce(tr_session* session, const tr_announce_request* req, tr_announce_response_func response_func,
void tr_tracker_http_announce(tr_session* session, tr_announce_request const* req, tr_announce_response_func response_func,
void* user_data);
void tr_tracker_udp_announce(tr_session* session, const tr_announce_request* req, tr_announce_response_func response_func,
void tr_tracker_udp_announce(tr_session* session, tr_announce_request const* req, tr_announce_response_func response_func,
void* user_data);
void tr_tracker_udp_start_shutdown(tr_session* session);

View File

@ -42,7 +42,7 @@
*****
****/
static const char* get_event_string(const tr_announce_request* req)
static char const* get_event_string(tr_announce_request const* req)
{
if (req->partial_seed)
{
@ -55,10 +55,10 @@ static const char* get_event_string(const tr_announce_request* req)
return tr_announce_event_get_string(req->event);
}
static char* announce_url_new(const tr_session* session, const tr_announce_request* req)
static char* announce_url_new(tr_session const* session, tr_announce_request const* req)
{
const char* str;
const unsigned char* ipv6;
char const* str;
unsigned char const* ipv6;
struct evbuffer* buf = evbuffer_new();
char escaped_info_hash[SHA_DIGEST_LENGTH * 3 + 1];
@ -140,13 +140,13 @@ static tr_pex* listToPex(tr_variant* peerList, size_t* setme_len)
{
size_t i;
size_t n;
const size_t len = tr_variantListSize(peerList);
size_t const len = tr_variantListSize(peerList);
tr_pex* pex = tr_new0(tr_pex, len);
for (i = n = 0; i < len; ++i)
{
int64_t port;
const char* ip;
char const* ip;
tr_address addr;
tr_variant* peer = tr_variantListChild(peerList, i);
@ -214,7 +214,7 @@ static void on_announce_done_eventthread(void* vdata)
tr_free(data);
}
static void on_announce_done(tr_session* session, bool did_connect, bool did_timeout, long response_code, const void* msg,
static void on_announce_done(tr_session* session, bool did_connect, bool did_timeout, long response_code, void const* msg,
size_t msglen, void* vdata)
{
tr_announce_response* response;
@ -227,14 +227,14 @@ static void on_announce_done(tr_session* session, bool did_connect, bool did_tim
if (response_code != HTTP_OK)
{
const char* fmt = _("Tracker gave HTTP response code %1$ld (%2$s)");
const char* response_str = tr_webGetResponseStr(response_code);
char const* fmt = _("Tracker gave HTTP response code %1$ld (%2$s)");
char const* response_str = tr_webGetResponseStr(response_code);
response->errmsg = tr_strdup_printf(fmt, response_code, response_str);
}
else
{
tr_variant benc;
const bool variant_loaded = !tr_variantFromBenc(&benc, msg, msglen);
bool const variant_loaded = !tr_variantFromBenc(&benc, msg, msglen);
if (tr_env_key_exists("TR_CURL_VERBOSE"))
{
@ -263,8 +263,8 @@ static void on_announce_done(tr_session* session, bool did_connect, bool did_tim
int64_t i;
size_t len;
tr_variant* tmp;
const char* str;
const uint8_t* raw;
char const* str;
uint8_t const* raw;
if (tr_variantDictFindStr(&benc, TR_KEY_failure_reason, &str, &len))
{
@ -333,7 +333,7 @@ static void on_announce_done(tr_session* session, bool did_connect, bool did_tim
tr_runInEventThread(session, on_announce_done_eventthread, data);
}
void tr_tracker_http_announce(tr_session* session, const tr_announce_request* request, tr_announce_response_func response_func,
void tr_tracker_http_announce(tr_session* session, tr_announce_request const* request, tr_announce_response_func response_func,
void* response_func_user_data)
{
struct announce_data* d;
@ -382,7 +382,7 @@ static void on_scrape_done_eventthread(void* vdata)
tr_free(data);
}
static void on_scrape_done(tr_session* session, bool did_connect, bool did_timeout, long response_code, const void* msg,
static void on_scrape_done(tr_session* session, bool did_connect, bool did_timeout, long response_code, void const* msg,
size_t msglen, void* vdata)
{
tr_scrape_response* response;
@ -395,8 +395,8 @@ static void on_scrape_done(tr_session* session, bool did_connect, bool did_timeo
if (response_code != HTTP_OK)
{
const char* fmt = _("Tracker gave HTTP response code %1$ld (%2$s)");
const char* response_str = tr_webGetResponseStr(response_code);
char const* fmt = _("Tracker gave HTTP response code %1$ld (%2$s)");
char const* response_str = tr_webGetResponseStr(response_code);
response->errmsg = tr_strdup_printf(fmt, response_code, response_str);
}
else
@ -406,8 +406,8 @@ static void on_scrape_done(tr_session* session, bool did_connect, bool did_timeo
tr_variant* files;
tr_variant* flags;
size_t len;
const char* str;
const bool variant_loaded = !tr_variantFromBenc(&top, msg, msglen);
char const* str;
bool const variant_loaded = !tr_variantFromBenc(&top, msg, msglen);
if (tr_env_key_exists("TR_CURL_VERBOSE"))
{
@ -502,7 +502,7 @@ static void on_scrape_done(tr_session* session, bool did_connect, bool did_timeo
tr_runInEventThread(session, on_scrape_done_eventthread, data);
}
static char* scrape_url_new(const tr_scrape_request* req)
static char* scrape_url_new(tr_scrape_request const* req)
{
int i;
char delimiter;
@ -522,7 +522,7 @@ static char* scrape_url_new(const tr_scrape_request* req)
return evbuffer_free_to_str(buf, NULL);
}
void tr_tracker_http_scrape(tr_session* session, const tr_scrape_request* request, tr_scrape_response_func response_func,
void tr_tracker_http_scrape(tr_session* session, tr_scrape_request const* request, tr_scrape_response_func response_func,
void* response_func_user_data)
{
int i;

View File

@ -52,7 +52,7 @@ static void tau_sockaddr_setport(struct sockaddr* sa, tr_port port)
}
}
static int tau_sendto(tr_session* session, struct evutil_addrinfo* ai, tr_port port, const void* buf, size_t buflen)
static int tau_sendto(tr_session* session, struct evutil_addrinfo* ai, tr_port port, void const* buf, size_t buflen)
{
tr_socket_t sockfd;
@ -177,13 +177,13 @@ struct tau_scrape_request
void* user_data;
};
static struct tau_scrape_request* tau_scrape_request_new(const tr_scrape_request* in, tr_scrape_response_func callback,
static struct tau_scrape_request* tau_scrape_request_new(tr_scrape_request const* in, tr_scrape_response_func callback,
void* user_data)
{
int i;
struct evbuffer* buf;
struct tau_scrape_request* req;
const tau_transaction_t transaction_id = tau_transaction_new();
tau_transaction_t const transaction_id = tau_transaction_new();
/* build the payload */
buf = evbuffer_new();
@ -227,7 +227,7 @@ static void tau_scrape_request_free(struct tau_scrape_request* req)
tr_free(req);
}
static void tau_scrape_request_finished(const struct tau_scrape_request* request)
static void tau_scrape_request_finished(struct tau_scrape_request const* request)
{
if (request->callback != NULL)
{
@ -235,7 +235,7 @@ static void tau_scrape_request_finished(const struct tau_scrape_request* request
}
}
static void tau_scrape_request_fail(struct tau_scrape_request* request, bool did_connect, bool did_timeout, const char* errmsg)
static void tau_scrape_request_fail(struct tau_scrape_request* request, bool did_connect, bool did_timeout, char const* errmsg)
{
request->response.did_connect = did_connect;
request->response.did_timeout = did_timeout;
@ -272,7 +272,7 @@ static void on_scrape_response(struct tau_scrape_request* request, tau_action_t
else
{
char* errmsg;
const size_t buflen = evbuffer_get_length(buf);
size_t const buflen = evbuffer_get_length(buf);
if ((action == TAU_ACTION_ERROR) && (buflen > 0))
{
@ -336,12 +336,12 @@ static tau_announce_event get_tau_announce_event(tr_announce_event e)
}
}
static struct tau_announce_request* tau_announce_request_new(const tr_announce_request* in, tr_announce_response_func callback,
static struct tau_announce_request* tau_announce_request_new(tr_announce_request const* in, tr_announce_response_func callback,
void* user_data)
{
struct evbuffer* buf;
struct tau_announce_request* req;
const tau_transaction_t transaction_id = tau_transaction_new();
tau_transaction_t const transaction_id = tau_transaction_new();
/* build the payload */
buf = evbuffer_new();
@ -386,7 +386,7 @@ static void tau_announce_request_free(struct tau_announce_request* req)
tr_free(req);
}
static void tau_announce_request_finished(const struct tau_announce_request* request)
static void tau_announce_request_finished(struct tau_announce_request const* request)
{
if (request->callback != NULL)
{
@ -395,7 +395,7 @@ static void tau_announce_request_finished(const struct tau_announce_request* req
}
static void tau_announce_request_fail(struct tau_announce_request* request, bool did_connect, bool did_timeout,
const char* errmsg)
char const* errmsg)
{
request->response.did_connect = did_connect;
request->response.did_timeout = did_timeout;
@ -405,7 +405,7 @@ static void tau_announce_request_fail(struct tau_announce_request* request, bool
static void on_announce_response(struct tau_announce_request* request, tau_action_t action, struct evbuffer* buf)
{
const size_t buflen = evbuffer_get_length(buf);
size_t const buflen = evbuffer_get_length(buf);
request->response.did_connect = true;
request->response.did_timeout = false;
@ -485,7 +485,7 @@ static void tau_tracker_free(struct tau_tracker* t)
tr_free(t);
}
static void tau_tracker_fail_all(struct tau_tracker* tracker, bool did_connect, bool did_timeout, const char* errmsg)
static void tau_tracker_fail_all(struct tau_tracker* tracker, bool did_connect, bool did_timeout, char const* errmsg)
{
int i;
int n;
@ -536,7 +536,7 @@ static void tau_tracker_on_dns(int errcode, struct evutil_addrinfo* addr, void*
}
}
static void tau_tracker_send_request(struct tau_tracker* tracker, const void* payload, size_t payload_len)
static void tau_tracker_send_request(struct tau_tracker* tracker, void const* payload, size_t payload_len)
{
struct evbuffer* buf = evbuffer_new();
dbgmsg(tracker->key, "sending request w/connection id %" PRIu64 "\n", tracker->connection_id);
@ -550,7 +550,7 @@ static void tau_tracker_send_reqs(struct tau_tracker* tracker)
{
int i, n;
tr_ptrArray* reqs;
const time_t now = tr_time();
time_t const now = tr_time();
assert(tracker->dns_request == NULL);
assert(tracker->connecting_at == 0);
@ -604,7 +604,7 @@ static void tau_tracker_send_reqs(struct tau_tracker* tracker)
static void on_tracker_connection_response(struct tau_tracker* tracker, tau_action_t action, struct evbuffer* buf)
{
const time_t now = tr_time();
time_t const now = tr_time();
tracker->connecting_at = 0;
tracker->connection_transaction_id = 0;
@ -618,7 +618,7 @@ static void on_tracker_connection_response(struct tau_tracker* tracker, tau_acti
else
{
char* errmsg;
const size_t buflen = buf ? evbuffer_get_length(buf) : 0;
size_t const buflen = buf ? evbuffer_get_length(buf) : 0;
if ((action == TAU_ACTION_ERROR) && (buflen > 0))
{
@ -641,8 +641,8 @@ static void tau_tracker_timeout_reqs(struct tau_tracker* tracker)
{
int i, n;
tr_ptrArray* reqs;
const time_t now = time(NULL);
const bool cancel_all = tracker->close_at && (tracker->close_at <= now);
time_t const now = time(NULL);
bool const cancel_all = tracker->close_at && (tracker->close_at <= now);
if (tracker->connecting_at && (tracker->connecting_at + TAU_REQUEST_TTL < now))
{
@ -684,15 +684,15 @@ static void tau_tracker_timeout_reqs(struct tau_tracker* tracker)
}
}
static bool tau_tracker_is_idle(const struct tau_tracker* tracker)
static bool tau_tracker_is_idle(struct tau_tracker const* tracker)
{
return tr_ptrArrayEmpty(&tracker->announces) && tr_ptrArrayEmpty(&tracker->scrapes) && tracker->dns_request == NULL;
}
static void tau_tracker_upkeep(struct tau_tracker* tracker)
{
const time_t now = tr_time();
const bool closing = tracker->close_at != 0;
time_t const now = tr_time();
bool const closing = tracker->close_at != 0;
/* if the address info is too old, expire it */
if (tracker->addr != NULL && (closing || tracker->addr_expiration_time <= now))
@ -781,7 +781,7 @@ static struct tr_announcer_udp* announcer_udp_get(tr_session* session)
/* Finds the tau_tracker struct that corresponds to this url.
If it doesn't exist yet, create one. */
static struct tau_tracker* tau_session_get_tracker(struct tr_announcer_udp* tau, const char* url)
static struct tau_tracker* tau_session_get_tracker(struct tr_announcer_udp* tau, char const* url)
{
int i;
int n;
@ -842,7 +842,7 @@ void tr_tracker_udp_upkeep(tr_session* session)
}
}
bool tr_tracker_udp_is_idle(const tr_session* session)
bool tr_tracker_udp_is_idle(tr_session const* session)
{
int i;
int n;
@ -880,7 +880,7 @@ void tr_tracker_udp_close(tr_session* session)
but sets a deadline on how much longer to wait for the remaining ones */
void tr_tracker_udp_start_shutdown(tr_session* session)
{
const time_t now = time(NULL);
time_t const now = time(NULL);
struct tr_announcer_udp* tau = session->announcer_udp;
if (tau != NULL)
@ -904,7 +904,7 @@ void tr_tracker_udp_start_shutdown(tr_session* session)
/* @brief process an incoming udp message if it's a tracker response.
* @return true if msg was a tracker response; false otherwise */
bool tau_handle_message(tr_session* session, const uint8_t* msg, size_t msglen)
bool tau_handle_message(tr_session* session, uint8_t const* msg, size_t msglen)
{
int i;
int n;
@ -998,7 +998,7 @@ bool tau_handle_message(tr_session* session, const uint8_t* msg, size_t msglen)
return false;
}
void tr_tracker_udp_announce(tr_session* session, const tr_announce_request* request, tr_announce_response_func response_func,
void tr_tracker_udp_announce(tr_session* session, tr_announce_request const* request, tr_announce_response_func response_func,
void* user_data)
{
struct tr_announcer_udp* tau = announcer_udp_get(session);
@ -1008,7 +1008,7 @@ void tr_tracker_udp_announce(tr_session* session, const tr_announce_request* req
tau_tracker_upkeep(tracker);
}
void tr_tracker_udp_scrape(tr_session* session, const tr_scrape_request* request, tr_scrape_response_func response_func,
void tr_tracker_udp_scrape(tr_session* session, tr_scrape_request const* request, tr_scrape_response_func response_func,
void* user_data)
{
struct tr_announcer_udp* tau = announcer_udp_get(session);

View File

@ -30,7 +30,7 @@
struct tr_tier;
static void tier_build_log_name(const struct tr_tier* tier, char* buf, size_t buflen);
static void tier_build_log_name(struct tr_tier const* tier, char* buf, size_t buflen);
#define dbgmsg(tier, ...) \
do \
@ -66,7 +66,7 @@ enum
****
***/
const char* tr_announce_event_get_string(tr_announce_event e)
char const* tr_announce_event_get_string(tr_announce_event e)
{
switch (e)
{
@ -112,11 +112,11 @@ static int compareTransfer(uint64_t a_uploaded, uint64_t a_downloaded, uint64_t
* tracker announcements of active torrents. The remaining keys are
* used to satisfy the uniqueness requirement of a sorted tr_ptrArray.
*/
static int compareStops(const void* va, const void* vb)
static int compareStops(void const* va, void const* vb)
{
int i;
const tr_announce_request* a = va;
const tr_announce_request* b = vb;
tr_announce_request const* a = va;
tr_announce_request const* b = vb;
/* primary key: volume of data transferred. */
if ((i = compareTransfer(a->up, a->down, b->up, b->down)))
@ -153,7 +153,7 @@ typedef struct tr_announcer
}
tr_announcer;
bool tr_announcerHasBacklog(const struct tr_announcer* announcer)
bool tr_announcerHasBacklog(struct tr_announcer const* announcer)
{
return announcer->slotsAvailable < 1;
}
@ -221,7 +221,7 @@ typedef struct
tr_tracker;
/* format: host+':'+ port */
static char* getKey(const char* url)
static char* getKey(char const* url)
{
char* ret;
char* scheme = NULL;
@ -236,7 +236,7 @@ static char* getKey(const char* url)
return ret;
}
static void trackerConstruct(tr_tracker* tracker, const tr_tracker_info* inf)
static void trackerConstruct(tr_tracker* tracker, tr_tracker_info const* inf)
{
memset(tracker, 0, sizeof(tr_tracker));
tracker->key = getKey(inf->announce);
@ -312,10 +312,10 @@ typedef struct tr_tier
}
tr_tier;
static time_t get_next_scrape_time(const tr_session* session, const tr_tier* tier, int interval)
static time_t get_next_scrape_time(tr_session const* session, tr_tier const* tier, int interval)
{
time_t ret;
const time_t now = tr_time();
time_t const now = tr_time();
/* Maybe don't scrape paused torrents */
if (!tier->isRunning && !session->scrapePausedTorrents)
@ -358,7 +358,7 @@ static void tierDestruct(tr_tier* tier)
tr_free(tier->announce_events);
}
static void tier_build_log_name(const tr_tier* tier, char* buf, size_t buflen)
static void tier_build_log_name(tr_tier const* tier, char* buf, size_t buflen)
{
tr_snprintf(buf, buflen, "[%s---%s]", (tier && tier->tor) ? tr_torrentName(tier->tor) : "?",
(tier && tier->currentTracker) ? tier->currentTracker->key : "?");
@ -367,7 +367,7 @@ static void tier_build_log_name(const tr_tier* tier, char* buf, size_t buflen)
static void tierIncrementTracker(tr_tier* tier)
{
/* move our index to the next tracker in the tier */
const int i = (tier->currentTracker == NULL) ? 0 : (tier->currentTrackerIndex + 1) % tier->tracker_count;
int const i = (tier->currentTracker == NULL) ? 0 : (tier->currentTrackerIndex + 1) % tier->tracker_count;
tier->currentTrackerIndex = i;
tier->currentTracker = &tier->trackers[i];
@ -433,7 +433,7 @@ static void tiersFree(tr_torrent_tiers* tt)
tr_free(tt);
}
static tr_tier* getTier(tr_announcer* announcer, const uint8_t* info_hash, int tierId)
static tr_tier* getTier(tr_announcer* announcer, uint8_t const* info_hash, int tierId)
{
tr_tier* tier = NULL;
@ -464,9 +464,9 @@ static tr_tier* getTier(tr_announcer* announcer, const uint8_t* info_hash, int t
**** PUBLISH
***/
static const tr_tracker_event TRACKER_EVENT_INIT = { 0, 0, 0, 0, 0, 0 };
static tr_tracker_event const TRACKER_EVENT_INIT = { 0, 0, 0, 0, 0, 0 };
static void publishMessage(tr_tier* tier, const char* msg, int type)
static void publishMessage(tr_tier* tier, char const* msg, int type)
{
if (tier && tier->tor && tier->tor->tiers && tier->tor->tiers->callback)
{
@ -489,12 +489,12 @@ static void publishErrorClear(tr_tier* tier)
publishMessage(tier, NULL, TR_TRACKER_ERROR_CLEAR);
}
static void publishWarning(tr_tier* tier, const char* msg)
static void publishWarning(tr_tier* tier, char const* msg)
{
publishMessage(tier, msg, TR_TRACKER_WARNING);
}
static void publishError(tr_tier* tier, const char* msg)
static void publishError(tr_tier* tier, char const* msg)
{
publishMessage(tier, msg, TR_TRACKER_ERROR);
}
@ -518,7 +518,7 @@ static int8_t getSeedProbability(tr_tier* tier, int seeds, int leechers, int pex
return -1; /* unknown */
}
static void publishPeersPex(tr_tier* tier, int seeds, int leechers, const tr_pex* pex, int n)
static void publishPeersPex(tr_tier* tier, int seeds, int leechers, tr_pex const* pex, int n)
{
if (tier->tor->tiers->callback)
{
@ -549,10 +549,10 @@ struct ann_tracker_info
/* primary key: tier
* secondary key: udp comes before http */
static int filter_trackers_compare_func(const void* va, const void* vb)
static int filter_trackers_compare_func(void const* va, void const* vb)
{
const struct ann_tracker_info* a = va;
const struct ann_tracker_info* b = vb;
struct ann_tracker_info const* a = va;
struct ann_tracker_info const* b = vb;
if (a->info.tier != b->info.tier)
{
@ -728,12 +728,12 @@ tr_torrent_tiers* tr_announcerAddTorrent(tr_torrent* tor, tr_tracker_callback ca
****
***/
static bool tierCanManualAnnounce(const tr_tier* tier)
static bool tierCanManualAnnounce(tr_tier const* tier)
{
return tier->manualAnnounceAllowedAt <= tr_time();
}
bool tr_announcerCanManualAnnounce(const tr_torrent* tor)
bool tr_announcerCanManualAnnounce(tr_torrent const* tor)
{
int i;
struct tr_torrent_tiers* tt = NULL;
@ -758,7 +758,7 @@ bool tr_announcerCanManualAnnounce(const tr_torrent* tor)
return false;
}
time_t tr_announcerNextManualAnnounce(const tr_torrent* tor)
time_t tr_announcerNextManualAnnounce(tr_torrent const* tor)
{
int i;
time_t ret = ~(time_t)0;
@ -776,7 +776,7 @@ time_t tr_announcerNextManualAnnounce(const tr_torrent* tor)
return ret;
}
static void dbgmsg_tier_announce_queue(const tr_tier* tier)
static void dbgmsg_tier_announce_queue(tr_tier const* tier)
{
if (tr_logGetDeepEnabled())
{
@ -789,8 +789,8 @@ static void dbgmsg_tier_announce_queue(const tr_tier* tier)
for (i = 0; i < tier->announce_event_count; ++i)
{
const tr_announce_event e = tier->announce_events[i];
const char* str = tr_announce_event_get_string(e);
tr_announce_event const e = tier->announce_events[i];
char const* str = tr_announce_event_get_string(e);
evbuffer_add_printf(buf, "[%d:%s]", i, str);
}
@ -824,7 +824,7 @@ static void tier_announce_event_push(tr_tier* tier, tr_announce_event e, time_t
if (e == TR_ANNOUNCE_EVENT_STOPPED)
{
bool has_completed = false;
const tr_announce_event c = TR_ANNOUNCE_EVENT_COMPLETED;
tr_announce_event const c = TR_ANNOUNCE_EVENT_COMPLETED;
for (i = 0; !has_completed && i < tier->announce_event_count; ++i)
{
@ -863,7 +863,7 @@ static void tier_announce_event_push(tr_tier* tier, tr_announce_event e, time_t
static tr_announce_event tier_announce_event_pull(tr_tier* tier)
{
const tr_announce_event e = tier->announce_events[0];
tr_announce_event const e = tier->announce_events[0];
tr_removeElementFromArray(tier->announce_events, 0, sizeof(tr_announce_event), tier->announce_event_count--);
@ -929,7 +929,7 @@ void tr_announcerAddBytes(tr_torrent* tor, int type, uint32_t byteCount)
****
***/
static tr_announce_request* announce_request_new(const tr_announcer* announcer, tr_torrent* tor, const tr_tier* tier,
static tr_announce_request* announce_request_new(tr_announcer const* announcer, tr_torrent* tor, tr_tier const* tier,
tr_announce_event event)
{
tr_announce_request* req = tr_new0(tr_announce_request, 1);
@ -966,7 +966,7 @@ void tr_announcerRemoveTorrent(tr_announcer* announcer, tr_torrent* tor)
if (tier->isRunning)
{
const tr_announce_event e = TR_ANNOUNCE_EVENT_STOPPED;
tr_announce_event const e = TR_ANNOUNCE_EVENT_STOPPED;
tr_announce_request* req = announce_request_new(announcer, tor, tier, e);
if (tr_ptrArrayFindSorted(&announcer->stops, req, compareStops) != NULL)
@ -985,7 +985,7 @@ void tr_announcerRemoveTorrent(tr_announcer* announcer, tr_torrent* tor)
}
}
static int getRetryInterval(const tr_tracker* t)
static int getRetryInterval(tr_tracker const* t)
{
switch (t->consecutiveFailures)
{
@ -1023,7 +1023,7 @@ struct announce_data
bool isRunningOnSuccess;
};
static void on_announce_error(tr_tier* tier, const char* err, tr_announce_event e)
static void on_announce_error(tr_tier* tier, char const* err, tr_announce_event e)
{
int interval;
@ -1048,13 +1048,13 @@ static void on_announce_error(tr_tier* tier, const char* err, tr_announce_event
tier_announce_event_push(tier, e, tr_time() + interval);
}
static void on_announce_done(const tr_announce_response* response, void* vdata)
static void on_announce_done(tr_announce_response const* response, void* vdata)
{
struct announce_data* data = vdata;
tr_announcer* announcer = data->session->announcer;
tr_tier* tier = getTier(announcer, response->info_hash, data->tierId);
const time_t now = tr_time();
const tr_announce_event event = data->event;
time_t const now = tr_time();
tr_announce_event const event = data->event;
if (announcer)
{
@ -1122,12 +1122,12 @@ static void on_announce_done(const tr_announce_response* response, void* vdata)
else
{
int i;
const char* str;
char const* str;
int scrape_fields = 0;
int seeders = 0;
int leechers = 0;
int downloads = 0;
const bool isStopped = event == TR_ANNOUNCE_EVENT_STOPPED;
bool const isStopped = event == TR_ANNOUNCE_EVENT_STOPPED;
publishErrorClear(tier);
@ -1278,7 +1278,7 @@ static void tierAnnounce(tr_announcer* announcer, tr_tier* tier)
tr_announce_request* req;
struct announce_data* data;
tr_torrent* tor = tier->tor;
const time_t now = tr_time();
time_t const now = tr_time();
assert(!tier->isAnnouncing);
assert(tier->announce_event_count > 0);
@ -1306,7 +1306,7 @@ static void tierAnnounce(tr_announcer* announcer, tr_tier* tier)
****
***/
static void on_scrape_error(tr_session* session, tr_tier* tier, const char* errmsg)
static void on_scrape_error(tr_session* session, tr_tier* tier, char const* errmsg)
{
int interval;
@ -1332,14 +1332,14 @@ static void on_scrape_error(tr_session* session, tr_tier* tier, const char* errm
tier->scrapeAt = get_next_scrape_time(session, tier, interval);
}
static tr_tier* find_tier(tr_torrent* tor, const char* scrape)
static tr_tier* find_tier(tr_torrent* tor, char const* scrape)
{
int i;
struct tr_torrent_tiers* tt = tor->tiers;
for (i = 0; tt && i < tt->tier_count; ++i)
{
const tr_tracker* const tracker = tt->tiers[i].currentTracker;
tr_tracker const* const tracker = tt->tiers[i].currentTracker;
if (tracker != NULL && tr_strcmp0(scrape, tracker->scrape) == 0)
{
@ -1350,16 +1350,16 @@ static tr_tier* find_tier(tr_torrent* tor, const char* scrape)
return NULL;
}
static void on_scrape_done(const tr_scrape_response* response, void* vsession)
static void on_scrape_done(tr_scrape_response const* response, void* vsession)
{
int i;
const time_t now = tr_time();
time_t const now = tr_time();
tr_session* session = vsession;
tr_announcer* announcer = session->announcer;
for (i = 0; i < response->row_count; ++i)
{
const struct tr_scrape_response_row* row = &response->rows[i];
struct tr_scrape_response_row const* row = &response->rows[i];
tr_torrent* tor = tr_torrentFindFromHash(session, row->info_hash);
if (tor != NULL)
@ -1445,7 +1445,7 @@ static void on_scrape_done(const tr_scrape_response* response, void* vsession)
}
}
static void scrape_request_delegate(tr_announcer* announcer, const tr_scrape_request* request, tr_scrape_response_func callback,
static void scrape_request_delegate(tr_announcer* announcer, tr_scrape_request const* request, tr_scrape_response_func callback,
void* callback_data)
{
tr_session* session = announcer->session;
@ -1468,9 +1468,9 @@ static void multiscrape(tr_announcer* announcer, tr_ptrArray* tiers)
{
int i;
int request_count = 0;
const time_t now = tr_time();
const int tier_count = tr_ptrArraySize(tiers);
const int max_request_count = MIN(announcer->slotsAvailable, tier_count);
time_t const now = tr_time();
int const tier_count = tr_ptrArraySize(tiers);
int const max_request_count = MIN(announcer->slotsAvailable, tier_count);
tr_scrape_request* requests = tr_new0(tr_scrape_request, max_request_count);
/* batch as many info_hashes into a request as we can */
@ -1479,7 +1479,7 @@ static void multiscrape(tr_announcer* announcer, tr_ptrArray* tiers)
int j;
tr_tier* tier = tr_ptrArrayNth(tiers, i);
char* url = tier->currentTracker->scrape;
const uint8_t* hash = tier->tor->info.hash;
uint8_t const* hash = tier->tor->info.hash;
/* if there's a request with this scrape URL and a free slot, use it */
for (j = 0; j < request_count; ++j)
@ -1528,7 +1528,7 @@ static void multiscrape(tr_announcer* announcer, tr_ptrArray* tiers)
static void flushCloseMessages(tr_announcer* announcer)
{
int i;
const int n = tr_ptrArraySize(&announcer->stops);
int const n = tr_ptrArraySize(&announcer->stops);
for (i = 0; i < n; ++i)
{
@ -1538,23 +1538,23 @@ static void flushCloseMessages(tr_announcer* announcer)
tr_ptrArrayClear(&announcer->stops);
}
static bool tierNeedsToAnnounce(const tr_tier* tier, const time_t now)
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);
}
static bool tierNeedsToScrape(const tr_tier* tier, const time_t now)
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);
}
static int compareTiers(const void* va, const void* vb)
static int compareTiers(void const* va, void const* vb)
{
int ret;
const tr_tier* a = *(const tr_tier**)va;
const tr_tier* b = *(const tr_tier**)vb;
tr_tier const* a = *(tr_tier const**)va;
tr_tier const* b = *(tr_tier const**)vb;
/* primary key: larger stats come before smaller */
ret = compareTransfer(a->byteCounts[TR_ANN_UP], a->byteCounts[TR_ANN_DOWN], b->byteCounts[TR_ANN_UP],
@ -1576,7 +1576,7 @@ static void announceMore(tr_announcer* announcer)
tr_torrent* tor;
tr_ptrArray announceMe = TR_PTR_ARRAY_INIT;
tr_ptrArray scrapeMe = TR_PTR_ARRAY_INIT;
const time_t now = tr_time();
time_t const now = tr_time();
dbgmsg(NULL, "announceMore: slotsAvailable is %d", announcer->slotsAvailable);
@ -1638,8 +1638,8 @@ static void onUpkeepTimer(evutil_socket_t foo UNUSED, short bar UNUSED, void* va
{
tr_announcer* announcer = vannouncer;
tr_session* session = announcer->session;
const bool is_closing = session->isClosed;
const time_t now = tr_time();
bool const is_closing = session->isClosed;
time_t const now = tr_time();
tr_sessionLock(session);
@ -1669,13 +1669,13 @@ static void onUpkeepTimer(evutil_socket_t foo UNUSED, short bar UNUSED, void* va
****
***/
tr_tracker_stat* tr_announcerStats(const tr_torrent* torrent, int* setmeTrackerCount)
tr_tracker_stat* tr_announcerStats(tr_torrent const* torrent, int* setmeTrackerCount)
{
int i;
int out = 0;
tr_tracker_stat* ret;
struct tr_torrent_tiers* tt;
const time_t now = tr_time();
time_t const now = tr_time();
assert(tr_isTorrent(torrent));
@ -1689,11 +1689,11 @@ tr_tracker_stat* tr_announcerStats(const tr_torrent* torrent, int* setmeTrackerC
for (i = 0; i < tt->tier_count; ++i)
{
int j;
const tr_tier* const tier = &tt->tiers[i];
tr_tier const* const tier = &tt->tiers[i];
for (j = 0; j < tier->tracker_count; ++j)
{
const tr_tracker* const tracker = &tier->trackers[j];
tr_tracker const* const tracker = &tier->trackers[j];
tr_tracker_stat* st = &ret[out++];
st->id = tracker->id;
@ -1795,9 +1795,9 @@ void tr_announcerStatsFree(tr_tracker_stat* trackers, int trackerCount UNUSED)
****
***/
static void copy_tier_attributes_impl(struct tr_tier* tgt, int trackerIndex, const tr_tier* src)
static void copy_tier_attributes_impl(struct tr_tier* tgt, int trackerIndex, tr_tier const* src)
{
const tr_tier keep = *tgt;
tr_tier const keep = *tgt;
/* sanity clause */
assert(trackerIndex < tgt->tracker_count);
@ -1821,7 +1821,7 @@ static void copy_tier_attributes_impl(struct tr_tier* tgt, int trackerIndex, con
tgt->currentTracker->downloaderCount = src->currentTracker->downloaderCount;
}
static void copy_tier_attributes(struct tr_torrent_tiers* tt, const tr_tier* src)
static void copy_tier_attributes(struct tr_torrent_tiers* tt, tr_tier const* src)
{
int i, j;
bool found = false;
@ -1842,7 +1842,7 @@ static void copy_tier_attributes(struct tr_torrent_tiers* tt, const tr_tier* src
void tr_announcerResetTorrent(tr_announcer* announcer UNUSED, tr_torrent* tor)
{
int i;
const time_t now = tr_time();
time_t const now = tr_time();
struct tr_torrent_tiers* tt = tor->tiers;
tr_torrent_tiers old = *tt;

View File

@ -39,11 +39,11 @@ typedef struct
TrackerEventType messageType;
/* for TR_TRACKER_WARNING and TR_TRACKER_ERROR */
const char* text;
const char* tracker;
char const* text;
char const* tracker;
/* for TR_TRACKER_PEERS */
const struct tr_pex* pex;
struct tr_pex const* pex;
size_t pexCount;
/* [0...100] for probability a peer is a seed. calculated by the leecher/seeder ratio */
@ -51,7 +51,7 @@ typedef struct
}
tr_tracker_event;
typedef void (* tr_tracker_callback)(tr_torrent* tor, const tr_tracker_event* event, void* client_data);
typedef void (* tr_tracker_callback)(tr_torrent* tor, tr_tracker_event const* event, void* client_data);
/**
*** Session ctor/dtor
@ -67,7 +67,7 @@ void tr_announcerClose(tr_session*);
struct tr_torrent_tiers* tr_announcerAddTorrent(tr_torrent* torrent, tr_tracker_callback cb, void* cbdata);
bool tr_announcerHasBacklog(const struct tr_announcer*);
bool tr_announcerHasBacklog(struct tr_announcer const*);
void tr_announcerResetTorrent(struct tr_announcer*, tr_torrent*);
@ -75,7 +75,7 @@ void tr_announcerRemoveTorrent(struct tr_announcer*, tr_torrent*);
void tr_announcerChangeMyPort(tr_torrent*);
bool tr_announcerCanManualAnnounce(const tr_torrent*);
bool tr_announcerCanManualAnnounce(tr_torrent const*);
void tr_announcerManualAnnounce(tr_torrent*);
@ -92,9 +92,9 @@ enum
void tr_announcerAddBytes(tr_torrent*, int up_down_or_corrupt, uint32_t byteCount);
time_t tr_announcerNextManualAnnounce(const tr_torrent*);
time_t tr_announcerNextManualAnnounce(tr_torrent const*);
tr_tracker_stat* tr_announcerStats(const tr_torrent* torrent, int* setmeTrackerCount);
tr_tracker_stat* tr_announcerStats(tr_torrent const* torrent, int* setmeTrackerCount);
void tr_announcerStatsFree(tr_tracker_stat* trackers, int trackerCount);
@ -106,4 +106,4 @@ void tr_tracker_udp_upkeep(tr_session* session);
void tr_tracker_udp_close(tr_session* session);
bool tr_tracker_udp_is_idle(const tr_session* session);
bool tr_tracker_udp_is_idle(tr_session const* session);

View File

@ -30,7 +30,7 @@
****
***/
static unsigned int getSpeed_Bps(const struct bratecontrol* r, unsigned int interval_msec, uint64_t now)
static unsigned int getSpeed_Bps(struct bratecontrol const* r, unsigned int interval_msec, uint64_t now)
{
if (!now)
{
@ -41,7 +41,7 @@ static unsigned int getSpeed_Bps(const struct bratecontrol* r, unsigned int inte
{
int i = r->newest;
uint64_t bytes = 0;
const uint64_t cutoff = now - interval_msec;
uint64_t const cutoff = now - interval_msec;
struct bratecontrol* rvolatile = (struct bratecontrol*)r;
for (;;)
@ -71,7 +71,7 @@ static unsigned int getSpeed_Bps(const struct bratecontrol* r, unsigned int inte
return r->cache_val;
}
static void bytesUsed(const uint64_t now, struct bratecontrol* r, size_t size)
static void bytesUsed(uint64_t const now, struct bratecontrol* r, size_t size)
{
if (r->transfers[r->newest].date + GRANULARITY_MSEC >= now)
{
@ -97,10 +97,10 @@ static void bytesUsed(const uint64_t now, struct bratecontrol* r, size_t size)
*******
******/
static int compareBandwidth(const void* va, const void* vb)
static int compareBandwidth(void const* va, void const* vb)
{
const tr_bandwidth* a = va;
const tr_bandwidth* b = vb;
tr_bandwidth const* a = va;
tr_bandwidth const* b = vb;
return a->uniqueKey - b->uniqueKey;
}
@ -166,7 +166,7 @@ void tr_bandwidthSetParent(tr_bandwidth* b, tr_bandwidth* parent)
static void allocateBandwidth(tr_bandwidth* b, tr_priority_t parent_priority, tr_direction dir, unsigned int period_msec,
tr_ptrArray* peer_pool)
{
const tr_priority_t priority = MAX(parent_priority, b->priority);
tr_priority_t const priority = MAX(parent_priority, b->priority);
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));
@ -174,7 +174,7 @@ static void allocateBandwidth(tr_bandwidth* b, tr_priority_t parent_priority, tr
/* set the available bandwidth */
if (b->band[dir].isLimited)
{
const uint64_t nextPulseSpeed = b->band[dir].desiredSpeed_Bps;
uint64_t const nextPulseSpeed = b->band[dir].desiredSpeed_Bps;
b->band[dir].bytesLeft = nextPulseSpeed * period_msec / 1000u;
}
@ -190,7 +190,7 @@ static void allocateBandwidth(tr_bandwidth* b, tr_priority_t parent_priority, tr
{
int i;
struct tr_bandwidth** children = (struct tr_bandwidth**)tr_ptrArrayBase(&b->children);
const int n = tr_ptrArraySize(&b->children);
int const n = tr_ptrArraySize(&b->children);
for (i = 0; i < n; ++i)
{
@ -214,14 +214,14 @@ static void phaseOne(tr_ptrArray* peerArray, tr_direction dir)
while (n > 0)
{
const int i = tr_rand_int_weak(n); /* pick a peer at random */
int const i = tr_rand_int_weak(n); /* pick a peer at random */
/* value of 3000 bytes chosen so that when using uTP we'll send a full-size
* frame right away and leave enough buffered data for the next frame to go
* out in a timely manner. */
const size_t increment = 3000;
size_t const increment = 3000;
const int bytesUsed = tr_peerIoFlush(peers[i], dir, increment);
int const bytesUsed = tr_peerIoFlush(peers[i], dir, increment);
dbgmsg("peer #%d of %d used %d bytes in this pass", i, n, bytesUsed);
@ -313,7 +313,7 @@ void tr_bandwidthSetPeer(tr_bandwidth* b, tr_peerIo* peer)
****
***/
static unsigned int bandwidthClamp(const tr_bandwidth* b, uint64_t now, tr_direction dir, unsigned int byteCount)
static unsigned int bandwidthClamp(tr_bandwidth const* b, uint64_t now, tr_direction dir, unsigned int byteCount)
{
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));
@ -365,12 +365,12 @@ static unsigned int bandwidthClamp(const tr_bandwidth* b, uint64_t now, tr_direc
return byteCount;
}
unsigned int tr_bandwidthClamp(const tr_bandwidth* b, tr_direction dir, unsigned int byteCount)
unsigned int tr_bandwidthClamp(tr_bandwidth const* b, tr_direction dir, unsigned int byteCount)
{
return bandwidthClamp(b, 0, dir, byteCount);
}
unsigned int tr_bandwidthGetRawSpeed_Bps(const tr_bandwidth* b, const uint64_t now, const tr_direction dir)
unsigned int tr_bandwidthGetRawSpeed_Bps(tr_bandwidth const* b, uint64_t const now, tr_direction const dir)
{
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));
@ -378,7 +378,7 @@ unsigned int tr_bandwidthGetRawSpeed_Bps(const tr_bandwidth* b, const uint64_t n
return getSpeed_Bps(&b->band[dir].raw, HISTORY_MSEC, now);
}
unsigned int tr_bandwidthGetPieceSpeed_Bps(const tr_bandwidth* b, const uint64_t now, const tr_direction dir)
unsigned int tr_bandwidthGetPieceSpeed_Bps(tr_bandwidth const* b, uint64_t const now, tr_direction const dir)
{
assert(tr_isBandwidth(b));
assert(tr_isDirection(dir));

View File

@ -126,7 +126,7 @@ void tr_bandwidthConstruct(tr_bandwidth* bandwidth, tr_session* session, tr_band
void tr_bandwidthDestruct(tr_bandwidth* bandwidth);
/** @brief test to see if the pointer refers to a live bandwidth object */
static inline bool tr_isBandwidth(const tr_bandwidth* b)
static inline bool tr_isBandwidth(tr_bandwidth const* b)
{
return (b != NULL) && (b->magicNumber == BANDWIDTH_MAGIC_NUMBER);
}
@ -143,7 +143,7 @@ static inline bool tr_isBandwidth(const tr_bandwidth* b)
static inline bool tr_bandwidthSetDesiredSpeed_Bps(tr_bandwidth* bandwidth, tr_direction dir, unsigned int desiredSpeed)
{
unsigned int* value = &bandwidth->band[dir].desiredSpeed_Bps;
const bool didChange = desiredSpeed != *value;
bool const didChange = desiredSpeed != *value;
*value = desiredSpeed;
return didChange;
}
@ -152,7 +152,7 @@ static inline bool tr_bandwidthSetDesiredSpeed_Bps(tr_bandwidth* bandwidth, tr_d
* @brief Get the desired speed for the bandwidth subtree.
* @see tr_bandwidthSetDesiredSpeed
*/
static inline double tr_bandwidthGetDesiredSpeed_Bps(const tr_bandwidth* bandwidth, tr_direction dir)
static inline double tr_bandwidthGetDesiredSpeed_Bps(tr_bandwidth const* bandwidth, tr_direction dir)
{
return bandwidth->band[dir].desiredSpeed_Bps;
}
@ -163,7 +163,7 @@ static inline double tr_bandwidthGetDesiredSpeed_Bps(const tr_bandwidth* bandwid
static inline bool tr_bandwidthSetLimited(tr_bandwidth* bandwidth, tr_direction dir, bool isLimited)
{
bool* value = &bandwidth->band[dir].isLimited;
const bool didChange = isLimited != *value;
bool const didChange = isLimited != *value;
*value = isLimited;
return didChange;
}
@ -171,7 +171,7 @@ static inline bool tr_bandwidthSetLimited(tr_bandwidth* bandwidth, tr_direction
/**
* @return nonzero if this bandwidth throttles its peer-ios speeds
*/
static inline bool tr_bandwidthIsLimited(const tr_bandwidth* bandwidth, tr_direction dir)
static inline bool tr_bandwidthIsLimited(tr_bandwidth const* bandwidth, tr_direction dir)
{
return bandwidth->band[dir].isLimited;
}
@ -184,17 +184,17 @@ void tr_bandwidthAllocate(tr_bandwidth* bandwidth, tr_direction direction, unsig
/**
* @brief clamps byteCount down to a number that this bandwidth will allow to be consumed
*/
unsigned int tr_bandwidthClamp(const tr_bandwidth* bandwidth, tr_direction direction, unsigned int byteCount);
unsigned int tr_bandwidthClamp(tr_bandwidth const* bandwidth, tr_direction direction, unsigned int byteCount);
/******
*******
******/
/** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */
unsigned int tr_bandwidthGetRawSpeed_Bps(const tr_bandwidth* bandwidth, const uint64_t now, const tr_direction direction);
unsigned int tr_bandwidthGetRawSpeed_Bps(tr_bandwidth const* bandwidth, uint64_t const now, tr_direction const direction);
/** @brief Get the number of piece data bytes read or sent by this bandwidth subtree. */
unsigned int tr_bandwidthGetPieceSpeed_Bps(const tr_bandwidth* bandwidth, const uint64_t now, const tr_direction direction);
unsigned int tr_bandwidthGetPieceSpeed_Bps(tr_bandwidth const* bandwidth, uint64_t const now, tr_direction const direction);
/**
* @brief Notify the bandwidth object that some of its allocated bandwidth has been consumed.
@ -217,12 +217,12 @@ void tr_bandwidthSetParent(tr_bandwidth* bandwidth, tr_bandwidth* parent);
static inline bool tr_bandwidthHonorParentLimits(tr_bandwidth* bandwidth, tr_direction direction, bool isEnabled)
{
bool* value = &bandwidth->band[direction].honorParentLimits;
const bool didChange = isEnabled != *value;
bool const didChange = isEnabled != *value;
*value = isEnabled;
return didChange;
}
static inline bool tr_bandwidthAreParentLimitsHonored(const tr_bandwidth* bandwidth, tr_direction direction)
static inline bool tr_bandwidthAreParentLimitsHonored(tr_bandwidth const* bandwidth, tr_direction direction)
{
assert(tr_isBandwidth(bandwidth));
assert(tr_isDirection(direction));

View File

@ -22,7 +22,7 @@ static int test_bitfield_count_range(void)
int end;
int count1;
int count2;
const int bitCount = 100 + tr_rand_int_weak(1000);
int const bitCount = 100 + tr_rand_int_weak(1000);
tr_bitfield bf;
/* generate a random bitfield */
@ -44,7 +44,7 @@ static int test_bitfield_count_range(void)
/* ensure end <= begin */
if (end < begin)
{
const int tmp = begin;
int const tmp = begin;
begin = end;
end = tmp;
}
@ -228,7 +228,7 @@ int main(void)
{
int l;
int ret;
const testFunc tests[] =
testFunc const tests[] =
{
test_bitfields,
test_bitfield_has_all_none

View File

@ -13,13 +13,13 @@
#include "bitfield.h"
#include "utils.h" /* tr_new0 () */
const tr_bitfield TR_BITFIELD_INIT = { NULL, 0, 0, 0, false, false };
tr_bitfield const TR_BITFIELD_INIT = { NULL, 0, 0, 0, false, false };
/****
*****
****/
static const int8_t trueBitCount[256] =
static int8_t const trueBitCount[256] =
{
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
@ -39,7 +39,7 @@ static const int8_t trueBitCount[256] =
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
};
static size_t countArray(const tr_bitfield* b)
static size_t countArray(tr_bitfield const* b)
{
size_t ret = 0;
size_t i = b->alloc_count;
@ -52,11 +52,11 @@ static size_t countArray(const tr_bitfield* b)
return ret;
}
static size_t countRange(const tr_bitfield* b, size_t begin, size_t end)
static size_t countRange(tr_bitfield const* b, size_t begin, size_t end)
{
size_t ret = 0;
const size_t first_byte = begin >> 3u;
const size_t last_byte = (end - 1) >> 3u;
size_t const first_byte = begin >> 3u;
size_t const last_byte = (end - 1) >> 3u;
if (!b->bit_count)
{
@ -89,7 +89,7 @@ static size_t countRange(const tr_bitfield* b, size_t begin, size_t end)
{
size_t i;
uint8_t val;
const size_t walk_end = MIN(b->alloc_count, last_byte);
size_t const walk_end = MIN(b->alloc_count, last_byte);
/* first byte */
i = begin - (first_byte * 8);
@ -119,7 +119,7 @@ static size_t countRange(const tr_bitfield* b, size_t begin, size_t end)
return ret;
}
size_t tr_bitfieldCountRange(const tr_bitfield* b, size_t begin, size_t end)
size_t tr_bitfieldCountRange(tr_bitfield const* b, size_t begin, size_t end)
{
if (tr_bitfieldHasAll(b))
{
@ -134,7 +134,7 @@ size_t tr_bitfieldCountRange(const tr_bitfield* b, size_t begin, size_t end)
return countRange(b, begin, end);
}
bool tr_bitfieldHas(const tr_bitfield* b, size_t n)
bool tr_bitfieldHas(tr_bitfield const* b, size_t n)
{
if (tr_bitfieldHasAll(b))
{
@ -160,7 +160,7 @@ bool tr_bitfieldHas(const tr_bitfield* b, size_t n)
#ifndef NDEBUG
static bool tr_bitfieldIsValid(const tr_bitfield* b)
static bool tr_bitfieldIsValid(tr_bitfield const* b)
{
assert(b != NULL);
assert((b->alloc_count == 0) == (b->bits == 0));
@ -171,7 +171,7 @@ static bool tr_bitfieldIsValid(const tr_bitfield* b)
#endif
size_t tr_bitfieldCountTrueBits(const tr_bitfield* b)
size_t tr_bitfieldCountTrueBits(tr_bitfield const* b)
{
assert(tr_bitfieldIsValid(b));
@ -185,8 +185,8 @@ static size_t get_bytes_needed(size_t bit_count)
static void set_all_true(uint8_t* array, size_t bit_count)
{
const uint8_t val = 0xFF;
const size_t n = get_bytes_needed(bit_count);
uint8_t const val = 0xFF;
size_t const n = get_bytes_needed(bit_count);
if (n > 0)
{
@ -196,9 +196,9 @@ static void set_all_true(uint8_t* array, size_t bit_count)
}
}
void* tr_bitfieldGetRaw(const tr_bitfield* b, size_t* byte_count)
void* tr_bitfieldGetRaw(tr_bitfield const* b, size_t* byte_count)
{
const size_t n = get_bytes_needed(b->bit_count);
size_t const n = get_bytes_needed(b->bit_count);
uint8_t* bits = tr_new0(uint8_t, n);
assert(b->bit_count > 0);
@ -220,7 +220,7 @@ void* tr_bitfieldGetRaw(const tr_bitfield* b, size_t* byte_count)
static void tr_bitfieldEnsureBitsAlloced(tr_bitfield* b, size_t n)
{
size_t bytes_needed;
const bool has_all = tr_bitfieldHasAll(b);
bool const has_all = tr_bitfieldHasAll(b);
if (has_all)
{
@ -335,7 +335,7 @@ void tr_bitfieldSetHasAll(tr_bitfield* b)
assert(tr_bitfieldIsValid(b));
}
void tr_bitfieldSetFromBitfield(tr_bitfield* b, const tr_bitfield* src)
void tr_bitfieldSetFromBitfield(tr_bitfield* b, tr_bitfield const* src)
{
if (tr_bitfieldHasAll(src))
{
@ -351,7 +351,7 @@ void tr_bitfieldSetFromBitfield(tr_bitfield* b, const tr_bitfield* src)
}
}
void tr_bitfieldSetRaw(tr_bitfield* b, const void* bits, size_t byte_count, bool bounded)
void tr_bitfieldSetRaw(tr_bitfield* b, void const* bits, size_t byte_count, bool bounded)
{
tr_bitfieldFreeArray(b);
b->true_count = 0;
@ -367,7 +367,7 @@ void tr_bitfieldSetRaw(tr_bitfield* b, const void* bits, size_t byte_count, bool
if (bounded)
{
/* ensure the excess bits are set to '0' */
const int excess_bit_count = byte_count * 8 - b->bit_count;
int const excess_bit_count = byte_count * 8 - b->bit_count;
assert(excess_bit_count >= 0);
assert(excess_bit_count <= 7);
@ -380,7 +380,7 @@ void tr_bitfieldSetRaw(tr_bitfield* b, const void* bits, size_t byte_count, bool
tr_bitfieldRebuildTrueCount(b);
}
void tr_bitfieldSetFromFlags(tr_bitfield* b, const bool* flags, size_t n)
void tr_bitfieldSetFromFlags(tr_bitfield* b, bool const* flags, size_t n)
{
size_t i;
size_t trueCount = 0;
@ -414,7 +414,7 @@ void tr_bitfieldAddRange(tr_bitfield* b, size_t begin, size_t end)
{
size_t sb, eb;
unsigned char sm, em;
const size_t diff = (end - begin) - tr_bitfieldCountRange(b, begin, end);
size_t const diff = (end - begin) - tr_bitfieldCountRange(b, begin, end);
if (diff == 0)
{
@ -472,7 +472,7 @@ void tr_bitfieldRemRange(tr_bitfield* b, size_t begin, size_t end)
{
size_t sb, eb;
unsigned char sm, em;
const size_t diff = tr_bitfieldCountRange(b, begin, end);
size_t const diff = tr_bitfieldCountRange(b, begin, end);
if (!diff)
{

View File

@ -51,7 +51,7 @@ void tr_bitfieldRemRange(tr_bitfield*, size_t begin, size_t end);
**** life cycle
***/
extern const tr_bitfield TR_BITFIELD_INIT;
extern tr_bitfield const TR_BITFIELD_INIT;
void tr_bitfieldConstruct(tr_bitfield*, size_t bit_count);
@ -64,30 +64,30 @@ static inline void tr_bitfieldDestruct(tr_bitfield* b)
****
***/
void tr_bitfieldSetFromFlags(tr_bitfield*, const bool* bytes, size_t n);
void tr_bitfieldSetFromFlags(tr_bitfield*, bool const* bytes, size_t n);
void tr_bitfieldSetFromBitfield(tr_bitfield*, const tr_bitfield*);
void tr_bitfieldSetFromBitfield(tr_bitfield*, tr_bitfield const*);
void tr_bitfieldSetRaw(tr_bitfield*, const void* bits, size_t byte_count, bool bounded);
void tr_bitfieldSetRaw(tr_bitfield*, void const* bits, size_t byte_count, bool bounded);
void* tr_bitfieldGetRaw(const tr_bitfield* b, size_t* byte_count);
void* tr_bitfieldGetRaw(tr_bitfield const* b, size_t* byte_count);
/***
****
***/
size_t tr_bitfieldCountRange(const tr_bitfield*, size_t begin, size_t end);
size_t tr_bitfieldCountRange(tr_bitfield const*, size_t begin, size_t end);
size_t tr_bitfieldCountTrueBits(const tr_bitfield* b);
size_t tr_bitfieldCountTrueBits(tr_bitfield const* b);
static inline bool tr_bitfieldHasAll(const tr_bitfield* b)
static inline bool tr_bitfieldHasAll(tr_bitfield const* b)
{
return b->bit_count ? (b->true_count == b->bit_count) : b->have_all_hint;
}
static inline bool tr_bitfieldHasNone(const tr_bitfield* b)
static inline bool tr_bitfieldHasNone(tr_bitfield const* b)
{
return b->bit_count ? (b->true_count == 0) : b->have_none_hint;
}
bool tr_bitfieldHas(const tr_bitfield* b, size_t n);
bool tr_bitfieldHas(tr_bitfield const* b, size_t n);

View File

@ -19,20 +19,20 @@
#include "libtransmission-test.h"
static const char* contents1 =
static char const* contents1 =
"Austin Law Firm:216.16.1.144-216.16.1.151\n"
"Sargent Controls and Aerospace:216.19.18.0-216.19.18.255\n"
"Corel Corporation:216.21.157.192-216.21.157.223\n"
"Fox Speed Channel:216.79.131.192-216.79.131.223\n";
static const char* contents2 =
static char const* contents2 =
"Austin Law Firm:216.16.1.144-216.16.1.151\n"
"Sargent Controls and Aerospace:216.19.18.0-216.19.18.255\n"
"Corel Corporation:216.21.157.192-216.21.157.223\n"
"Fox Speed Channel:216.79.131.192-216.79.131.223\n"
"Evilcorp:216.88.88.0-216.88.88.255\n";
static void create_text_file(const char* path, const char* contents)
static void create_text_file(char const* path, char const* contents)
{
tr_sys_file_t fd;
char* dir;
@ -48,7 +48,7 @@ static void create_text_file(const char* path, const char* contents)
libttest_sync();
}
static bool address_is_blocked(tr_session* session, const char* address_str)
static bool address_is_blocked(tr_session* session, char const* address_str)
{
struct tr_address addr;
tr_address_from_string(&addr, address_str);
@ -146,7 +146,7 @@ static int test_updating(void)
int main(void)
{
const testFunc tests[] =
testFunc const tests[] =
{
test_parsing,
test_updating

View File

@ -60,7 +60,7 @@ static void blocklistLoad(tr_blocklistFile* b)
tr_sys_path_info info;
char* base;
tr_error* error = NULL;
const char* err_fmt = _("Couldn't read \"%1$s\": %2$s");
char const* err_fmt = _("Couldn't read \"%1$s\": %2$s");
blocklistClose(b);
@ -112,10 +112,10 @@ static void blocklistEnsureLoaded(tr_blocklistFile* b)
}
}
static int compareAddressToRange(const void* va, const void* vb)
static int compareAddressToRange(void const* va, void const* vb)
{
const uint32_t* a = va;
const struct tr_ipv4_range* b = vb;
uint32_t const* a = va;
struct tr_ipv4_range const* b = vb;
if (*a < b->begin)
{
@ -140,7 +140,7 @@ static void blocklistDelete(tr_blocklistFile* b)
**** PACKAGE-VISIBLE
***/
tr_blocklistFile* tr_blocklistFileNew(const char* filename, bool isEnabled)
tr_blocklistFile* tr_blocklistFileNew(char const* filename, bool isEnabled)
{
tr_blocklistFile* b;
@ -152,7 +152,7 @@ tr_blocklistFile* tr_blocklistFileNew(const char* filename, bool isEnabled)
return b;
}
const char* tr_blocklistFileGetFilename(const tr_blocklistFile* b)
char const* tr_blocklistFileGetFilename(tr_blocklistFile const* b)
{
return b->filename;
}
@ -164,12 +164,12 @@ void tr_blocklistFileFree(tr_blocklistFile* b)
tr_free(b);
}
bool tr_blocklistFileExists(const tr_blocklistFile* b)
bool tr_blocklistFileExists(tr_blocklistFile const* b)
{
return tr_sys_path_exists(b->filename, NULL);
}
int tr_blocklistFileGetRuleCount(const tr_blocklistFile* b)
int tr_blocklistFileGetRuleCount(tr_blocklistFile const* b)
{
blocklistEnsureLoaded((tr_blocklistFile*)b);
@ -189,10 +189,10 @@ void tr_blocklistFileSetEnabled(tr_blocklistFile* b, bool isEnabled)
b->isEnabled = isEnabled;
}
bool tr_blocklistFileHasAddress(tr_blocklistFile* b, const tr_address* addr)
bool tr_blocklistFileHasAddress(tr_blocklistFile* b, tr_address const* addr)
{
uint32_t needle;
const struct tr_ipv4_range* range;
struct tr_ipv4_range const* range;
assert(tr_address_is_valid(addr));
@ -220,7 +220,7 @@ bool tr_blocklistFileHasAddress(tr_blocklistFile* b, const tr_address* addr)
* http://wiki.phoenixlabs.org/wiki/P2P_Format
* http://en.wikipedia.org/wiki/PeerGuardian#P2P_plaintext_format
*/
static bool parseLine1(const char* line, struct tr_ipv4_range* range)
static bool parseLine1(char const* line, struct tr_ipv4_range* range)
{
char* walk;
int b[4];
@ -267,7 +267,7 @@ static bool parseLine1(const char* line, struct tr_ipv4_range* range)
* DAT format: "000.000.000.000 - 000.255.255.255 , 000 , invalid ip"
* http://wiki.phoenixlabs.org/wiki/DAT_Format
*/
static bool parseLine2(const char* line, struct tr_ipv4_range* range)
static bool parseLine2(char const* line, struct tr_ipv4_range* range)
{
int unk;
int a[4];
@ -302,15 +302,15 @@ static bool parseLine2(const char* line, struct tr_ipv4_range* range)
return true;
}
static bool parseLine(const char* line, struct tr_ipv4_range* range)
static bool parseLine(char const* line, struct tr_ipv4_range* range)
{
return parseLine1(line, range) || parseLine2(line, range);
}
static int compareAddressRangesByFirstAddress(const void* va, const void* vb)
static int compareAddressRangesByFirstAddress(void const* va, void const* vb)
{
const struct tr_ipv4_range* a = va;
const struct tr_ipv4_range* b = vb;
struct tr_ipv4_range const* a = va;
struct tr_ipv4_range const* b = vb;
if (a->begin != b->begin)
{
@ -320,13 +320,13 @@ static int compareAddressRangesByFirstAddress(const void* va, const void* vb)
return 0;
}
int tr_blocklistFileSetContent(tr_blocklistFile* b, const char* filename)
int tr_blocklistFileSetContent(tr_blocklistFile* b, char const* filename)
{
tr_sys_file_t in;
tr_sys_file_t out;
int inCount = 0;
char line[2048];
const char* err_fmt = _("Couldn't read \"%1$s\": %2$s");
char const* err_fmt = _("Couldn't read \"%1$s\": %2$s");
struct tr_ipv4_range* ranges = NULL;
size_t ranges_alloc = 0;
size_t ranges_count = 0;
@ -386,7 +386,7 @@ int tr_blocklistFileSetContent(tr_blocklistFile* b, const char* filename)
{
struct tr_ipv4_range* r;
struct tr_ipv4_range* keep = ranges;
const struct tr_ipv4_range* end;
struct tr_ipv4_range const* end;
/* sort */
qsort(ranges, ranges_count, sizeof(struct tr_ipv4_range), compareAddressRangesByFirstAddress);

View File

@ -16,13 +16,13 @@ struct tr_address;
typedef struct tr_blocklistFile tr_blocklistFile;
tr_blocklistFile* tr_blocklistFileNew(const char* filename, bool isEnabled);
tr_blocklistFile* tr_blocklistFileNew(char const* filename, bool isEnabled);
bool tr_blocklistFileExists(const tr_blocklistFile* b);
bool tr_blocklistFileExists(tr_blocklistFile const* b);
const char* tr_blocklistFileGetFilename(const tr_blocklistFile* b);
char const* tr_blocklistFileGetFilename(tr_blocklistFile const* b);
int tr_blocklistFileGetRuleCount(const tr_blocklistFile* b);
int tr_blocklistFileGetRuleCount(tr_blocklistFile const* b);
void tr_blocklistFileFree(tr_blocklistFile* b);
@ -30,6 +30,6 @@ bool tr_blocklistFileIsEnabled(tr_blocklistFile* b);
void tr_blocklistFileSetEnabled(tr_blocklistFile* b, bool isEnabled);
bool tr_blocklistFileHasAddress(tr_blocklistFile* b, const struct tr_address* addr);
bool tr_blocklistFileHasAddress(tr_blocklistFile* b, struct tr_address const* addr);
int tr_blocklistFileSetContent(tr_blocklistFile* b, const char* filename);
int tr_blocklistFileSetContent(tr_blocklistFile* b, char const* filename);

View File

@ -77,17 +77,17 @@ struct run_info
};
/* return a count of how many contiguous blocks there are starting at this pos */
static int getBlockRun(const tr_cache* cache, int pos, struct run_info* info)
static int getBlockRun(tr_cache const* cache, int pos, struct run_info* info)
{
int i;
const int n = tr_ptrArraySize(&cache->blocks);
const struct cache_block* const* blocks = (const struct cache_block* const*)tr_ptrArrayBase(&cache->blocks);
const struct cache_block* ref = blocks[pos];
int const n = tr_ptrArraySize(&cache->blocks);
struct cache_block const* const* blocks = (struct cache_block const* const*)tr_ptrArrayBase(&cache->blocks);
struct cache_block const* ref = blocks[pos];
tr_block_index_t block = ref->block;
for (i = pos; i < n; ++i, ++block)
{
const struct cache_block* b = blocks[i];
struct cache_block const* b = blocks[i];
if (b->block != block)
{
@ -106,7 +106,7 @@ static int getBlockRun(const tr_cache* cache, int pos, struct run_info* info)
if (info != NULL)
{
const struct cache_block* b = blocks[i - 1];
struct cache_block const* b = blocks[i - 1];
info->last_block_time = b->time;
info->is_piece_done = tr_torrentPieceIsComplete(b->tor, b->piece);
info->is_multi_piece = b->piece != blocks[pos]->piece;
@ -118,10 +118,10 @@ static int getBlockRun(const tr_cache* cache, int pos, struct run_info* info)
}
/* higher rank comes before lower rank */
static int compareRuns(const void* va, const void* vb)
static int compareRuns(void const* va, void const* vb)
{
const struct run_info* a = va;
const struct run_info* b = vb;
struct run_info const* a = va;
struct run_info const* b = vb;
return b->rank - a->rank;
}
@ -138,9 +138,9 @@ enum
*/
static int calcRuns(tr_cache* cache, struct run_info* runs)
{
const int n = tr_ptrArraySize(&cache->blocks);
int const n = tr_ptrArraySize(&cache->blocks);
int i = 0, pos;
const time_t now = tr_time();
time_t const now = tr_time();
for (pos = 0; pos < n; pos += runs[i++].len)
{
@ -179,8 +179,8 @@ static int flushContiguous(tr_cache* cache, int pos, int n)
struct cache_block* b = blocks[pos];
tr_torrent* tor = b->tor;
const tr_piece_index_t piece = b->piece;
const uint32_t offset = b->offset;
tr_piece_index_t const piece = b->piece;
uint32_t const offset = b->offset;
for (i = pos; i < pos + n; ++i)
{
@ -232,7 +232,7 @@ static int cacheTrim(tr_cache* cache)
{
/* Amount of cache that should be removed by the flush. This influences how large
* runs can grow as well as how often flushes will happen. */
const int cacheCutoff = 1 + cache->max_blocks / 4;
int const cacheCutoff = 1 + cache->max_blocks / 4;
struct run_info* runs = tr_new(struct run_info, tr_ptrArraySize(&cache->blocks));
int i = 0, j = 0;
@ -272,7 +272,7 @@ int tr_cacheSetLimit(tr_cache* cache, int64_t max_bytes)
return cacheTrim(cache);
}
int64_t tr_cacheGetLimit(const tr_cache* cache)
int64_t tr_cacheGetLimit(tr_cache const* cache)
{
return cache->max_bytes;
}
@ -297,10 +297,10 @@ void tr_cacheFree(tr_cache* cache)
****
***/
static int cache_block_compare(const void* va, const void* vb)
static int cache_block_compare(void const* va, void const* vb)
{
const struct cache_block* a = va;
const struct cache_block* b = vb;
struct cache_block const* a = va;
struct cache_block const* b = vb;
/* primary key: torrent id */
if (a->tor->uniqueId != b->tor->uniqueId)
@ -439,7 +439,7 @@ int tr_cacheFlushFile(tr_cache* cache, tr_torrent* torrent, tr_file_index_t i)
/* flush out all the blocks in that file */
while (!err && (pos < tr_ptrArraySize(&cache->blocks)))
{
const struct cache_block* b = tr_ptrArrayNth(&cache->blocks, pos);
struct cache_block const* b = tr_ptrArrayNth(&cache->blocks, pos);
if (b->tor != torrent)
{
@ -460,12 +460,12 @@ int tr_cacheFlushFile(tr_cache* cache, tr_torrent* torrent, tr_file_index_t i)
int tr_cacheFlushTorrent(tr_cache* cache, tr_torrent* torrent)
{
int err = 0;
const int pos = findBlockPos(cache, torrent, 0);
int const pos = findBlockPos(cache, torrent, 0);
/* flush out all the blocks in that torrent */
while (!err && (pos < tr_ptrArraySize(&cache->blocks)))
{
const struct cache_block* b = tr_ptrArrayNth(&cache->blocks, pos);
struct cache_block const* b = tr_ptrArrayNth(&cache->blocks, pos);
if (b->tor != torrent)
{

View File

@ -30,7 +30,7 @@ void tr_cacheFree(tr_cache*);
int tr_cacheSetLimit(tr_cache* cache, int64_t max_bytes);
int64_t tr_cacheGetLimit(const tr_cache*);
int64_t tr_cacheGetLimit(tr_cache const*);
int tr_cacheWriteBlock(tr_cache* cache, tr_torrent* torrent, tr_piece_index_t piece, uint32_t offset, uint32_t len,
struct evbuffer* writeme);

View File

@ -38,8 +38,8 @@ static int charint(uint8_t ch)
static bool getShadowInt(uint8_t ch, int* setme)
{
const char* str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
const char* pch = strchr(str, ch);
char const* str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-";
char const* pch = strchr(str, ch);
if (!pch)
{
@ -50,7 +50,7 @@ static bool getShadowInt(uint8_t ch, int* setme)
return true;
}
static int strint(const void* pch, int span)
static int strint(void const* pch, int span)
{
char tmp[64];
memcpy(tmp, pch, span);
@ -58,7 +58,7 @@ static int strint(const void* pch, int span)
return strtol(tmp, NULL, 0);
}
static const char* getMnemonicEnd(uint8_t ch)
static char const* getMnemonicEnd(uint8_t ch)
{
switch (ch)
{
@ -79,28 +79,28 @@ static const char* getMnemonicEnd(uint8_t ch)
}
}
static void three_digits(char* buf, size_t buflen, const char* name, const uint8_t* digits)
static void three_digits(char* buf, size_t buflen, char const* name, uint8_t const* digits)
{
tr_snprintf(buf, buflen, "%s %d.%d.%d", name, charint(digits[0]), charint(digits[1]), charint(digits[2]));
}
static void four_digits(char* buf, size_t buflen, const char* name, const uint8_t* digits)
static void four_digits(char* buf, size_t buflen, char const* name, uint8_t const* digits)
{
tr_snprintf(buf, buflen, "%s %d.%d.%d.%d", name, charint(digits[0]), charint(digits[1]), charint(digits[2]),
charint(digits[3]));
}
static void two_major_two_minor(char* buf, size_t buflen, const char* name, const uint8_t* digits)
static void two_major_two_minor(char* buf, size_t buflen, char const* name, uint8_t const* digits)
{
tr_snprintf(buf, buflen, "%s %d.%02d", name, strint(digits, 2), strint(digits + 2, 2));
}
static void no_version(char* buf, size_t buflen, const char* name)
static void no_version(char* buf, size_t buflen, char const* name)
{
tr_strlcpy(buf, name, buflen);
}
static void mainline_style(char* buf, size_t buflen, const char* name, const uint8_t* id)
static void mainline_style(char* buf, size_t buflen, char const* name, uint8_t const* id)
{
if (id[4] == '-' && id[6] == '-')
{
@ -112,7 +112,7 @@ static void mainline_style(char* buf, size_t buflen, const char* name, const uin
}
}
static bool isMainlineStyle(const uint8_t* peer_id)
static bool isMainlineStyle(uint8_t const* peer_id)
{
/**
* One of the following styles will be used:
@ -122,13 +122,13 @@ static bool isMainlineStyle(const uint8_t* peer_id)
return peer_id[2] == '-' && peer_id[7] == '-' && (peer_id[4] == '-' || peer_id[5] == '-');
}
static bool decodeBitCometClient(char* buf, size_t buflen, const uint8_t* id)
static bool decodeBitCometClient(char* buf, size_t buflen, uint8_t const* id)
{
const char* chid = (char*)id;
char const* chid = (char*)id;
bool is_bitlord;
int major, minor;
const char* name;
const char* mod = NULL;
char const* name;
char const* mod = NULL;
if (strncmp(chid, "exbc", 4) == 0)
{
@ -168,10 +168,10 @@ static bool decodeBitCometClient(char* buf, size_t buflen, const uint8_t* id)
return true;
}
char* tr_clientForId(char* buf, size_t buflen, const void* id_in)
char* tr_clientForId(char* buf, size_t buflen, void const* id_in)
{
const uint8_t* id = id_in;
const char* chid = (char*)id;
uint8_t const* id = id_in;
char const* chid = (char*)id;
*buf = '\0';
@ -761,7 +761,7 @@ char* tr_clientForId(char* buf, size_t buflen, const void* id_in)
if (strchr("AOQRSTU", id[0]) && getShadowInt(id[1], &a) && getShadowInt(id[2], &b) && getShadowInt(id[3], &c))
{
const char* name = NULL;
char const* name = NULL;
switch (id[0])
{
@ -806,9 +806,9 @@ char* tr_clientForId(char* buf, size_t buflen, const void* id_in)
if (!*buf)
{
char out[32], * walk = out;
const char* in, * in_end;
char const* in, * in_end;
for (in = (const char*)id, in_end = in + 8; in != in_end; ++in)
for (in = (char const*)id, in_end = in + 8; in != in_end; ++in)
{
if (isprint((unsigned char)*in))
{

View File

@ -16,4 +16,4 @@
* @brief parse a peer-id into a human-readable client name and version number
* @ingroup utils
*/
char* tr_clientForId(char* buf, size_t buflen, const void* peer_id);
char* tr_clientForId(char* buf, size_t buflen, void const* peer_id);

View File

@ -32,7 +32,7 @@ void tr_cpConstruct(tr_completion* cp, tr_torrent* tor)
tr_cpReset(cp);
}
void tr_cpBlockInit(tr_completion* cp, const tr_bitfield* b)
void tr_cpBlockInit(tr_completion* cp, tr_bitfield const* b)
{
tr_cpReset(cp);
@ -56,7 +56,7 @@ void tr_cpBlockInit(tr_completion* cp, const tr_bitfield* b)
****
***/
tr_completeness tr_cpGetStatus(const tr_completion* cp)
tr_completeness tr_cpGetStatus(tr_completion const* cp)
{
if (tr_cpHasAll(cp))
{
@ -79,7 +79,7 @@ tr_completeness tr_cpGetStatus(const tr_completion* cp)
void tr_cpPieceRem(tr_completion* cp, tr_piece_index_t piece)
{
tr_block_index_t i, f, l;
const tr_torrent* tor = cp->tor;
tr_torrent const* tor = cp->tor;
tr_torGetPieceBlockRange(cp->tor, piece, &f, &l);
@ -109,11 +109,11 @@ void tr_cpPieceAdd(tr_completion* cp, tr_piece_index_t piece)
void tr_cpBlockAdd(tr_completion* cp, tr_block_index_t block)
{
const tr_torrent* tor = cp->tor;
tr_torrent const* tor = cp->tor;
if (!tr_cpBlockIsComplete(cp, block))
{
const tr_piece_index_t piece = tr_torBlockPiece(cp->tor, block);
tr_piece_index_t const piece = tr_torBlockPiece(cp->tor, block);
tr_bitfieldAdd(&cp->blockBitfield, block);
cp->sizeNow += tr_torBlockCountBytes(tor, block);
@ -127,15 +127,15 @@ void tr_cpBlockAdd(tr_completion* cp, tr_block_index_t block)
****
***/
uint64_t tr_cpHaveValid(const tr_completion* ccp)
uint64_t tr_cpHaveValid(tr_completion const* ccp)
{
if (ccp->haveValidIsDirty)
{
tr_piece_index_t i;
uint64_t size = 0;
tr_completion* cp = (tr_completion*)ccp; /* mutable */
const tr_torrent* tor = ccp->tor;
const tr_info* info = &tor->info;
tr_torrent const* tor = ccp->tor;
tr_info const* info = &tor->info;
for (i = 0; i < info->pieceCount; ++i)
{
@ -152,13 +152,13 @@ uint64_t tr_cpHaveValid(const tr_completion* ccp)
return ccp->haveValidLazy;
}
uint64_t tr_cpSizeWhenDone(const tr_completion* ccp)
uint64_t tr_cpSizeWhenDone(tr_completion const* ccp)
{
if (ccp->sizeWhenDoneIsDirty)
{
uint64_t size = 0;
const tr_torrent* tor = ccp->tor;
const tr_info* inf = tr_torrentInfo(tor);
tr_torrent const* tor = ccp->tor;
tr_info const* inf = tr_torrentInfo(tor);
tr_completion* cp = (tr_completion*)ccp; /* mutable */
if (tr_cpHasAll(ccp))
@ -172,7 +172,7 @@ uint64_t tr_cpSizeWhenDone(const tr_completion* ccp)
for (p = 0; p < inf->pieceCount; ++p)
{
uint64_t n = 0;
const uint64_t pieceSize = tr_torPieceCountBytes(tor, p);
uint64_t const pieceSize = tr_torPieceCountBytes(tor, p);
if (!inf->pieces[p].dnd)
{
@ -207,20 +207,20 @@ uint64_t tr_cpSizeWhenDone(const tr_completion* ccp)
return ccp->sizeWhenDoneLazy;
}
uint64_t tr_cpLeftUntilDone(const tr_completion* cp)
uint64_t tr_cpLeftUntilDone(tr_completion const* cp)
{
const uint64_t sizeWhenDone = tr_cpSizeWhenDone(cp);
uint64_t const sizeWhenDone = tr_cpSizeWhenDone(cp);
assert(sizeWhenDone >= cp->sizeNow);
return sizeWhenDone - cp->sizeNow;
}
void tr_cpGetAmountDone(const tr_completion* cp, float* tab, int tabCount)
void tr_cpGetAmountDone(tr_completion const* cp, float* tab, int tabCount)
{
int i;
const bool seed = tr_cpHasAll(cp);
const float interval = cp->tor->info.pieceCount / (float)tabCount;
bool const seed = tr_cpHasAll(cp);
float const interval = cp->tor->info.pieceCount / (float)tabCount;
for (i = 0; i < tabCount; ++i)
{
@ -231,14 +231,14 @@ void tr_cpGetAmountDone(const tr_completion* cp, float* tab, int tabCount)
else
{
tr_block_index_t f, l;
const tr_piece_index_t piece = (tr_piece_index_t)i * interval;
tr_piece_index_t const piece = (tr_piece_index_t)i * interval;
tr_torGetPieceBlockRange(cp->tor, piece, &f, &l);
tab[i] = tr_bitfieldCountRange(&cp->blockBitfield, f, l + 1) / (float)(l + 1 - f);
}
}
}
size_t tr_cpMissingBlocksInPiece(const tr_completion* cp, tr_piece_index_t piece)
size_t tr_cpMissingBlocksInPiece(tr_completion const* cp, tr_piece_index_t piece)
{
if (tr_cpHasAll(cp))
{
@ -252,7 +252,7 @@ size_t tr_cpMissingBlocksInPiece(const tr_completion* cp, tr_piece_index_t piece
}
}
size_t tr_cpMissingBytesInPiece(const tr_completion* cp, tr_piece_index_t piece)
size_t tr_cpMissingBytesInPiece(tr_completion const* cp, tr_piece_index_t piece)
{
if (tr_cpHasAll(cp))
{
@ -262,7 +262,7 @@ size_t tr_cpMissingBytesInPiece(const tr_completion* cp, tr_piece_index_t piece)
{
size_t haveBytes = 0;
tr_block_index_t f, l;
const size_t pieceByteSize = tr_torPieceCountBytes(cp->tor, piece);
size_t const pieceByteSize = tr_torPieceCountBytes(cp->tor, piece);
tr_torGetPieceBlockRange(cp->tor, piece, &f, &l);
if (f != l)
@ -284,7 +284,7 @@ size_t tr_cpMissingBytesInPiece(const tr_completion* cp, tr_piece_index_t piece)
}
}
bool tr_cpFileIsComplete(const tr_completion* cp, tr_file_index_t i)
bool tr_cpFileIsComplete(tr_completion const* cp, tr_file_index_t i)
{
if (cp->tor->info.files[i].length == 0)
{
@ -298,7 +298,7 @@ bool tr_cpFileIsComplete(const tr_completion* cp, tr_file_index_t i)
}
}
void* tr_cpCreatePieceBitfield(const tr_completion* cp, size_t* byte_count)
void* tr_cpCreatePieceBitfield(tr_completion const* cp, size_t* byte_count)
{
void* ret;
tr_piece_index_t n;
@ -332,9 +332,9 @@ void* tr_cpCreatePieceBitfield(const tr_completion* cp, size_t* byte_count)
return ret;
}
double tr_cpPercentComplete(const tr_completion* cp)
double tr_cpPercentComplete(tr_completion const* cp)
{
const double ratio = tr_getRatio(cp->sizeNow, cp->tor->info.totalSize);
double const ratio = tr_getRatio(cp->sizeNow, cp->tor->info.totalSize);
if ((int)ratio == TR_RATIO_NA)
{
@ -350,9 +350,9 @@ double tr_cpPercentComplete(const tr_completion* cp)
}
}
double tr_cpPercentDone(const tr_completion* cp)
double tr_cpPercentDone(tr_completion const* cp)
{
const double ratio = tr_getRatio(cp->sizeNow, tr_cpSizeWhenDone(cp));
const int iratio = (int)ratio;
double const ratio = tr_getRatio(cp->sizeNow, tr_cpSizeWhenDone(cp));
int const iratio = (int)ratio;
return ((iratio == TR_RATIO_NA) || (iratio == TR_RATIO_INF)) ? 0.0 : ratio;
}

View File

@ -49,7 +49,7 @@ tr_completion;
void tr_cpConstruct(tr_completion*, tr_torrent*);
void tr_cpBlockInit(tr_completion* cp, const tr_bitfield* blocks);
void tr_cpBlockInit(tr_completion* cp, tr_bitfield const* blocks);
static inline void tr_cpDestruct(tr_completion* cp)
{
@ -60,31 +60,31 @@ static inline void tr_cpDestruct(tr_completion* cp)
*** General
**/
double tr_cpPercentComplete(const tr_completion* cp);
double tr_cpPercentComplete(tr_completion const* cp);
double tr_cpPercentDone(const tr_completion* cp);
double tr_cpPercentDone(tr_completion const* cp);
tr_completeness tr_cpGetStatus(const tr_completion*);
tr_completeness tr_cpGetStatus(tr_completion const*);
uint64_t tr_cpHaveValid(const tr_completion*);
uint64_t tr_cpHaveValid(tr_completion const*);
uint64_t tr_cpSizeWhenDone(const tr_completion*);
uint64_t tr_cpSizeWhenDone(tr_completion const*);
uint64_t tr_cpLeftUntilDone(const tr_completion*);
uint64_t tr_cpLeftUntilDone(tr_completion const*);
void tr_cpGetAmountDone(const tr_completion* completion, float* tab, int tabCount);
void tr_cpGetAmountDone(tr_completion const* completion, float* tab, int tabCount);
static inline uint64_t tr_cpHaveTotal(const tr_completion* cp)
static inline uint64_t tr_cpHaveTotal(tr_completion const* cp)
{
return cp->sizeNow;
}
static inline bool tr_cpHasAll(const tr_completion* cp)
static inline bool tr_cpHasAll(tr_completion const* cp)
{
return tr_torrentHasMetadata(cp->tor) && tr_bitfieldHasAll(&cp->blockBitfield);
}
static inline bool tr_cpHasNone(const tr_completion* cp)
static inline bool tr_cpHasNone(tr_completion const* cp)
{
return !tr_torrentHasMetadata(cp->tor) || tr_bitfieldHasNone(&cp->blockBitfield);
}
@ -97,11 +97,11 @@ void tr_cpPieceAdd(tr_completion* cp, tr_piece_index_t i);
void tr_cpPieceRem(tr_completion* cp, tr_piece_index_t i);
size_t tr_cpMissingBlocksInPiece(const tr_completion*, tr_piece_index_t);
size_t tr_cpMissingBlocksInPiece(tr_completion const*, tr_piece_index_t);
size_t tr_cpMissingBytesInPiece(const tr_completion*, tr_piece_index_t);
size_t tr_cpMissingBytesInPiece(tr_completion const*, tr_piece_index_t);
static inline bool tr_cpPieceIsComplete(const tr_completion* cp, tr_piece_index_t i)
static inline bool tr_cpPieceIsComplete(tr_completion const* cp, tr_piece_index_t i)
{
return tr_cpMissingBlocksInPiece(cp, i) == 0;
}
@ -112,7 +112,7 @@ static inline bool tr_cpPieceIsComplete(const tr_completion* cp, tr_piece_index_
void tr_cpBlockAdd(tr_completion* cp, tr_block_index_t i);
static inline bool tr_cpBlockIsComplete(const tr_completion* cp, tr_block_index_t i)
static inline bool tr_cpBlockIsComplete(tr_completion const* cp, tr_block_index_t i)
{
return tr_bitfieldHas(&cp->blockBitfield, i);
}
@ -121,9 +121,9 @@ static inline bool tr_cpBlockIsComplete(const tr_completion* cp, tr_block_index_
**** Misc
***/
bool tr_cpFileIsComplete(const tr_completion* cp, tr_file_index_t);
bool tr_cpFileIsComplete(tr_completion const* cp, tr_file_index_t);
void* tr_cpCreatePieceBitfield(const tr_completion* cp, size_t* byte_count);
void* tr_cpCreatePieceBitfield(tr_completion const* cp, size_t* byte_count);
static inline void tr_cpInvalidateDND(tr_completion* cp)
{

View File

@ -64,9 +64,9 @@ static int test_encrypt_decrypt(void)
tr_crypto a;
tr_crypto_ b;
uint8_t hash[SHA_DIGEST_LENGTH];
const char test1[] = { "test1" };
char const test1[] = { "test1" };
char buf11[sizeof(test1)], buf12[sizeof(test1)];
const char test2[] = { "@#)C$@)#(*%bvkdjfhwbc039bc4603756VB3)" };
char const test2[] = { "@#)C$@)#(*%bvkdjfhwbc039bc4603756VB3)" };
char buf21[sizeof(test2)], buf22[sizeof(test2)];
int i;
@ -122,8 +122,8 @@ static int test_ssha1(void)
{
struct
{
const char* const plain_text;
const char* const ssha1;
char const* const plain_text;
char const* const ssha1;
}
test_data[] =
{
@ -203,7 +203,7 @@ static int test_random(void)
/* test that tr_rand_int () stays in-bounds */
for (i = 0; i < 100000; ++i)
{
const int val = tr_rand_int(100);
int const val = tr_rand_int(100);
check(val >= 0);
check(val < 100);
}
@ -211,7 +211,7 @@ static int test_random(void)
return 0;
}
static bool base64_eq(const char* a, const char* b)
static bool base64_eq(char const* a, char const* b)
{
for (;; ++a, ++b)
{
@ -308,7 +308,7 @@ static int test_base64(void)
int main(void)
{
const testFunc tests[] =
testFunc const tests[] =
{
test_torrent_hash,
test_encrypt_decrypt,

View File

@ -50,14 +50,14 @@ struct tr_dh_ctx
#define MY_NAME "tr_crypto_utils"
static void log_cyassl_error(int error_code, const char* file, int line)
static void log_cyassl_error(int error_code, char const* file, int line)
{
if (tr_logLevelIsActive(TR_LOG_ERROR))
{
#if API_VERSION_HEX >= 0x03004000
const char* error_message = API(GetErrorString)(error_code);
char const* error_message = API(GetErrorString)(error_code);
#elif API_VERSION_HEX >= 0x03000002
const char* error_message = CTaoCryptGetErrorString(error_code);
char const* error_message = CTaoCryptGetErrorString(error_code);
#else
char error_message[CYASSL_MAX_ERROR_SZ];
CTaoCryptErrorString(error_code, error_message);
@ -67,9 +67,9 @@ static void log_cyassl_error(int error_code, const char* file, int line)
}
}
static bool check_cyassl_result(int result, const char* file, int line)
static bool check_cyassl_result(int result, char const* file, int line)
{
const bool ret = result == 0;
bool const ret = result == 0;
if (!ret)
{
@ -132,7 +132,7 @@ tr_sha1_ctx_t tr_sha1_init(void)
return NULL;
}
bool tr_sha1_update(tr_sha1_ctx_t handle, const void* data, size_t data_length)
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
assert(handle != NULL);
@ -175,7 +175,7 @@ void tr_rc4_free(tr_rc4_ctx_t handle)
tr_free(handle);
}
void tr_rc4_set_key(tr_rc4_ctx_t handle, const uint8_t* key, size_t key_length)
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
assert(handle != NULL);
assert(key != NULL);
@ -183,7 +183,7 @@ void tr_rc4_set_key(tr_rc4_ctx_t handle, const uint8_t* key, size_t key_length)
API(Arc4SetKey)(handle, key, key_length);
}
void tr_rc4_process(tr_rc4_ctx_t handle, const void* input, void* output, size_t length)
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length)
{
assert(handle != NULL);
@ -202,7 +202,7 @@ void tr_rc4_process(tr_rc4_ctx_t handle, const void* input, void* output, size_t
****
***/
tr_dh_ctx_t tr_dh_new(const uint8_t* prime_num, size_t prime_num_length, const uint8_t* generator_num,
tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t const* generator_num,
size_t generator_num_length)
{
struct tr_dh_ctx* handle = tr_new0(struct tr_dh_ctx, 1);
@ -274,7 +274,7 @@ bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length UNUSED, ui
return true;
}
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, const uint8_t* other_public_key, size_t other_public_key_length)
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, uint8_t const* other_public_key, size_t other_public_key_length)
{
struct tr_dh_ctx* handle = raw_handle;
struct tr_dh_secret* ret;

View File

@ -43,7 +43,7 @@ static void tr_dh_secret_align(struct tr_dh_secret* handle, size_t current_key_l
tr_dh_align_key(handle->key, current_key_length, handle->key_length);
}
bool tr_dh_secret_derive(tr_dh_secret_t raw_handle, const void* prepend_data, size_t prepend_data_size, const void* append_data,
bool tr_dh_secret_derive(tr_dh_secret_t raw_handle, void const* prepend_data, size_t prepend_data_size, void const* append_data,
size_t append_data_size, uint8_t* hash)
{
struct tr_dh_secret* handle = raw_handle;

View File

@ -35,9 +35,9 @@
#define MY_NAME "tr_crypto_utils"
static void log_openssl_error(const char* file, int line)
static void log_openssl_error(char const* file, int line)
{
const unsigned long error_code = ERR_get_error();
unsigned long const error_code = ERR_get_error();
if (tr_logLevelIsActive(TR_LOG_ERROR))
{
@ -67,9 +67,9 @@ static void log_openssl_error(const char* file, int line)
#define log_error() log_openssl_error(__FILE__, __LINE__)
static bool check_openssl_result(int result, int expected_result, bool expected_equal, const char* file, int line)
static bool check_openssl_result(int result, int expected_result, bool expected_equal, char const* file, int line)
{
const bool ret = (result == expected_result) == expected_equal;
bool const ret = (result == expected_result) == expected_equal;
if (!ret)
{
@ -83,9 +83,9 @@ static bool check_openssl_result(int result, int expected_result, bool expected_
#define check_result_eq(result, x_result) check_openssl_result((result), (x_result), true, __FILE__, __LINE__)
#define check_result_neq(result, x_result) check_openssl_result((result), (x_result), false, __FILE__, __LINE__)
static bool check_openssl_pointer(void* pointer, const char* file, int line)
static bool check_openssl_pointer(void* pointer, char const* file, int line)
{
const bool ret = pointer != NULL;
bool const ret = pointer != NULL;
if (!ret)
{
@ -114,7 +114,7 @@ tr_sha1_ctx_t tr_sha1_init(void)
return NULL;
}
bool tr_sha1_update(tr_sha1_ctx_t handle, const void* data, size_t data_length)
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
assert(handle != NULL);
@ -204,7 +204,7 @@ void tr_rc4_free(tr_rc4_ctx_t handle)
EVP_CIPHER_CTX_free(handle);
}
void tr_rc4_set_key(tr_rc4_ctx_t handle, const uint8_t* key, size_t key_length)
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
assert(handle != NULL);
assert(key != NULL);
@ -217,7 +217,7 @@ void tr_rc4_set_key(tr_rc4_ctx_t handle, const uint8_t* key, size_t key_length)
check_result(EVP_CipherInit_ex(handle, NULL, NULL, key, NULL, -1));
}
void tr_rc4_process(tr_rc4_ctx_t handle, const void* input, void* output, size_t length)
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length)
{
int output_length;
@ -282,7 +282,7 @@ static inline int DH_set_length(DH* dh, long length)
return 1;
}
static inline void DH_get0_key(const DH* dh, const BIGNUM** pub_key, const BIGNUM** priv_key)
static inline void DH_get0_key(DH const* dh, BIGNUM const** pub_key, BIGNUM const** priv_key)
{
if (pub_key != NULL)
{
@ -297,7 +297,7 @@ static inline void DH_get0_key(const DH* dh, const BIGNUM** pub_key, const BIGNU
#endif
tr_dh_ctx_t tr_dh_new(const uint8_t* prime_num, size_t prime_num_length, const uint8_t* generator_num,
tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t const* generator_num,
size_t generator_num_length)
{
DH* handle = DH_new();
@ -334,7 +334,7 @@ bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length, uint8_t*
{
DH* handle = raw_handle;
int dh_size, my_public_key_length;
const BIGNUM* my_public_key;
BIGNUM const* my_public_key;
assert(handle != NULL);
assert(public_key != NULL);
@ -361,7 +361,7 @@ bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length, uint8_t*
return true;
}
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t handle, const uint8_t* other_public_key, size_t other_public_key_length)
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t handle, uint8_t const* other_public_key, size_t other_public_key_length)
{
struct tr_dh_secret* ret;
int dh_size, secret_key_length;

View File

@ -41,7 +41,7 @@
#define MY_NAME "tr_crypto_utils"
static void log_polarssl_error(int error_code, const char* file, int line)
static void log_polarssl_error(int error_code, char const* file, int line)
{
if (tr_logLevelIsActive(TR_LOG_ERROR))
{
@ -61,9 +61,9 @@ static void log_polarssl_error(int error_code, const char* file, int line)
#define log_error(error_code) log_polarssl_error((error_code), __FILE__, __LINE__)
static bool check_polarssl_result(int result, int expected_result, const char* file, int line)
static bool check_polarssl_result(int result, int expected_result, char const* file, int line)
{
const bool ret = result == expected_result;
bool const ret = result == expected_result;
if (!ret)
{
@ -145,7 +145,7 @@ tr_sha1_ctx_t tr_sha1_init(void)
return handle;
}
bool tr_sha1_update(tr_sha1_ctx_t handle, const void* data, size_t data_length)
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length)
{
assert(handle != NULL);
@ -201,7 +201,7 @@ void tr_rc4_free(tr_rc4_ctx_t handle)
tr_free(handle);
}
void tr_rc4_set_key(tr_rc4_ctx_t handle, const uint8_t* key, size_t key_length)
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length)
{
assert(handle != NULL);
assert(key != NULL);
@ -209,7 +209,7 @@ void tr_rc4_set_key(tr_rc4_ctx_t handle, const uint8_t* key, size_t key_length)
API(arc4_setup)(handle, key, key_length);
}
void tr_rc4_process(tr_rc4_ctx_t handle, const void* input, void* output, size_t length)
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length)
{
assert(handle != NULL);
@ -228,7 +228,7 @@ void tr_rc4_process(tr_rc4_ctx_t handle, const void* input, void* output, size_t
****
***/
tr_dh_ctx_t tr_dh_new(const uint8_t* prime_num, size_t prime_num_length, const uint8_t* generator_num,
tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t const* generator_num,
size_t generator_num_length)
{
API(dhm_context) * handle = tr_new0(API(dhm_context), 1);
@ -277,7 +277,7 @@ bool tr_dh_make_key(tr_dh_ctx_t raw_handle, size_t private_key_length, uint8_t*
return check_result(API(dhm_make_public)(handle, private_key_length, public_key, handle->len, my_rand, NULL));
}
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, const uint8_t* other_public_key, size_t other_public_key_length)
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t raw_handle, uint8_t const* other_public_key, size_t other_public_key_length)
{
API(dhm_context) * handle = raw_handle;
struct tr_dh_secret* ret;

View File

@ -31,7 +31,7 @@ void tr_dh_align_key(uint8_t* key_buffer, size_t key_size, size_t buffer_size)
the msb's of key buffer need to be zeroed appropriately. */
if (key_size < buffer_size)
{
const size_t offset = buffer_size - key_size;
size_t const offset = buffer_size - key_size;
memmove(key_buffer + offset, key_buffer, key_size);
memset(key_buffer, 0, offset);
}
@ -41,7 +41,7 @@ void tr_dh_align_key(uint8_t* key_buffer, size_t key_size, size_t buffer_size)
****
***/
bool tr_sha1(uint8_t* hash, const void* data1, int data1_length, ...)
bool tr_sha1(uint8_t* hash, void const* data1, int data1_length, ...)
{
tr_sha1_ctx_t sha;
@ -53,13 +53,13 @@ bool tr_sha1(uint8_t* hash, const void* data1, int data1_length, ...)
if (tr_sha1_update(sha, data1, data1_length))
{
va_list vl;
const void* data;
void const* data;
va_start(vl, data1_length);
while ((data = va_arg(vl, const void*)) != NULL)
while ((data = va_arg(vl, void const*)) != NULL)
{
const int data_length = va_arg(vl, int);
int const data_length = va_arg(vl, int);
assert(data_length >= 0);
if (!tr_sha1_update(sha, data, data_length))
@ -125,7 +125,7 @@ int tr_rand_int_weak(int upper_bound)
****
***/
char* tr_ssha1(const char* plain_text)
char* tr_ssha1(char const* plain_text)
{
enum
{
@ -133,7 +133,7 @@ char* tr_ssha1(const char* plain_text)
salter_len = 64
};
static const char* salter =
static char const* salter =
"0123456789"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@ -162,15 +162,15 @@ char* tr_ssha1(const char* plain_text)
return tr_strdup(buf);
}
bool tr_ssha1_matches(const char* ssha1, const char* plain_text)
bool tr_ssha1_matches(char const* ssha1, char const* plain_text)
{
assert(ssha1 != NULL);
assert(plain_text != NULL);
const size_t brace_len = 1;
const size_t brace_and_hash_len = brace_len + 2 * SHA_DIGEST_LENGTH;
size_t const brace_len = 1;
size_t const brace_and_hash_len = brace_len + 2 * SHA_DIGEST_LENGTH;
const size_t source_len = strlen(ssha1);
size_t const source_len = strlen(ssha1);
if (source_len < brace_and_hash_len || ssha1[0] != '{')
{
@ -178,8 +178,8 @@ bool tr_ssha1_matches(const char* ssha1, const char* plain_text)
}
/* extract the salt */
const char* const salt = ssha1 + brace_and_hash_len;
const size_t salt_len = source_len - brace_and_hash_len;
char const* const salt = ssha1 + brace_and_hash_len;
size_t const salt_len = source_len - brace_and_hash_len;
uint8_t buf[SHA_DIGEST_LENGTH * 2 + 1];
@ -187,14 +187,14 @@ bool tr_ssha1_matches(const char* ssha1, const char* plain_text)
tr_sha1(buf, plain_text, (int)strlen(plain_text), salt, (int)salt_len, NULL);
tr_sha1_to_hex((char*)buf, buf);
return strncmp(ssha1 + brace_len, (const char*)buf, SHA_DIGEST_LENGTH * 2) == 0;
return strncmp(ssha1 + brace_len, (char const*)buf, SHA_DIGEST_LENGTH * 2) == 0;
}
/***
****
***/
void* tr_base64_encode(const void* input, size_t input_length, size_t* output_length)
void* tr_base64_encode(void const* input, size_t input_length, size_t* output_length)
{
char* ret;
@ -243,12 +243,12 @@ void* tr_base64_encode(const void* input, size_t input_length, size_t* output_le
return ret;
}
void* tr_base64_encode_str(const char* input, size_t* output_length)
void* tr_base64_encode_str(char const* input, size_t* output_length)
{
return tr_base64_encode(input, input == NULL ? 0 : strlen(input), output_length);
}
void* tr_base64_decode(const void* input, size_t input_length, size_t* output_length)
void* tr_base64_decode(void const* input, size_t input_length, size_t* output_length)
{
char* ret;
@ -291,7 +291,7 @@ void* tr_base64_decode(const void* input, size_t input_length, size_t* output_le
return ret;
}
void* tr_base64_decode_str(const char* input, size_t* output_length)
void* tr_base64_decode_str(char const* input, size_t* output_length)
{
return tr_base64_decode(input, input == NULL ? 0 : strlen(input), output_length);
}

View File

@ -37,7 +37,7 @@ typedef void* tr_dh_secret_t;
/**
* @brief Generate a SHA1 hash from one or more chunks of memory.
*/
bool tr_sha1(uint8_t* hash, const void* data1, int data1_length, ...) TR_GNUC_NULL_TERMINATED;
bool tr_sha1(uint8_t* hash, void const* data1, int data1_length, ...) TR_GNUC_NULL_TERMINATED;
/**
* @brief Allocate and initialize new SHA1 hasher context.
@ -47,7 +47,7 @@ tr_sha1_ctx_t tr_sha1_init(void);
/**
* @brief Update SHA1 hash.
*/
bool tr_sha1_update(tr_sha1_ctx_t handle, const void* data, size_t data_length);
bool tr_sha1_update(tr_sha1_ctx_t handle, void const* data, size_t data_length);
/**
* @brief Finalize and export SHA1 hash, free hasher context.
@ -67,17 +67,17 @@ void tr_rc4_free(tr_rc4_ctx_t handle);
/**
* @brief Set RC4 cipher key.
*/
void tr_rc4_set_key(tr_rc4_ctx_t handle, const uint8_t* key, size_t key_length);
void tr_rc4_set_key(tr_rc4_ctx_t handle, uint8_t const* key, size_t key_length);
/**
* @brief Process memory block with RC4 cipher.
*/
void tr_rc4_process(tr_rc4_ctx_t handle, const void* input, void* output, size_t length);
void tr_rc4_process(tr_rc4_ctx_t handle, void const* input, void* output, size_t length);
/**
* @brief Allocate and initialize new Diffie-Hellman (DH) key exchange context.
*/
tr_dh_ctx_t tr_dh_new(const uint8_t* prime_num, size_t prime_num_length, const uint8_t* generator_num,
tr_dh_ctx_t tr_dh_new(uint8_t const* prime_num, size_t prime_num_length, uint8_t const* generator_num,
size_t generator_num_length);
/**
@ -93,13 +93,13 @@ bool tr_dh_make_key(tr_dh_ctx_t handle, size_t private_key_length, uint8_t* publ
/**
* @brief Perform DH key exchange, generate secret key.
*/
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t handle, const uint8_t* other_public_key, size_t other_public_key_length);
tr_dh_secret_t tr_dh_agree(tr_dh_ctx_t handle, uint8_t const* other_public_key, size_t other_public_key_length);
/**
* @brief Calculate SHA1 hash of DH secret key, prepending and/or appending
* given data to the key during calculation.
*/
bool tr_dh_secret_derive(tr_dh_secret_t handle, const void* prepend_data, size_t prepend_data_size, const void* append_data,
bool tr_dh_secret_derive(tr_dh_secret_t handle, void const* prepend_data, size_t prepend_data_size, void const* append_data,
size_t append_data_size, uint8_t* hash);
/**
@ -133,41 +133,41 @@ bool tr_rand_buffer(void* buffer, size_t length);
/**
* @brief Generate a SSHA password from its plaintext source.
*/
char* tr_ssha1(const char* plain_text) TR_GNUC_MALLOC;
char* tr_ssha1(char const* plain_text) TR_GNUC_MALLOC;
/**
* @brief Validate a test password against the a ssha1 password.
*/
bool tr_ssha1_matches(const char* ssha1, const char* plain_text);
bool tr_ssha1_matches(char const* ssha1, char const* plain_text);
/**
* @brief Translate a block of bytes into base64.
* @return a newly-allocated null-terminated string that can be freed with tr_free ()
*/
void* tr_base64_encode(const void* input, size_t input_length, size_t* output_length) TR_GNUC_MALLOC;
void* tr_base64_encode(void const* input, size_t input_length, size_t* output_length) TR_GNUC_MALLOC;
/**
* @brief Translate null-terminated string into base64.
* @return a newly-allocated null-terminated string that can be freed with tr_free ()
*/
void* tr_base64_encode_str(const char* input, size_t* output_length) TR_GNUC_MALLOC;
void* tr_base64_encode_str(char const* input, size_t* output_length) TR_GNUC_MALLOC;
/**
* @brief Translate a block of bytes from base64 into raw form.
* @return a newly-allocated null-terminated string that can be freed with tr_free ()
*/
void* tr_base64_decode(const void* input, size_t input_length, size_t* output_length) TR_GNUC_MALLOC;
void* tr_base64_decode(void const* input, size_t input_length, size_t* output_length) TR_GNUC_MALLOC;
/**
* @brief Translate null-terminated string from base64 into raw form.
* @return a newly-allocated null-terminated string that can be freed with tr_free ()
*/
void* tr_base64_decode_str(const char* input, size_t* output_length) TR_GNUC_MALLOC;
void* tr_base64_decode_str(char const* input, size_t* output_length) TR_GNUC_MALLOC;
/**
* @brief Wrapper around tr_binary_to_hex () for SHA_DIGEST_LENGTH.
*/
static inline void tr_sha1_to_hex(char* hex, const uint8_t* sha1)
static inline void tr_sha1_to_hex(char* hex, uint8_t const* sha1)
{
tr_binary_to_hex(sha1, hex, SHA_DIGEST_LENGTH);
}
@ -175,7 +175,7 @@ static inline void tr_sha1_to_hex(char* hex, const uint8_t* sha1)
/**
* @brief Wrapper around tr_hex_to_binary () for SHA_DIGEST_LENGTH.
*/
static inline void tr_hex_to_sha1(uint8_t* sha1, const char* hex)
static inline void tr_hex_to_sha1(uint8_t* sha1, char const* hex)
{
tr_hex_to_binary(hex, sha1, SHA_DIGEST_LENGTH);
}

View File

@ -21,7 +21,7 @@
#define PRIME_LEN 96
#define DH_PRIVKEY_LEN 20
static const uint8_t dh_P[PRIME_LEN] =
static uint8_t const dh_P[PRIME_LEN] =
{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
@ -33,7 +33,7 @@ static const uint8_t dh_P[PRIME_LEN] =
0xA6, 0x3A, 0x36, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x05, 0x63,
};
static const uint8_t dh_G[] = { 2 };
static uint8_t const dh_G[] = { 2 };
/**
***
@ -52,7 +52,7 @@ static void ensureKeyExists(tr_crypto* crypto)
}
}
void tr_cryptoConstruct(tr_crypto* crypto, const uint8_t* torrentHash, bool isIncoming)
void tr_cryptoConstruct(tr_crypto* crypto, uint8_t const* torrentHash, bool isIncoming)
{
memset(crypto, 0, sizeof(tr_crypto));
@ -72,14 +72,14 @@ void tr_cryptoDestruct(tr_crypto* crypto)
***
**/
bool tr_cryptoComputeSecret(tr_crypto* crypto, const uint8_t* peerPublicKey)
bool tr_cryptoComputeSecret(tr_crypto* crypto, uint8_t const* peerPublicKey)
{
ensureKeyExists(crypto);
crypto->mySecret = tr_dh_agree(crypto->dh, peerPublicKey, KEY_LEN);
return crypto->mySecret != NULL;
}
const uint8_t* tr_cryptoGetMyPublicKey(const tr_crypto* crypto, int* setme_len)
uint8_t const* tr_cryptoGetMyPublicKey(tr_crypto const* crypto, int* setme_len)
{
ensureKeyExists((tr_crypto*)crypto);
*setme_len = KEY_LEN;
@ -90,7 +90,7 @@ const uint8_t* tr_cryptoGetMyPublicKey(const tr_crypto* crypto, int* setme_len)
***
**/
static void initRC4(tr_crypto* crypto, tr_rc4_ctx_t* setme, const char* key)
static void initRC4(tr_crypto* crypto, tr_rc4_ctx_t* setme, char const* key)
{
uint8_t buf[SHA_DIGEST_LENGTH];
@ -110,13 +110,13 @@ static void initRC4(tr_crypto* crypto, tr_rc4_ctx_t* setme, const char* key)
void tr_cryptoDecryptInit(tr_crypto* crypto)
{
uint8_t discard[1024];
const char* txt = crypto->isIncoming ? "keyA" : "keyB";
char const* txt = crypto->isIncoming ? "keyA" : "keyB";
initRC4(crypto, &crypto->dec_key, txt);
tr_rc4_process(crypto->dec_key, discard, discard, sizeof(discard));
}
void tr_cryptoDecrypt(tr_crypto* crypto, size_t buf_len, const void* buf_in, void* buf_out)
void tr_cryptoDecrypt(tr_crypto* crypto, size_t buf_len, void const* buf_in, void* buf_out)
{
/* FIXME: someone calls this function with uninitialized key */
if (crypto->dec_key == NULL)
@ -135,13 +135,13 @@ void tr_cryptoDecrypt(tr_crypto* crypto, size_t buf_len, const void* buf_in, voi
void tr_cryptoEncryptInit(tr_crypto* crypto)
{
uint8_t discard[1024];
const char* txt = crypto->isIncoming ? "keyB" : "keyA";
char const* txt = crypto->isIncoming ? "keyB" : "keyA";
initRC4(crypto, &crypto->enc_key, txt);
tr_rc4_process(crypto->enc_key, discard, discard, sizeof(discard));
}
void tr_cryptoEncrypt(tr_crypto* crypto, size_t buf_len, const void* buf_in, void* buf_out)
void tr_cryptoEncrypt(tr_crypto* crypto, size_t buf_len, void const* buf_in, void* buf_out)
{
/* FIXME: someone calls this function with uninitialized key */
if (crypto->enc_key == NULL)
@ -157,8 +157,8 @@ void tr_cryptoEncrypt(tr_crypto* crypto, size_t buf_len, const void* buf_in, voi
tr_rc4_process(crypto->enc_key, buf_in, buf_out, buf_len);
}
bool tr_cryptoSecretKeySha1(const tr_crypto* crypto, const void* prepend_data, size_t prepend_data_size,
const void* append_data, size_t append_data_size, uint8_t* hash)
bool tr_cryptoSecretKeySha1(tr_crypto const* crypto, void const* prepend_data, size_t prepend_data_size,
void const* append_data, size_t append_data_size, uint8_t* hash)
{
assert(crypto != NULL);
assert(crypto->mySecret != NULL);
@ -170,7 +170,7 @@ bool tr_cryptoSecretKeySha1(const tr_crypto* crypto, const void* prepend_data, s
***
**/
void tr_cryptoSetTorrentHash(tr_crypto* crypto, const uint8_t* hash)
void tr_cryptoSetTorrentHash(tr_crypto* crypto, uint8_t const* hash)
{
crypto->torrentHashIsSet = hash != NULL;
@ -184,14 +184,14 @@ void tr_cryptoSetTorrentHash(tr_crypto* crypto, const uint8_t* hash)
}
}
const uint8_t* tr_cryptoGetTorrentHash(const tr_crypto* crypto)
uint8_t const* tr_cryptoGetTorrentHash(tr_crypto const* crypto)
{
assert(crypto);
return crypto->torrentHashIsSet ? crypto->torrentHash : NULL;
}
bool tr_cryptoHasTorrentHash(const tr_crypto* crypto)
bool tr_cryptoHasTorrentHash(tr_crypto const* crypto)
{
assert(crypto);

View File

@ -43,31 +43,31 @@ typedef struct
tr_crypto;
/** @brief construct a new tr_crypto object */
void tr_cryptoConstruct(tr_crypto* crypto, const uint8_t* torrentHash, bool isIncoming);
void tr_cryptoConstruct(tr_crypto* crypto, uint8_t const* torrentHash, bool isIncoming);
/** @brief destruct an existing tr_crypto object */
void tr_cryptoDestruct(tr_crypto* crypto);
void tr_cryptoSetTorrentHash(tr_crypto* crypto, const uint8_t* torrentHash);
void tr_cryptoSetTorrentHash(tr_crypto* crypto, uint8_t const* torrentHash);
const uint8_t* tr_cryptoGetTorrentHash(const tr_crypto* crypto);
uint8_t const* tr_cryptoGetTorrentHash(tr_crypto const* crypto);
bool tr_cryptoHasTorrentHash(const tr_crypto* crypto);
bool tr_cryptoHasTorrentHash(tr_crypto const* crypto);
bool tr_cryptoComputeSecret(tr_crypto* crypto, const uint8_t* peerPublicKey);
bool tr_cryptoComputeSecret(tr_crypto* crypto, uint8_t const* peerPublicKey);
const uint8_t* tr_cryptoGetMyPublicKey(const tr_crypto* crypto, int* setme_len);
uint8_t const* tr_cryptoGetMyPublicKey(tr_crypto const* crypto, int* setme_len);
void tr_cryptoDecryptInit(tr_crypto* crypto);
void tr_cryptoDecrypt(tr_crypto* crypto, size_t buflen, const void* buf_in, void* buf_out);
void tr_cryptoDecrypt(tr_crypto* crypto, size_t buflen, void const* buf_in, void* buf_out);
void tr_cryptoEncryptInit(tr_crypto* crypto);
void tr_cryptoEncrypt(tr_crypto* crypto, size_t buflen, const void* buf_in, void* buf_out);
void tr_cryptoEncrypt(tr_crypto* crypto, size_t buflen, void const* buf_in, void* buf_out);
bool tr_cryptoSecretKeySha1(const tr_crypto* crypto, const void* prepend_data, size_t prepend_data_size,
const void* append_data, size_t append_data_size, uint8_t* hash);
bool tr_cryptoSecretKeySha1(tr_crypto const* crypto, void const* prepend_data, size_t prepend_data_size,
void const* append_data, size_t append_data_size, uint8_t* hash);
/* @} */

View File

@ -72,7 +72,7 @@ static int test_error_propagate(void)
int main(void)
{
const testFunc tests[] =
testFunc const tests[] =
{
test_error_set,
test_error_propagate

View File

@ -12,7 +12,7 @@
#include "error.h"
#include "utils.h"
tr_error* tr_error_new(int code, const char* message_format, ...)
tr_error* tr_error_new(int code, char const* message_format, ...)
{
tr_error* error;
va_list args;
@ -26,7 +26,7 @@ tr_error* tr_error_new(int code, const char* message_format, ...)
return error;
}
tr_error* tr_error_new_literal(int code, const char* message)
tr_error* tr_error_new_literal(int code, char const* message)
{
tr_error* error;
@ -39,7 +39,7 @@ tr_error* tr_error_new_literal(int code, const char* message)
return error;
}
tr_error* tr_error_new_valist(int code, const char* message_format, va_list args)
tr_error* tr_error_new_valist(int code, char const* message_format, va_list args)
{
tr_error* error;
@ -63,7 +63,7 @@ void tr_error_free(tr_error* error)
tr_free(error);
}
void tr_error_set(tr_error** error, int code, const char* message_format, ...)
void tr_error_set(tr_error** error, int code, char const* message_format, ...)
{
va_list args;
@ -80,7 +80,7 @@ void tr_error_set(tr_error** error, int code, const char* message_format, ...)
va_end(args);
}
void tr_error_set_literal(tr_error** error, int code, const char* message)
void tr_error_set_literal(tr_error** error, int code, char const* message)
{
if (error == NULL)
{
@ -123,7 +123,7 @@ void tr_error_clear(tr_error** error)
*error = NULL;
}
static void error_prefix_valist(tr_error** error, const char* prefix_format, va_list args)
static void error_prefix_valist(tr_error** error, char const* prefix_format, va_list args)
{
char* prefix;
char* new_message;
@ -141,7 +141,7 @@ static void error_prefix_valist(tr_error** error, const char* prefix_format, va_
tr_free(prefix);
}
void tr_error_prefix(tr_error** error, const char* prefix_format, ...)
void tr_error_prefix(tr_error** error, char const* prefix_format, ...)
{
va_list args;
@ -157,7 +157,7 @@ void tr_error_prefix(tr_error** error, const char* prefix_format, ...)
va_end(args);
}
void tr_error_propagate_prefixed(tr_error** new_error, tr_error** old_error, const char* prefix_format, ...)
void tr_error_propagate_prefixed(tr_error** new_error, tr_error** old_error, char const* prefix_format, ...)
{
va_list args;

View File

@ -47,7 +47,7 @@ tr_error;
*
* @return Newly allocated error object on success, `NULL` otherwise.
*/
tr_error* tr_error_new(int code, const char* message_format, ...) TR_GNUC_PRINTF(2, 3);
tr_error* tr_error_new(int code, char const* message_format, ...) TR_GNUC_PRINTF(2, 3);
/**
* @brief Create new error object using literal error message.
@ -57,7 +57,7 @@ tr_error* tr_error_new(int code, const char* message_format, ...) TR_GNUC_PRINTF
*
* @return Newly allocated error object on success, `NULL` otherwise.
*/
tr_error* tr_error_new_literal(int code, const char* message);
tr_error* tr_error_new_literal(int code, char const* message);
/**
* @brief Create new error object using `vprintf`-style formatting.
@ -68,7 +68,7 @@ tr_error* tr_error_new_literal(int code, const char* message);
*
* @return Newly allocated error object on success, `NULL` otherwise.
*/
tr_error* tr_error_new_valist(int code, const char* message_format, va_list args);
tr_error* tr_error_new_valist(int code, char const* message_format, va_list args);
/**
* @brief Free memory used by error object.
@ -87,7 +87,7 @@ void tr_error_free(tr_error* error);
* @param[in] message_format Error message format string.
* @param[in] ... Format arguments.
*/
void tr_error_set(tr_error** error, int code, const char* message_format, ...) TR_GNUC_PRINTF(3, 4);
void tr_error_set(tr_error** error, int code, char const* message_format, ...) TR_GNUC_PRINTF(3, 4);
/**
* @brief Create and set new error object using literal error message.
@ -98,7 +98,7 @@ void tr_error_set(tr_error** error, int code, const char* message_format, ...) T
* @param[in] code Error code (platform-specific).
* @param[in] message Error message.
*/
void tr_error_set_literal(tr_error** error, int code, const char* message);
void tr_error_set_literal(tr_error** error, int code, char const* message);
/**
* @brief Propagate existing error object upwards.
@ -132,7 +132,7 @@ void tr_error_clear(tr_error** error);
* @param[in] prefix_format Prefix format string.
* @param[in] ... Format arguments.
*/
void tr_error_prefix(tr_error** error, const char* prefix_format, ...) TR_GNUC_PRINTF(2, 3);
void tr_error_prefix(tr_error** error, char const* prefix_format, ...) TR_GNUC_PRINTF(2, 3);
/**
* @brief Prefix message and propagate existing error object upwards.
@ -146,7 +146,7 @@ void tr_error_prefix(tr_error** error, const char* prefix_format, ...) TR_GNUC_P
* @param[in] prefix_format Prefix format string.
* @param[in] ... Format arguments.
*/
void tr_error_propagate_prefixed(tr_error** new_error, tr_error** old_error, const char* prefix_format, ...) TR_GNUC_PRINTF(3,
void tr_error_propagate_prefixed(tr_error** new_error, tr_error** old_error, char const* prefix_format, ...) TR_GNUC_PRINTF(3,
4);
/** @} */

View File

@ -59,7 +59,7 @@ static bool preallocate_file_sparse(tr_sys_file_t fd, uint64_t length, tr_error*
if (!TR_ERROR_IS_ENOSPC(my_error->code))
{
const char zero = '\0';
char const zero = '\0';
tr_error_clear(&my_error);
@ -103,7 +103,7 @@ static bool preallocate_file_full(tr_sys_file_t fd, uint64_t length, tr_error**
/* fallback: the old-fashioned way */
while (success && length > 0)
{
const uint64_t thisPass = MIN(length, sizeof(buf));
uint64_t const thisPass = MIN(length, sizeof(buf));
uint64_t bytes_written;
success = tr_sys_file_write(fd, buf, thisPass, &bytes_written, &my_error);
length -= bytes_written;
@ -136,7 +136,7 @@ struct tr_cached_file
time_t used_at;
};
static inline bool cached_file_is_open(const struct tr_cached_file* o)
static inline bool cached_file_is_open(struct tr_cached_file const* o)
{
assert(o != NULL);
@ -156,7 +156,7 @@ static void cached_file_close(struct tr_cached_file* o)
* errno values include ENOENT if the parent folder doesn't exist,
* plus the errno values set by tr_sys_dir_create () and tr_sys_file_open ().
*/
static int cached_file_open(struct tr_cached_file* o, const char* filename, bool writable, tr_preallocation_mode allocation,
static int cached_file_open(struct tr_cached_file* o, char const* filename, bool writable, tr_preallocation_mode allocation,
uint64_t file_size)
{
int flags;
@ -207,7 +207,7 @@ static int cached_file_open(struct tr_cached_file* o, const char* filename, bool
if (writable && !already_existed && allocation != TR_PREALLOCATE_NONE)
{
bool success = false;
const char* type = NULL;
char const* type = NULL;
if (allocation == TR_PREALLOCATE_FULL)
{
@ -249,7 +249,7 @@ static int cached_file_open(struct tr_cached_file* o, const char* filename, bool
fail:
{
const int err = error->code;
int const err = error->code;
tr_error_free(error);
if (fd != TR_BAD_SYS_FILE)
@ -268,13 +268,13 @@ fail:
struct tr_fileset
{
struct tr_cached_file* begin;
const struct tr_cached_file* end;
struct tr_cached_file const* end;
};
static void fileset_construct(struct tr_fileset* set, int n)
{
struct tr_cached_file* o;
const struct tr_cached_file TR_CACHED_FILE_INIT = { false, TR_BAD_SYS_FILE, 0, 0, 0 };
struct tr_cached_file const TR_CACHED_FILE_INIT = { false, TR_BAD_SYS_FILE, 0, 0, 0 };
set->begin = tr_new(struct tr_cached_file, n);
set->end = set->begin + n;
@ -393,7 +393,7 @@ static void ensureSessionFdInfoExists(tr_session* session)
if (session->fdInfo == NULL)
{
struct tr_fdInfo* i;
const int FILE_CACHE_SIZE = 32;
int const FILE_CACHE_SIZE = 32;
/* Create the local file cache */
i = tr_new0(struct tr_fdInfo, 1);
@ -407,8 +407,8 @@ static void ensureSessionFdInfoExists(tr_session* session)
if (!getrlimit(RLIMIT_NOFILE, &limit))
{
const int old_limit = (int)limit.rlim_cur;
const int new_limit = MIN(limit.rlim_max, FD_SETSIZE);
int const old_limit = (int)limit.rlim_cur;
int const new_limit = MIN(limit.rlim_max, FD_SETSIZE);
if (new_limit != old_limit)
{
@ -449,7 +449,7 @@ static struct tr_fileset* get_fileset(tr_session* session)
return &session->fdInfo->fileset;
}
void tr_fdFileClose(tr_session* s, const tr_torrent* tor, tr_file_index_t i)
void tr_fdFileClose(tr_session* s, tr_torrent const* tor, tr_file_index_t i)
{
struct tr_cached_file* o;
@ -501,7 +501,7 @@ void tr_fdTorrentClose(tr_session* session, int torrent_id)
}
/* returns an fd on success, or a TR_BAD_SYS_FILE on failure and sets errno */
tr_sys_file_t tr_fdFileCheckout(tr_session* session, int torrent_id, tr_file_index_t i, const char* filename, bool writable,
tr_sys_file_t tr_fdFileCheckout(tr_session* session, int torrent_id, tr_file_index_t i, char const* filename, bool writable,
tr_preallocation_mode allocation, uint64_t file_size)
{
struct tr_fileset* set = get_fileset(session);
@ -518,7 +518,7 @@ tr_sys_file_t tr_fdFileCheckout(tr_session* session, int torrent_id, tr_file_ind
if (!cached_file_is_open(o))
{
const int err = cached_file_open(o, filename, writable, allocation, file_size);
int const err = cached_file_open(o, filename, writable, allocation, file_size);
if (err)
{

View File

@ -38,7 +38,7 @@
*
* @see tr_fdFileClose
*/
tr_sys_file_t tr_fdFileCheckout(tr_session* session, int torrent_id, tr_file_index_t file_num, const char* filename,
tr_sys_file_t tr_fdFileCheckout(tr_session* session, int torrent_id, tr_file_index_t file_num, char const* filename,
bool do_write, tr_preallocation_mode preallocation_mode, uint64_t preallocation_file_size);
tr_sys_file_t tr_fdFileGetCached(tr_session* session, int torrent_id, tr_file_index_t file_num, bool doWrite);
@ -53,7 +53,7 @@ bool tr_fdFileGetCachedMTime(tr_session* session, int torrent_id, tr_file_index_
*
* @see tr_fdFileCheckout
*/
void tr_fdFileClose(tr_session* session, const tr_torrent* tor, tr_file_index_t file_num);
void tr_fdFileClose(tr_session* session, tr_torrent const* tor, tr_file_index_t file_num);
/**
* Closes all the files associated with a given torrent id

View File

@ -89,7 +89,7 @@ static void set_system_error_if_file_found(tr_error** error, int code)
}
}
static void stat_to_sys_path_info(const struct stat* sb, tr_sys_path_info* info)
static void stat_to_sys_path_info(struct stat const* sb, tr_sys_path_info* info)
{
if (S_ISREG(sb->st_mode))
{
@ -113,7 +113,7 @@ static void set_file_for_single_pass(tr_sys_file_t handle)
/* Set hints about the lookahead buffer and caching. It's okay
for these to fail silently, so don't let them affect errno */
const int err = errno;
int const err = errno;
if (handle == TR_BAD_SYS_FILE)
{
@ -138,7 +138,7 @@ static void set_file_for_single_pass(tr_sys_file_t handle)
#ifndef HAVE_MKDIRP
static bool create_path(const char* path_in, int permissions, tr_error** error)
static bool create_path(char const* path_in, int permissions, tr_error** error)
{
char* p;
char* pp;
@ -217,7 +217,7 @@ static bool create_path(const char* path_in, int permissions, tr_error** error)
#endif
bool tr_sys_path_exists(const char* path, tr_error** error)
bool tr_sys_path_exists(char const* path, tr_error** error)
{
bool ret;
@ -233,7 +233,7 @@ bool tr_sys_path_exists(const char* path, tr_error** error)
return ret;
}
bool tr_sys_path_get_info(const char* path, int flags, tr_sys_path_info* info, tr_error** error)
bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, tr_error** error)
{
bool ret;
struct stat sb;
@ -262,14 +262,14 @@ bool tr_sys_path_get_info(const char* path, int flags, tr_sys_path_info* info, t
return ret;
}
bool tr_sys_path_is_relative(const char* path)
bool tr_sys_path_is_relative(char const* path)
{
assert(path != NULL);
return path[0] != '/';
}
bool tr_sys_path_is_same(const char* path1, const char* path2, tr_error** error)
bool tr_sys_path_is_same(char const* path1, char const* path2, tr_error** error)
{
bool ret = false;
struct stat sb1, sb2;
@ -289,7 +289,7 @@ bool tr_sys_path_is_same(const char* path1, const char* path2, tr_error** error)
return ret;
}
char* tr_sys_path_resolve(const char* path, tr_error** error)
char* tr_sys_path_resolve(char const* path, tr_error** error)
{
char* ret = NULL;
char* tmp = NULL;
@ -335,7 +335,7 @@ char* tr_sys_path_resolve(const char* path, tr_error** error)
return ret;
}
char* tr_sys_path_basename(const char* path, tr_error** error)
char* tr_sys_path_basename(char const* path, tr_error** error)
{
char* ret = NULL;
char* tmp;
@ -359,7 +359,7 @@ char* tr_sys_path_basename(const char* path, tr_error** error)
return ret;
}
char* tr_sys_path_dirname(const char* path, tr_error** error)
char* tr_sys_path_dirname(char const* path, tr_error** error)
{
char* ret = NULL;
char* tmp;
@ -383,7 +383,7 @@ char* tr_sys_path_dirname(const char* path, tr_error** error)
return ret;
}
bool tr_sys_path_rename(const char* src_path, const char* dst_path, tr_error** error)
bool tr_sys_path_rename(char const* src_path, char const* dst_path, tr_error** error)
{
bool ret;
@ -400,7 +400,7 @@ bool tr_sys_path_rename(const char* src_path, const char* dst_path, tr_error** e
return ret;
}
bool tr_sys_path_remove(const char* path, tr_error** error)
bool tr_sys_path_remove(char const* path, tr_error** error)
{
bool ret;
@ -442,7 +442,7 @@ tr_sys_file_t tr_sys_file_get_std(tr_std_sys_file_t std_file, tr_error** error)
return ret;
}
tr_sys_file_t tr_sys_file_open(const char* path, int flags, int permissions, tr_error** error)
tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, tr_error** error)
{
tr_sys_file_t ret;
int native_flags = 0;
@ -653,7 +653,7 @@ bool tr_sys_file_read_at(tr_sys_file_t handle, void* buffer, uint64_t size, uint
return ret;
}
bool tr_sys_file_write(tr_sys_file_t handle, const void* buffer, uint64_t size, uint64_t* bytes_written, tr_error** error)
bool tr_sys_file_write(tr_sys_file_t handle, void const* buffer, uint64_t size, uint64_t* bytes_written, tr_error** error)
{
bool ret = false;
ssize_t my_bytes_written;
@ -682,7 +682,7 @@ bool tr_sys_file_write(tr_sys_file_t handle, const void* buffer, uint64_t size,
return ret;
}
bool tr_sys_file_write_at(tr_sys_file_t handle, const void* buffer, uint64_t size, uint64_t offset, uint64_t* bytes_written,
bool tr_sys_file_write_at(tr_sys_file_t handle, void const* buffer, uint64_t size, uint64_t offset, uint64_t* bytes_written,
tr_error** error)
{
bool ret = false;
@ -927,7 +927,7 @@ void* tr_sys_file_map_for_reading(tr_sys_file_t handle, uint64_t offset, uint64_
return ret;
}
bool tr_sys_file_unmap(const void* address, uint64_t size, tr_error** error)
bool tr_sys_file_unmap(void const* address, uint64_t size, tr_error** error)
{
bool ret;
@ -1011,7 +1011,7 @@ char* tr_sys_dir_get_current(tr_error** error)
if (ret == NULL)
{
const int err = errno;
int const err = errno;
tr_free(tmp);
errno = err;
}
@ -1025,7 +1025,7 @@ char* tr_sys_dir_get_current(tr_error** error)
return ret;
}
bool tr_sys_dir_create(const char* path, int flags, int permissions, tr_error** error)
bool tr_sys_dir_create(char const* path, int flags, int permissions, tr_error** error)
{
bool ret;
tr_error* my_error = NULL;
@ -1099,7 +1099,7 @@ bool tr_sys_dir_create_temp(char* path_template, tr_error** error)
return ret;
}
tr_sys_dir_t tr_sys_dir_open(const char* path, tr_error** error)
tr_sys_dir_t tr_sys_dir_open(char const* path, tr_error** error)
{
tr_sys_dir_t ret;
@ -1120,9 +1120,9 @@ tr_sys_dir_t tr_sys_dir_open(const char* path, tr_error** error)
return ret;
}
const char* tr_sys_dir_read_name(tr_sys_dir_t handle, tr_error** error)
char const* tr_sys_dir_read_name(tr_sys_dir_t handle, tr_error** error)
{
const char* ret = NULL;
char const* ret = NULL;
struct dirent* entry;
assert(handle != TR_BAD_SYS_DIR);

View File

@ -30,14 +30,14 @@
static tr_session* session;
static char* create_test_dir(const char* name)
static char* create_test_dir(char const* name)
{
char* const test_dir = tr_buildPath(tr_sessionGetConfigDir(session), name, NULL);
tr_sys_dir_create(test_dir, 0, 0777, NULL);
return test_dir;
}
static bool create_symlink(const char* dst_path, const char* src_path, bool dst_is_dir)
static bool create_symlink(char const* dst_path, char const* src_path, bool dst_is_dir)
{
#ifndef _WIN32
@ -64,7 +64,7 @@ static bool create_symlink(const char* dst_path, const char* src_path, bool dst_
#endif
}
static bool create_hardlink(const char* dst_path, const char* src_path)
static bool create_hardlink(char const* dst_path, char const* src_path)
{
#ifndef _WIN32
@ -92,19 +92,19 @@ static void clear_path_info(tr_sys_path_info* info)
info->last_modified_at = (time_t)-1;
}
static bool path_contains_no_symlinks(const char* path)
static bool path_contains_no_symlinks(char const* path)
{
const char* p = path;
char const* p = path;
while (*p != '\0')
{
tr_sys_path_info info;
char* pathPart;
const char* slashPos = strchr(p, '/');
char const* slashPos = strchr(p, '/');
#ifdef _WIN32
const char* backslashPos = strchr(p, '\\');
char const* backslashPos = strchr(p, '\\');
if (slashPos == NULL || (backslashPos != NULL && backslashPos < slashPos))
{
@ -135,7 +135,7 @@ static bool path_contains_no_symlinks(const char* path)
return true;
}
static bool validate_permissions(const char* path, unsigned int permissions)
static bool validate_permissions(char const* path, unsigned int permissions)
{
#ifndef _WIN32
@ -626,11 +626,11 @@ static int test_path_resolve(void)
struct xname_test_data
{
const char* input;
const char* output;
char const* input;
char const* output;
};
static int test_path_xname(const struct xname_test_data* data, size_t data_size, char* (*func)(const char*, tr_error**))
static int test_path_xname(struct xname_test_data const* data, size_t data_size, char* (*func)(char const*, tr_error**))
{
for (size_t i = 0; i < data_size; ++i)
{
@ -657,7 +657,7 @@ static int test_path_xname(const struct xname_test_data* data, size_t data_size,
static int test_path_basename_dirname(void)
{
const struct xname_test_data common_xname_tests[] =
struct xname_test_data const common_xname_tests[] =
{
{ "/", "/" },
{ "", "." },
@ -704,7 +704,7 @@ static int test_path_basename_dirname(void)
return 1;
}
const struct xname_test_data basename_tests[] =
struct xname_test_data const basename_tests[] =
{
{ "a", "a" },
{ "aa", "aa" },
@ -733,7 +733,7 @@ static int test_path_basename_dirname(void)
return 1;
}
const struct xname_test_data dirname_tests[] =
struct xname_test_data const dirname_tests[] =
{
{ "/a/b/c", "/a/b" },
{ "a/b/c", "a/b" },
@ -1431,11 +1431,11 @@ static int test_dir_create(void)
return 0;
}
static int test_dir_read_impl(const char* path, bool* have1, bool* have2)
static int test_dir_read_impl(char const* path, bool* have1, bool* have2)
{
tr_error* err = NULL;
tr_sys_dir_t dd;
const char* name;
char const* name;
*have1 = *have2 = false;
@ -1530,7 +1530,7 @@ static int test_dir_read(void)
int main(void)
{
const testFunc tests[] =
testFunc const tests[] =
{
test_get_info,
test_path_exists,

View File

@ -64,7 +64,7 @@ static void set_system_error_if_file_found(tr_error** error, DWORD code)
}
}
static time_t filetime_to_unix_time(const FILETIME* t)
static time_t filetime_to_unix_time(FILETIME const* t)
{
uint64_t tmp = 0;
@ -79,7 +79,7 @@ static time_t filetime_to_unix_time(const FILETIME* t)
return tmp / 1000000UL;
}
static void stat_to_sys_path_info(DWORD attributes, DWORD size_low, DWORD size_high, const FILETIME* mtime,
static void stat_to_sys_path_info(DWORD attributes, DWORD size_low, DWORD size_high, FILETIME const* mtime,
tr_sys_path_info* info)
{
assert(mtime != NULL);
@ -110,12 +110,12 @@ static inline bool is_slash(char c)
return c == '\\' || c == '/';
}
static inline bool is_unc_path(const char* path)
static inline bool is_unc_path(char const* path)
{
return is_slash(path[0]) && path[1] == path[0];
}
static bool is_valid_path(const char* path)
static bool is_valid_path(char const* path)
{
if (is_unc_path(path))
{
@ -126,7 +126,7 @@ static bool is_valid_path(const char* path)
}
else
{
const char* colon_pos = strchr(path, ':');
char const* colon_pos = strchr(path, ':');
if (colon_pos != NULL)
{
@ -142,19 +142,19 @@ static bool is_valid_path(const char* path)
return strpbrk(path, "<>:\"|?*") == NULL;
}
static wchar_t* path_to_native_path_ex(const char* path, int extra_chars_after, int* real_result_size)
static wchar_t* path_to_native_path_ex(char const* path, int extra_chars_after, int* real_result_size)
{
/* Extending maximum path length limit up to ~32K. See "Naming Files, Paths, and Namespaces"
(https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx) for more info */
const wchar_t local_prefix[] = { '\\', '\\', '?', '\\' };
const wchar_t unc_prefix[] = { '\\', '\\', '?', '\\', 'U', 'N', 'C', '\\' };
wchar_t const local_prefix[] = { '\\', '\\', '?', '\\' };
wchar_t const unc_prefix[] = { '\\', '\\', '?', '\\', 'U', 'N', 'C', '\\' };
const bool is_relative = tr_sys_path_is_relative(path);
const bool is_unc = is_unc_path(path);
bool const is_relative = tr_sys_path_is_relative(path);
bool const is_unc = is_unc_path(path);
/* `-2` for UNC since we overwrite existing prefix slashes */
const int extra_chars_before = is_relative ? 0 : (is_unc ? ARRAYSIZE(unc_prefix) - 2 : ARRAYSIZE(local_prefix));
int const extra_chars_before = is_relative ? 0 : (is_unc ? ARRAYSIZE(unc_prefix) - 2 : ARRAYSIZE(local_prefix));
/* TODO (?): assert (!is_relative); */
@ -197,12 +197,12 @@ static wchar_t* path_to_native_path_ex(const char* path, int extra_chars_after,
return wide_path;
}
static wchar_t* path_to_native_path(const char* path)
static wchar_t* path_to_native_path(char const* path)
{
return path_to_native_path_ex(path, 0, NULL);
}
static tr_sys_file_t open_file(const char* path, DWORD access, DWORD disposition, DWORD flags, tr_error** error)
static tr_sys_file_t open_file(char const* path, DWORD access, DWORD disposition, DWORD flags, tr_error** error)
{
tr_sys_file_t ret = TR_BAD_SYS_FILE;
wchar_t* wide_path;
@ -227,7 +227,7 @@ static tr_sys_file_t open_file(const char* path, DWORD access, DWORD disposition
return ret;
}
static bool create_dir(const char* path, int flags, int permissions, bool okay_if_exists, tr_error** error)
static bool create_dir(char const* path, int flags, int permissions, bool okay_if_exists, tr_error** error)
{
bool ret;
wchar_t* wide_path;
@ -256,7 +256,7 @@ static bool create_dir(const char* path, int flags, int permissions, bool okay_i
if (!ret && error_code == ERROR_ALREADY_EXISTS && okay_if_exists)
{
const DWORD attributes = GetFileAttributesW(wide_path);
DWORD const attributes = GetFileAttributesW(wide_path);
if (attributes != INVALID_FILE_ATTRIBUTES &&
(attributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
@ -275,7 +275,7 @@ static bool create_dir(const char* path, int flags, int permissions, bool okay_i
return ret;
}
static void create_temp_path(char* path_template, void (* callback)(const char* path, void* param,
static void create_temp_path(char* path_template, void (* callback)(char const* path, void* param,
tr_error** error), void* callback_param, tr_error** error)
{
char* path;
@ -297,7 +297,7 @@ static void create_temp_path(char* path_template, void (* callback)(const char*
while (i > 0 && path_template[i - 1] == 'X')
{
const int c = tr_rand_int(26 + 26 + 10);
int const c = tr_rand_int(26 + 26 + 10);
path[i - 1] = c < 26 ? c + 'A' : (c < 26 + 26 ? (c - 26) + 'a' : (c - 26 - 26) + '0');
--i;
}
@ -326,7 +326,7 @@ static void create_temp_path(char* path_template, void (* callback)(const char*
tr_free(path);
}
bool tr_sys_path_exists(const char* path, tr_error** error)
bool tr_sys_path_exists(char const* path, tr_error** error)
{
bool ret = false;
wchar_t* wide_path;
@ -369,7 +369,7 @@ bool tr_sys_path_exists(const char* path, tr_error** error)
return ret;
}
bool tr_sys_path_get_info(const char* path, int flags, tr_sys_path_info* info, tr_error** error)
bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, tr_error** error)
{
bool ret = false;
wchar_t* wide_path;
@ -430,7 +430,7 @@ bool tr_sys_path_get_info(const char* path, int flags, tr_sys_path_info* info, t
return ret;
}
bool tr_sys_path_is_relative(const char* path)
bool tr_sys_path_is_relative(char const* path)
{
assert(path != NULL);
@ -449,7 +449,7 @@ bool tr_sys_path_is_relative(const char* path)
return true;
}
bool tr_sys_path_is_same(const char* path1, const char* path2, tr_error** error)
bool tr_sys_path_is_same(char const* path1, char const* path2, tr_error** error)
{
bool ret = false;
wchar_t* wide_path1 = NULL;
@ -514,7 +514,7 @@ cleanup:
return ret;
}
char* tr_sys_path_resolve(const char* path, tr_error** error)
char* tr_sys_path_resolve(char const* path, tr_error** error)
{
char* ret = NULL;
wchar_t* wide_path;
@ -579,7 +579,7 @@ cleanup:
return ret;
}
char* tr_sys_path_basename(const char* path, tr_error** error)
char* tr_sys_path_basename(char const* path, tr_error** error)
{
if (path == NULL || path[0] == '\0')
{
@ -592,7 +592,7 @@ char* tr_sys_path_basename(const char* path, tr_error** error)
return NULL;
}
const char* end = path + strlen(path);
char const* end = path + strlen(path);
while (end > path && is_slash(*(end - 1)))
{
@ -604,7 +604,7 @@ char* tr_sys_path_basename(const char* path, tr_error** error)
return tr_strdup("/");
}
const char* name = end;
char const* name = end;
while (name > path && *(name - 1) != ':' && !is_slash(*(name - 1)))
{
@ -619,7 +619,7 @@ char* tr_sys_path_basename(const char* path, tr_error** error)
return tr_strndup(name, end - name);
}
char* tr_sys_path_dirname(const char* path, tr_error** error)
char* tr_sys_path_dirname(char const* path, tr_error** error)
{
if (path == NULL || path[0] == '\0')
{
@ -632,14 +632,14 @@ char* tr_sys_path_dirname(const char* path, tr_error** error)
return NULL;
}
const bool is_unc = is_unc_path(path);
bool const is_unc = is_unc_path(path);
if (is_unc && path[2] == '\0')
{
return tr_strdup(path);
}
const char* end = path + strlen(path);
char const* end = path + strlen(path);
while (end > path && is_slash(*(end - 1)))
{
@ -651,7 +651,7 @@ char* tr_sys_path_dirname(const char* path, tr_error** error)
return tr_strdup("/");
}
const char* name = end;
char const* name = end;
while (name > path && *(name - 1) != ':' && !is_slash(*(name - 1)))
{
@ -676,7 +676,7 @@ char* tr_sys_path_dirname(const char* path, tr_error** error)
return tr_strndup(path, name - path);
}
bool tr_sys_path_rename(const char* src_path, const char* dst_path, tr_error** error)
bool tr_sys_path_rename(char const* src_path, char const* dst_path, tr_error** error)
{
bool ret = false;
wchar_t* wide_src_path;
@ -723,7 +723,7 @@ bool tr_sys_path_rename(const char* src_path, const char* dst_path, tr_error** e
return ret;
}
bool tr_sys_path_remove(const char* path, tr_error** error)
bool tr_sys_path_remove(char const* path, tr_error** error)
{
bool ret = false;
wchar_t* wide_path;
@ -734,7 +734,7 @@ bool tr_sys_path_remove(const char* path, tr_error** error)
if (wide_path != NULL)
{
const DWORD attributes = GetFileAttributesW(wide_path);
DWORD const attributes = GetFileAttributesW(wide_path);
if (attributes != INVALID_FILE_ATTRIBUTES)
{
@ -795,7 +795,7 @@ tr_sys_file_t tr_sys_file_get_std(tr_std_sys_file_t std_file, tr_error** error)
return ret;
}
tr_sys_file_t tr_sys_file_open(const char* path, int flags, int permissions, tr_error** error)
tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, tr_error** error)
{
tr_sys_file_t ret;
DWORD native_access = 0;
@ -859,7 +859,7 @@ tr_sys_file_t tr_sys_file_open(const char* path, int flags, int permissions, tr_
return ret;
}
static void file_open_temp_callback(const char* path, void* param, tr_error** error)
static void file_open_temp_callback(char const* path, void* param, tr_error** error)
{
tr_sys_file_t* result = (tr_sys_file_t*)param;
@ -1018,7 +1018,7 @@ bool tr_sys_file_read_at(tr_sys_file_t handle, void* buffer, uint64_t size, uint
return ret;
}
bool tr_sys_file_write(tr_sys_file_t handle, const void* buffer, uint64_t size, uint64_t* bytes_written, tr_error** error)
bool tr_sys_file_write(tr_sys_file_t handle, void const* buffer, uint64_t size, uint64_t* bytes_written, tr_error** error)
{
bool ret = false;
DWORD my_bytes_written;
@ -1049,7 +1049,7 @@ bool tr_sys_file_write(tr_sys_file_t handle, const void* buffer, uint64_t size,
return ret;
}
bool tr_sys_file_write_at(tr_sys_file_t handle, const void* buffer, uint64_t size, uint64_t offset, uint64_t* bytes_written,
bool tr_sys_file_write_at(tr_sys_file_t handle, void const* buffer, uint64_t size, uint64_t offset, uint64_t* bytes_written,
tr_error** error)
{
bool ret = false;
@ -1192,7 +1192,7 @@ void* tr_sys_file_map_for_reading(tr_sys_file_t handle, uint64_t offset, uint64_
return ret;
}
bool tr_sys_file_unmap(const void* address, uint64_t size, tr_error** error)
bool tr_sys_file_unmap(void const* address, uint64_t size, tr_error** error)
{
bool ret;
@ -1278,12 +1278,12 @@ char* tr_sys_dir_get_current(tr_error** error)
return ret;
}
bool tr_sys_dir_create(const char* path, int flags, int permissions, tr_error** error)
bool tr_sys_dir_create(char const* path, int flags, int permissions, tr_error** error)
{
return create_dir(path, flags, permissions, true, error);
}
static void dir_create_temp_callback(const char* path, void* param, tr_error** error)
static void dir_create_temp_callback(char const* path, void* param, tr_error** error)
{
bool* result = (bool*)param;
@ -1303,7 +1303,7 @@ bool tr_sys_dir_create_temp(char* path_template, tr_error** error)
return ret;
}
tr_sys_dir_t tr_sys_dir_open(const char* path, tr_error** error)
tr_sys_dir_t tr_sys_dir_open(char const* path, tr_error** error)
{
tr_sys_dir_t ret;
int pattern_size;
@ -1339,7 +1339,7 @@ tr_sys_dir_t tr_sys_dir_open(const char* path, tr_error** error)
return ret;
}
const char* tr_sys_dir_read_name(tr_sys_dir_t handle, tr_error** error)
char const* tr_sys_dir_read_name(tr_sys_dir_t handle, tr_error** error)
{
char* ret;
DWORD error_code = ERROR_SUCCESS;

View File

@ -48,7 +48,7 @@ bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_siz
if (found_eol || buffer_size == 0 || bytes_read == 0)
{
const int64_t delta = -(int64_t)bytes_read + i + (found_eol ? 1 : 0);
int64_t const delta = -(int64_t)bytes_read + i + (found_eol ? 1 : 0);
if (delta != 0)
{
@ -76,7 +76,7 @@ bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_siz
return ret;
}
bool tr_sys_file_write_line(tr_sys_file_t handle, const char* buffer, tr_error** error)
bool tr_sys_file_write_line(tr_sys_file_t handle, char const* buffer, tr_error** error)
{
bool ret;
@ -93,7 +93,7 @@ bool tr_sys_file_write_line(tr_sys_file_t handle, const char* buffer, tr_error**
return ret;
}
bool tr_sys_file_write_fmt(tr_sys_file_t handle, const char* format, tr_error** error, ...)
bool tr_sys_file_write_fmt(tr_sys_file_t handle, char const* format, tr_error** error, ...)
{
bool ret = false;
char* buffer;

View File

@ -149,7 +149,7 @@ tr_sys_path_info;
*
* @return `True` on success, `false` otherwise (with `error` set accordingly).
*/
bool tr_sys_path_get_info(const char* path, int flags, tr_sys_path_info* info, struct tr_error** error);
bool tr_sys_path_get_info(char const* path, int flags, tr_sys_path_info* info, struct tr_error** error);
/**
* @brief Portability wrapper for `access ()`.
@ -162,7 +162,7 @@ bool tr_sys_path_get_info(const char* path, int flags, tr_sys_path_info* info, s
* be returned in case of error; if you need to distinguish the two,
* check if `error` is `NULL` afterwards.
*/
bool tr_sys_path_exists(const char* path, struct tr_error** error);
bool tr_sys_path_exists(char const* path, struct tr_error** error);
/**
* @brief Check whether path is relative.
@ -173,7 +173,7 @@ bool tr_sys_path_exists(const char* path, struct tr_error** error);
*
* @return `True` if path is relative, `false` otherwise
*/
bool tr_sys_path_is_relative(const char* path);
bool tr_sys_path_is_relative(char const* path);
/**
* @brief Test to see if the two filenames point to the same file.
@ -188,7 +188,7 @@ bool tr_sys_path_is_relative(const char* path);
* if you need to distinguish the two, check if `error` is `NULL`
* afterwards.
*/
bool tr_sys_path_is_same(const char* path1, const char* path2, struct tr_error** error);
bool tr_sys_path_is_same(char const* path1, char const* path2, struct tr_error** error);
/**
* @brief Portability wrapper for `realpath ()`.
@ -202,7 +202,7 @@ bool tr_sys_path_is_same(const char* path1, const char* path2, struct tr_error**
* when no longer needed), `NULL` otherwise (with `error` set
* accordingly).
*/
char* tr_sys_path_resolve(const char* path, struct tr_error** error);
char* tr_sys_path_resolve(char const* path, struct tr_error** error);
/**
* @brief Portability wrapper for `basename ()`.
@ -216,7 +216,7 @@ char* tr_sys_path_resolve(const char* path, struct tr_error** error);
* it when no longer needed), `NULL` otherwise (with `error` set
* accordingly).
*/
char* tr_sys_path_basename(const char* path, struct tr_error** error);
char* tr_sys_path_basename(char const* path, struct tr_error** error);
/**
* @brief Portability wrapper for `dirname ()`.
@ -230,7 +230,7 @@ char* tr_sys_path_basename(const char* path, struct tr_error** error);
* when no longer needed), `NULL` otherwise (with `error` set
* accordingly).
*/
char* tr_sys_path_dirname(const char* path, struct tr_error** error);
char* tr_sys_path_dirname(char const* path, struct tr_error** error);
/**
* @brief Portability wrapper for `rename ()`.
@ -244,7 +244,7 @@ char* tr_sys_path_dirname(const char* path, struct tr_error** error);
* Rename will generally only succeed if both source and destination are
* on the same partition.
*/
bool tr_sys_path_rename(const char* src_path, const char* dst_path, struct tr_error** error);
bool tr_sys_path_rename(char const* src_path, char const* dst_path, struct tr_error** error);
/**
* @brief Portability wrapper for `remove ()`.
@ -257,7 +257,7 @@ bool tr_sys_path_rename(const char* src_path, const char* dst_path, struct tr_er
* Directory removal will only succeed if it is empty (contains no other
* files and directories).
*/
bool tr_sys_path_remove(const char* path, struct tr_error** error);
bool tr_sys_path_remove(char const* path, struct tr_error** error);
/* File-related wrappers */
@ -287,7 +287,7 @@ tr_sys_file_t tr_sys_file_get_std(tr_std_sys_file_t std_file, struct tr_error**
* @return Opened file descriptor on success, `TR_BAD_SYS_FILE` otherwise (with
* `error` set accordingly).
*/
tr_sys_file_t tr_sys_file_open(const char* path, int flags, int permissions, struct tr_error** error);
tr_sys_file_t tr_sys_file_open(char const* path, int flags, int permissions, struct tr_error** error);
/**
* @brief Portability wrapper for `mkstemp ()`.
@ -390,7 +390,7 @@ bool tr_sys_file_read_at(tr_sys_file_t handle, void* buffer, uint64_t size, uint
*
* @return `True` on success, `false` otherwise (with `error` set accordingly).
*/
bool tr_sys_file_write(tr_sys_file_t handle, const void* buffer, uint64_t size, uint64_t* bytes_written,
bool tr_sys_file_write(tr_sys_file_t handle, void const* buffer, uint64_t size, uint64_t* bytes_written,
struct tr_error** error);
/**
@ -408,7 +408,7 @@ bool tr_sys_file_write(tr_sys_file_t handle, const void* buffer, uint64_t size,
*
* @return `True` on success, `false` otherwise (with `error` set accordingly).
*/
bool tr_sys_file_write_at(tr_sys_file_t handle, const void* buffer, uint64_t size, uint64_t offset, uint64_t* bytes_written,
bool tr_sys_file_write_at(tr_sys_file_t handle, void const* buffer, uint64_t size, uint64_t offset, uint64_t* bytes_written,
struct tr_error** error);
/**
@ -484,7 +484,7 @@ void* tr_sys_file_map_for_reading(tr_sys_file_t handle, uint64_t offset, uint64_
*
* @return `True` on success, `false` otherwise (with `error` set accordingly).
*/
bool tr_sys_file_unmap(const void* address, uint64_t size, struct tr_error** error);
bool tr_sys_file_unmap(void const* address, uint64_t size, struct tr_error** error);
/**
* @brief Portability wrapper for `flock ()`.
@ -542,7 +542,7 @@ bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_siz
*
* @return `True` on success, `false` otherwise (with `error` set accordingly).
*/
bool tr_sys_file_write_line(tr_sys_file_t handle, const char* buffer, struct tr_error** error);
bool tr_sys_file_write_line(tr_sys_file_t handle, char const* buffer, struct tr_error** error);
/**
* @brief Portability wrapper for `fprintf ()`.
@ -561,7 +561,7 @@ bool tr_sys_file_write_line(tr_sys_file_t handle, const char* buffer, struct tr_
*
* @return `True` on success, `false` otherwise (with `error` set accordingly).
*/
bool tr_sys_file_write_fmt(tr_sys_file_t handle, const char* format, struct tr_error** error, ...);
bool tr_sys_file_write_fmt(tr_sys_file_t handle, char const* format, struct tr_error** error, ...);
/* Directory-related wrappers */
@ -589,7 +589,7 @@ char* tr_sys_dir_get_current(struct tr_error** error);
*
* @return `True` on success, `false` otherwise (with `error` set accordingly).
*/
bool tr_sys_dir_create(const char* path, int flags, int permissions, struct tr_error** error);
bool tr_sys_dir_create(char const* path, int flags, int permissions, struct tr_error** error);
/**
* @brief Portability wrapper for `mkdtemp ()`.
@ -616,7 +616,7 @@ bool tr_sys_dir_create_temp(char* path_template, struct tr_error** error);
* @return Opened directory descriptor on success, `TR_BAD_SYS_DIR` otherwise
* (with `error` set accordingly).
*/
tr_sys_dir_t tr_sys_dir_open(const char* path, struct tr_error** error);
tr_sys_dir_t tr_sys_dir_open(char const* path, struct tr_error** error);
/**
* @brief Portability wrapper for `readdir ()`.
@ -631,7 +631,7 @@ tr_sys_dir_t tr_sys_dir_open(const char* path, struct tr_error** error);
* of directory; if you need to distinguish the two, check if `error`
* is `NULL` afterwards.
*/
const char* tr_sys_dir_read_name(tr_sys_dir_t handle, struct tr_error** error);
char const* tr_sys_dir_read_name(tr_sys_dir_t handle, struct tr_error** error);
/**
* @brief Portability wrapper for `closedir ()`.

View File

@ -147,9 +147,9 @@ struct tr_handshake
} \
while (0)
static const char* getStateName(const handshake_state_t state)
static char const* getStateName(handshake_state_t const state)
{
static const char* const state_strings[N_STATES] =
static char const* const state_strings[N_STATES] =
{
"awaiting handshake", /* AWAITING_HANDSHAKE */
"awaiting peer id", /* AWAITING_PEER_ID */
@ -181,8 +181,8 @@ static void setReadState(tr_handshake* handshake, handshake_state_t state)
static bool buildHandshakeMessage(tr_handshake* handshake, uint8_t* buf)
{
const unsigned char* peer_id = NULL;
const uint8_t* torrentHash;
unsigned char const* peer_id = NULL;
uint8_t const* torrentHash;
tr_torrent* tor;
bool success;
@ -314,7 +314,7 @@ static handshake_parse_err_t parseHandshake(tr_handshake* handshake, struct evbu
static void sendYa(tr_handshake* handshake)
{
int len;
const uint8_t* public_key;
uint8_t const* public_key;
char outbuf[KEY_LEN + PadA_MAXLEN];
char* walk = outbuf;
@ -335,7 +335,7 @@ static void sendYa(tr_handshake* handshake)
tr_peerIoWriteBytes(handshake->io, outbuf, walk - outbuf, false);
}
static uint32_t getCryptoProvide(const tr_handshake* handshake)
static uint32_t getCryptoProvide(tr_handshake const* handshake)
{
uint32_t provide = 0;
@ -354,7 +354,7 @@ static uint32_t getCryptoProvide(const tr_handshake* handshake)
return provide;
}
static uint32_t getCryptoSelect(const tr_handshake* handshake, uint32_t crypto_provide)
static uint32_t getCryptoSelect(tr_handshake const* handshake, uint32_t crypto_provide)
{
uint32_t choices[2];
int i;
@ -388,7 +388,7 @@ static uint32_t getCryptoSelect(const tr_handshake* handshake, uint32_t crypto_p
return 0;
}
static void computeRequestHash(const tr_handshake* handshake, const char* name, uint8_t* hash)
static void computeRequestHash(tr_handshake const* handshake, char const* name, uint8_t* hash)
{
tr_cryptoSecretKeySha1(handshake->crypto, name, 4, NULL, 0, hash);
}
@ -509,8 +509,8 @@ static ReadState readYb(tr_handshake* handshake, struct evbuffer* inbuf)
static ReadState readVC(tr_handshake* handshake, struct evbuffer* inbuf)
{
uint8_t tmp[VC_LENGTH];
const int key_len = VC_LENGTH;
const uint8_t key[VC_LENGTH] = { 0, 0, 0, 0, 0, 0, 0, 0 };
int const key_len = VC_LENGTH;
uint8_t const key[VC_LENGTH] = { 0, 0, 0, 0, 0, 0, 0, 0 };
/* note: this works w/o having to `unwind' the buffer if
* we read too much, but it is pretty brute-force.
@ -545,7 +545,7 @@ static ReadState readCryptoSelect(tr_handshake* handshake, struct evbuffer* inbu
{
uint16_t pad_d_len;
uint32_t crypto_select;
static const size_t needlen = sizeof(uint32_t) + sizeof(uint16_t);
static size_t const needlen = sizeof(uint32_t) + sizeof(uint16_t);
if (evbuffer_get_length(inbuf) < needlen)
{
@ -579,7 +579,7 @@ static ReadState readCryptoSelect(tr_handshake* handshake, struct evbuffer* inbu
static ReadState readPadD(tr_handshake* handshake, struct evbuffer* inbuf)
{
const size_t needlen = handshake->pad_d_len;
size_t const needlen = handshake->pad_d_len;
dbgmsg(handshake, "pad d: need %zu, got %zu", needlen, evbuffer_get_length(inbuf));
@ -657,7 +657,7 @@ static ReadState readHandshake(tr_handshake* handshake, struct evbuffer* inbuf)
tr_peerIoReadBytes(handshake->io, inbuf, pstr, pstrlen);
pstr[pstrlen] = '\0';
if (strncmp((const char*)pstr, "BitTorrent protocol", 19) != 0)
if (strncmp((char const*)pstr, "BitTorrent protocol", 19) != 0)
{
return tr_handshakeDone(handshake, false);
}
@ -751,7 +751,7 @@ static ReadState readYa(tr_handshake* handshake, struct evbuffer* inbuf)
{
uint8_t ya[KEY_LEN];
uint8_t* walk, outbuf[KEY_LEN + PadB_MAXLEN];
const uint8_t* myKey;
uint8_t const* myKey;
int len;
dbgmsg(handshake, "in readYa... need %d, have %zu", KEY_LEN, evbuffer_get_length(inbuf));
@ -789,7 +789,7 @@ static ReadState readYa(tr_handshake* handshake, struct evbuffer* inbuf)
static ReadState readPadA(tr_handshake* handshake, struct evbuffer* inbuf)
{
/* resynchronizing on HASH ('req1',S) */
struct evbuffer_ptr ptr = evbuffer_search(inbuf, (const char*)handshake->myReq1, SHA_DIGEST_LENGTH, NULL);
struct evbuffer_ptr ptr = evbuffer_search(inbuf, (char const*)handshake->myReq1, SHA_DIGEST_LENGTH, NULL);
if (ptr.pos != -1) /* match */
{
@ -800,7 +800,7 @@ static ReadState readPadA(tr_handshake* handshake, struct evbuffer* inbuf)
}
else
{
const size_t len = evbuffer_get_length(inbuf);
size_t const len = evbuffer_get_length(inbuf);
if (len > SHA_DIGEST_LENGTH)
{
@ -823,7 +823,7 @@ static ReadState readCryptoProvide(tr_handshake* handshake, struct evbuffer* inb
uint16_t padc_len = 0;
uint32_t crypto_provide = 0;
tr_torrent* tor;
const size_t needlen = SHA_DIGEST_LENGTH + /* HASH ('req1',s) */
size_t const needlen = SHA_DIGEST_LENGTH + /* HASH ('req1',s) */
SHA_DIGEST_LENGTH + /* HASH ('req2', SKEY) xor HASH ('req3', S) */
VC_LENGTH + sizeof(crypto_provide) + sizeof(padc_len);
@ -849,8 +849,8 @@ static ReadState readCryptoProvide(tr_handshake* handshake, struct evbuffer* inb
if ((tor = tr_torrentFindFromObfuscatedHash(handshake->session, obfuscatedTorrentHash)))
{
const bool clientIsSeed = tr_torrentIsSeed(tor);
const bool peerIsSeed = tr_peerMgrPeerIsSeed(tor, tr_peerIoGetAddress(handshake->io, NULL));
bool const clientIsSeed = tr_torrentIsSeed(tor);
bool const peerIsSeed = tr_peerMgrPeerIsSeed(tor, tr_peerIoGetAddress(handshake->io, NULL));
dbgmsg(handshake, "got INCOMING connection's encrypted handshake for torrent [%s]", tr_torrentName(tor));
tr_peerIoSetTorrentHash(handshake->io, tor->info.hash);
@ -887,7 +887,7 @@ static ReadState readPadC(tr_handshake* handshake, struct evbuffer* inbuf)
{
char* padc;
uint16_t ia_len;
const size_t needlen = handshake->pad_c_len + sizeof(uint16_t);
size_t const needlen = handshake->pad_c_len + sizeof(uint16_t);
if (evbuffer_get_length(inbuf) < needlen)
{
@ -909,7 +909,7 @@ static ReadState readPadC(tr_handshake* handshake, struct evbuffer* inbuf)
static ReadState readIA(tr_handshake* handshake, struct evbuffer* inbuf)
{
const size_t needlen = handshake->ia_len;
size_t const needlen = handshake->ia_len;
struct evbuffer* outbuf;
uint32_t crypto_select;
@ -956,7 +956,7 @@ static ReadState readIA(tr_handshake* handshake, struct evbuffer* inbuf)
* PadD is reserved for future extensions to the handshake...
* standard practice at this time is for it to be zero-length */
{
const uint16_t len = 0;
uint16_t const len = 0;
evbuffer_add_uint16(outbuf, len);
}
@ -994,7 +994,7 @@ static ReadState readIA(tr_handshake* handshake, struct evbuffer* inbuf)
static ReadState readPayloadStream(tr_handshake* handshake, struct evbuffer* inbuf)
{
handshake_parse_err_t i;
const size_t needlen = HANDSHAKE_SIZE;
size_t const needlen = HANDSHAKE_SIZE;
dbgmsg(handshake, "reading payload stream... have %zu, need %zu", evbuffer_get_length(inbuf), needlen);
@ -1115,8 +1115,8 @@ static ReadState canRead(struct tr_peerIo* io, void* arg, size_t* piece)
static bool fireDoneFunc(tr_handshake* handshake, bool isConnected)
{
const uint8_t* peer_id = isConnected && handshake->havePeerID ? tr_peerIoGetPeersId(handshake->io) : NULL;
const bool success = (*handshake->doneCB)(handshake, handshake->io, handshake->haveReadAnythingFromPeer, isConnected,
uint8_t const* peer_id = isConnected && handshake->havePeerID ? tr_peerIoGetPeersId(handshake->io) : NULL;
bool const success = (*handshake->doneCB)(handshake, handshake->io, handshake->haveReadAnythingFromPeer, isConnected,
peer_id, handshake->doneUserData);
return success;
@ -1281,7 +1281,7 @@ struct tr_peerIo* tr_handshakeStealIO(tr_handshake* handshake)
return io;
}
const tr_address* tr_handshakeGetAddr(const struct tr_handshake* handshake, tr_port* port)
tr_address const* tr_handshakeGetAddr(struct tr_handshake const* handshake, tr_port* port)
{
assert(handshake != NULL);
assert(handshake->io != NULL);

View File

@ -26,13 +26,13 @@ typedef struct tr_handshake tr_handshake;
/* returns true on success, false on error */
typedef bool (* handshakeDoneCB)(struct tr_handshake* handshake, struct tr_peerIo* io, bool readAnythingFromPeer,
bool isConnected, const uint8_t* peerId, void* userData);
bool isConnected, uint8_t const* peerId, void* userData);
/** @brief instantiate a new handshake */
tr_handshake* tr_handshakeNew(struct tr_peerIo* io, tr_encryption_mode encryptionMode, handshakeDoneCB doneCB,
void* doneUserData);
const tr_address* tr_handshakeGetAddr(const struct tr_handshake* handshake, tr_port* port);
tr_address const* tr_handshakeGetAddr(struct tr_handshake const* handshake, tr_port* port);
void tr_handshakeAbort(tr_handshake* handshake);

View File

@ -31,10 +31,10 @@ void tr_historyAdd(tr_recentHistory* h, time_t now, unsigned int n)
}
}
unsigned int tr_historyGet(const tr_recentHistory* h, time_t now, unsigned int sec)
unsigned int tr_historyGet(tr_recentHistory const* h, time_t now, unsigned int sec)
{
unsigned int n = 0;
const time_t cutoff = (now ? now : tr_time()) - sec;
time_t const cutoff = (now ? now : tr_time()) - sec;
int i = h->newest;
for (;;)

View File

@ -52,4 +52,4 @@ void tr_historyAdd(tr_recentHistory*, time_t when, unsigned int n);
* @param when the current time in sec, such as from tr_time ()
* @param seconds how many seconds to count back through.
*/
unsigned int tr_historyGet(const tr_recentHistory*, time_t when, unsigned int seconds);
unsigned int tr_historyGet(tr_recentHistory const*, time_t when, unsigned int seconds);

View File

@ -42,9 +42,9 @@ static int readOrWriteBytes(tr_session* session, tr_torrent* tor, int ioMode, tr
{
tr_sys_file_t fd;
int err = 0;
const bool doWrite = ioMode >= TR_IO_WRITE;
const tr_info* const info = &tor->info;
const tr_file* const file = &info->files[fileIndex];
bool const doWrite = ioMode >= TR_IO_WRITE;
tr_info const* const info = &tor->info;
tr_file const* const file = &info->files[fileIndex];
assert(fileIndex < info->fileCount);
assert(!file->length || (fileOffset < file->length));
@ -65,7 +65,7 @@ static int readOrWriteBytes(tr_session* session, tr_torrent* tor, int ioMode, tr
{
/* it's not cached, so open/create it now */
char* subpath;
const char* base;
char const* base;
/* see if the file exists... */
if (!tr_torrentFindFile2(tor, fileIndex, &base, &subpath, NULL))
@ -86,7 +86,7 @@ static int readOrWriteBytes(tr_session* session, tr_torrent* tor, int ioMode, tr
{
/* open (and maybe create) the file */
char* filename = tr_buildPath(base, subpath, NULL);
const int prealloc = file->dnd || !doWrite ? TR_PREALLOCATE_NONE : tor->session->preallocationMode;
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)
@ -145,10 +145,10 @@ static int readOrWriteBytes(tr_session* session, tr_torrent* tor, int ioMode, tr
return err;
}
static int compareOffsetToFile(const void* a, const void* b)
static int compareOffsetToFile(void const* a, void const* b)
{
const uint64_t offset = *(const uint64_t*)a;
const tr_file* file = b;
uint64_t const offset = *(uint64_t const*)a;
tr_file const* file = b;
if (offset < file->offset)
{
@ -163,11 +163,11 @@ static int compareOffsetToFile(const void* a, const void* b)
return 0;
}
void tr_ioFindFileLocation(const tr_torrent* tor, tr_piece_index_t pieceIndex, uint32_t pieceOffset, tr_file_index_t* fileIndex,
void tr_ioFindFileLocation(tr_torrent const* tor, tr_piece_index_t pieceIndex, uint32_t pieceOffset, tr_file_index_t* fileIndex,
uint64_t* fileOffset)
{
const uint64_t offset = tr_pieceOffset(tor, pieceIndex, pieceOffset, 0);
const tr_file* file;
uint64_t const offset = tr_pieceOffset(tor, pieceIndex, pieceOffset, 0);
tr_file const* file;
assert(tr_isTorrent(tor));
assert(offset < tor->info.totalSize);
@ -191,7 +191,7 @@ static int readOrWritePiece(tr_torrent* tor, int ioMode, tr_piece_index_t pieceI
int err = 0;
tr_file_index_t fileIndex;
uint64_t fileOffset;
const tr_info* info = &tor->info;
tr_info const* info = &tor->info;
if (pieceIndex >= tor->info.pieceCount)
{
@ -202,8 +202,8 @@ static int readOrWritePiece(tr_torrent* tor, int ioMode, tr_piece_index_t pieceI
while (buflen && !err)
{
const tr_file* file = &info->files[fileIndex];
const uint64_t bytesThisPass = MIN(buflen, file->length - fileOffset);
tr_file const* file = &info->files[fileIndex];
uint64_t const bytesThisPass = MIN(buflen, file->length - fileOffset);
err = readOrWriteBytes(tor->session, tor, ioMode, fileIndex, fileOffset, buf, bytesThisPass);
buf += bytesThisPass;
@ -232,7 +232,7 @@ int tr_ioPrefetch(tr_torrent* tor, tr_piece_index_t pieceIndex, uint32_t begin,
return readOrWritePiece(tor, TR_IO_PREFETCH, pieceIndex, begin, NULL, len);
}
int tr_ioWrite(tr_torrent* tor, tr_piece_index_t pieceIndex, uint32_t begin, uint32_t len, const uint8_t* buf)
int tr_ioWrite(tr_torrent* tor, tr_piece_index_t pieceIndex, uint32_t begin, uint32_t len, uint8_t const* buf)
{
return readOrWritePiece(tor, TR_IO_WRITE, pieceIndex, begin, (uint8_t*)buf, len);
}
@ -246,7 +246,7 @@ static bool recalculateHash(tr_torrent* tor, tr_piece_index_t pieceIndex, uint8_
size_t bytesLeft;
uint32_t offset = 0;
bool success = true;
const size_t buflen = tor->blockSize;
size_t const buflen = tor->blockSize;
void* buffer = tr_valloc(buflen);
tr_sha1_ctx_t sha;
@ -263,7 +263,7 @@ static bool recalculateHash(tr_torrent* tor, tr_piece_index_t pieceIndex, uint8_
while (bytesLeft)
{
const size_t len = MIN(bytesLeft, buflen);
size_t const len = MIN(bytesLeft, buflen);
success = !tr_cacheReadBlock(tor->session->cache, tor, pieceIndex, offset, len, buffer);
if (!success)

View File

@ -31,7 +31,7 @@ int tr_ioPrefetch(tr_torrent* tor, tr_piece_index_t pieceIndex, uint32_t begin,
* Writes the block specified by the piece index, offset, and length.
* @return 0 on success, or an errno value on failure.
*/
int tr_ioWrite(struct tr_torrent* tor, tr_piece_index_t pieceIndex, uint32_t offset, uint32_t len, const uint8_t* writeme);
int tr_ioWrite(struct tr_torrent* tor, tr_piece_index_t pieceIndex, uint32_t offset, uint32_t len, uint8_t const* writeme);
/**
* @brief Test to see if the piece matches its metainfo's SHA1 checksum.
@ -41,7 +41,7 @@ bool tr_ioTestPiece(tr_torrent* tor, tr_piece_index_t piece);
/**
* Converts a piece index + offset into a file index + offset.
*/
void tr_ioFindFileLocation(const tr_torrent* tor, tr_piece_index_t pieceIndex, uint32_t pieceOffset, tr_file_index_t* fileIndex,
void tr_ioFindFileLocation(tr_torrent const* tor, tr_piece_index_t pieceIndex, uint32_t pieceOffset, tr_file_index_t* fileIndex,
uint64_t* fileOffset);
/* @} */

View File

@ -19,9 +19,9 @@
static int test_elements(void)
{
const char* in;
char const* in;
tr_variant top;
const char* str;
char const* str;
bool f;
double d;
int64_t i;
@ -70,12 +70,12 @@ static int test_elements(void)
static int test_utf8(void)
{
const char* in = "{ \"key\": \"Letöltések\" }";
char const* in = "{ \"key\": \"Letöltések\" }";
tr_variant top;
const char* str;
char const* str;
char* json;
int err;
const tr_quark key = tr_quark_new("key", 3);
tr_quark const key = tr_quark_new("key", 3);
err = tr_variantFromJson(&top, in, strlen(in));
check(!err);
@ -142,7 +142,7 @@ static int test_utf8(void)
static int test1(void)
{
const char* in =
char const* in =
"{\n"
" \"headers\": {\n"
" \"type\": \"request\",\n"
@ -156,9 +156,9 @@ static int test1(void)
" }\n"
"}\n";
tr_variant top, * headers, * body, * args, * ids;
const char* str;
char const* str;
int64_t i;
const int err = tr_variantFromJson(&top, in, strlen(in));
int const err = tr_variantFromJson(&top, in, strlen(in));
check(!err);
check(tr_variantIsDict(&top));
@ -188,7 +188,7 @@ static int test1(void)
static int test2(void)
{
tr_variant top;
const char* in = " ";
char const* in = " ";
int err;
top.type = 0;
@ -202,16 +202,16 @@ static int test2(void)
static int test3(void)
{
const char* in =
char const* in =
"{ \"error\": 2,"
" \"errorString\": \"torrent not registered with this tracker 6UHsVW'*C\","
" \"eta\": 262792,"
" \"id\": 25,"
" \"leftUntilDone\": 2275655680 }";
tr_variant top;
const char* str;
char const* str;
const int err = tr_variantFromJson(&top, in, strlen(in));
int const err = tr_variantFromJson(&top, in, strlen(in));
check(!err);
check(tr_variantDictFindStr(&top, TR_KEY_errorString, &str, NULL));
check_streq("torrent not registered with this tracker 6UHsVW'*C", str);
@ -222,11 +222,11 @@ static int test3(void)
static int test_unescape(void)
{
const char* in = "{ \"string-1\": \"\\/usr\\/lib\" }";
char const* in = "{ \"string-1\": \"\\/usr\\/lib\" }";
tr_variant top;
const char* str;
char const* str;
const int err = tr_variantFromJson(&top, in, strlen(in));
int const err = tr_variantFromJson(&top, in, strlen(in));
check_int_eq(0, err);
check(tr_variantDictFindStr(&top, tr_quark_new("string-1", 8), &str, NULL));
check_streq("/usr/lib", str);
@ -241,14 +241,14 @@ int main(void)
int n;
int rv;
const char* comma_locales[] =
char const* comma_locales[] =
{
"da_DK.UTF-8",
"fr_FR.UTF-8",
"ru_RU.UTF-8"
};
const testFunc tests[] =
testFunc const tests[] =
{
test_elements,
test_utf8,

View File

@ -50,9 +50,9 @@ bool should_print(bool pass)
#endif
}
bool check_condition_impl(const char* file, int line, bool condition)
bool check_condition_impl(char const* file, int line, bool condition)
{
const bool pass = condition;
bool const pass = condition;
if (should_print(pass))
{
@ -62,9 +62,9 @@ bool check_condition_impl(const char* file, int line, bool condition)
return pass;
}
bool check_streq_impl(const char* file, int line, const char* expected, const char* actual)
bool check_streq_impl(char const* file, int line, char const* expected, char const* actual)
{
const bool pass = tr_strcmp0(expected, actual) == 0;
bool const pass = tr_strcmp0(expected, actual) == 0;
if (should_print(pass))
{
@ -82,9 +82,9 @@ bool check_streq_impl(const char* file, int line, const char* expected, const ch
return pass;
}
bool check_int_eq_impl(const char* file, int line, int64_t expected, int64_t actual)
bool check_int_eq_impl(char const* file, int line, int64_t expected, int64_t actual)
{
const bool pass = expected == actual;
bool const pass = expected == actual;
if (should_print(pass))
{
@ -101,9 +101,9 @@ bool check_int_eq_impl(const char* file, int line, int64_t expected, int64_t act
return pass;
}
bool check_uint_eq_impl(const char* file, int line, uint64_t expected, uint64_t actual)
bool check_uint_eq_impl(char const* file, int line, uint64_t expected, uint64_t actual)
{
const bool pass = expected == actual;
bool const pass = expected == actual;
if (should_print(pass))
{
@ -120,9 +120,9 @@ bool check_uint_eq_impl(const char* file, int line, uint64_t expected, uint64_t
return pass;
}
bool check_ptr_eq_impl(const char* file, int line, const void* expected, const void* actual)
bool check_ptr_eq_impl(char const* file, int line, void const* expected, void const* actual)
{
const bool pass = expected == actual;
bool const pass = expected == actual;
if (should_print(pass))
{
@ -139,7 +139,7 @@ bool check_ptr_eq_impl(const char* file, int line, const void* expected, const v
return pass;
}
int runTests(const testFunc* const tests, int numTests)
int runTests(testFunc const* const tests, int numTests)
{
int i;
int ret;
@ -187,7 +187,7 @@ char* libtest_sandbox_create(void)
return sandbox;
}
static void rm_rf(const char* killme)
static void rm_rf(char const* killme)
{
tr_sys_path_info info;
@ -197,7 +197,7 @@ static void rm_rf(const char* killme)
if (info.type == TR_SYS_PATH_IS_DIRECTORY && (odir = tr_sys_dir_open(killme, NULL)) != TR_BAD_SYS_DIR)
{
const char* name;
char const* name;
while ((name = tr_sys_dir_read_name(odir, NULL)) != NULL)
{
@ -221,7 +221,7 @@ static void rm_rf(const char* killme)
}
}
void libtest_sandbox_destroy(const char* sandbox)
void libtest_sandbox_destroy(char const* sandbox)
{
rm_rf(sandbox);
}
@ -251,7 +251,7 @@ void libtest_sandbox_destroy(const char* sandbox)
tr_session* libttest_session_init(tr_variant* settings)
{
size_t len;
const char* str;
char const* str;
char* sandbox;
char* path;
tr_quark q;
@ -361,7 +361,7 @@ tr_torrent* libttest_zero_torrent_init(tr_session* session)
int err;
size_t metainfo_len;
char* metainfo;
const char* metainfo_base64;
char const* metainfo_base64;
tr_torrent* tor;
tr_ctor* ctor;
@ -421,7 +421,7 @@ void libttest_zero_torrent_populate(tr_torrent* tor, bool complete)
tr_sys_file_t fd;
char* path;
char* dirname;
const tr_file* file = &tor->info.files[i];
tr_file const* file = &tor->info.files[i];
if (!complete && (i == 0))
{
@ -491,11 +491,11 @@ void libttest_blockingTorrentVerify(tr_torrent* tor)
}
}
static void build_parent_dir(const char* path)
static void build_parent_dir(char const* path)
{
char* dir;
tr_error* error = NULL;
const int tmperr = errno;
int const tmperr = errno;
dir = tr_sys_path_dirname(path, NULL);
tr_sys_dir_create(dir, TR_SYS_DIR_CREATE_PARENTS, 0700, &error);
@ -505,10 +505,10 @@ static void build_parent_dir(const char* path)
errno = tmperr;
}
void libtest_create_file_with_contents(const char* path, const void* payload, size_t n)
void libtest_create_file_with_contents(char const* path, void const* payload, size_t n)
{
tr_sys_file_t fd;
const int tmperr = errno;
int const tmperr = errno;
build_parent_dir(path);
@ -521,15 +521,15 @@ void libtest_create_file_with_contents(const char* path, const void* payload, si
errno = tmperr;
}
void libtest_create_file_with_string_contents(const char* path, const char* str)
void libtest_create_file_with_string_contents(char const* path, char const* str)
{
libtest_create_file_with_contents(path, str, strlen(str));
}
void libtest_create_tmpfile_with_contents(char* tmpl, const void* payload, size_t n)
void libtest_create_tmpfile_with_contents(char* tmpl, void const* payload, size_t n)
{
tr_sys_file_t fd;
const int tmperr = errno;
int const tmperr = errno;
uint64_t n_left = n;
tr_error* error = NULL;

View File

@ -22,11 +22,11 @@ extern bool verbose;
bool should_print(bool pass);
bool check_condition_impl(const char* file, int line, bool condition);
bool check_int_eq_impl(const char* file, int line, int64_t expected, int64_t actual);
bool check_uint_eq_impl(const char* file, int line, uint64_t expected, uint64_t actual);
bool check_ptr_eq_impl(const char* file, int line, const void* expected, const void* actual);
bool check_streq_impl(const char* file, int line, const char* expected, const char* actual);
bool check_condition_impl(char const* file, int line, bool condition);
bool check_int_eq_impl(char const* file, int line, int64_t expected, int64_t actual);
bool check_uint_eq_impl(char const* file, int line, uint64_t expected, uint64_t actual);
bool check_ptr_eq_impl(char const* file, int line, void const* expected, void const* actual);
bool check_streq_impl(char const* file, int line, char const* expected, char const* actual);
/***
****
@ -100,12 +100,12 @@ typedef int (* testFunc)(void);
#define NUM_TESTS(tarray) ((int)(sizeof(tarray) / sizeof(tarray[0])))
int runTests(const testFunc* const tests, int numTests);
int runTests(testFunc const* const tests, int numTests);
#define MAIN_SINGLE_TEST(test) \
int main(void) \
{ \
const testFunc tests[] = { test }; \
testFunc const tests[] = { test }; \
return runTests(tests, 1); \
}
@ -117,11 +117,11 @@ tr_torrent* libttest_zero_torrent_init(tr_session* session);
void libttest_blockingTorrentVerify(tr_torrent* tor);
void libtest_create_file_with_contents(const char* path, const void* contents, size_t n);
void libtest_create_tmpfile_with_contents(char* tmpl, const void* payload, size_t n);
void libtest_create_file_with_string_contents(const char* path, const char* str);
void libtest_create_file_with_contents(char const* path, void const* contents, size_t n);
void libtest_create_tmpfile_with_contents(char* tmpl, void const* payload, size_t n);
void libtest_create_file_with_string_contents(char const* path, char const* str);
char* libtest_sandbox_create(void);
void libtest_sandbox_destroy(const char* sandbox);
void libtest_sandbox_destroy(char const* sandbox);
void libttest_sync(void);

View File

@ -11,7 +11,7 @@
#include "platform.h"
#include "utils.h"
static const tr_list TR_LIST_CLEAR = { NULL, NULL, NULL };
static tr_list const TR_LIST_CLEAR = { NULL, NULL, NULL };
static tr_list* recycled_nodes = NULL;
@ -124,7 +124,7 @@ void tr_list_append(tr_list** list, void* data)
}
}
static tr_list* tr_list_find_data(tr_list* list, const void* data)
static tr_list* tr_list_find_data(tr_list* list, void const* data)
{
for (; list; list = list->next)
{
@ -176,17 +176,17 @@ void* tr_list_pop_front(tr_list** list)
return ret;
}
void* tr_list_remove_data(tr_list** list, const void* data)
void* tr_list_remove_data(tr_list** list, void const* data)
{
return tr_list_remove_node(list, tr_list_find_data(*list, data));
}
void* tr_list_remove(tr_list** list, const void* b, TrListCompareFunc compare_func)
void* tr_list_remove(tr_list** list, void const* b, TrListCompareFunc compare_func)
{
return tr_list_remove_node(list, tr_list_find(*list, b, compare_func));
}
tr_list* tr_list_find(tr_list* list, const void* b, TrListCompareFunc func)
tr_list* tr_list_find(tr_list* list, void const* b, TrListCompareFunc func)
{
for (; list; list = list->next)
{
@ -206,7 +206,7 @@ void tr_list_insert_sorted(tr_list** list, void* data, TrListCompareFunc compare
for (l = *list; l != NULL; l = l->next)
{
const int c = (compare)(data, l->data);
int const c = (compare)(data, l->data);
if (c <= 0)
{
@ -233,7 +233,7 @@ void tr_list_insert_sorted(tr_list** list, void* data, TrListCompareFunc compare
}
}
int tr_list_size(const tr_list* list)
int tr_list_size(tr_list const* list)
{
int size = 0;

View File

@ -28,14 +28,14 @@ typedef struct tr_list
}
tr_list;
typedef int (* TrListCompareFunc)(const void* a, const void* b);
typedef int (* TrListCompareFunc)(void const* a, void const* b);
typedef void (* TrListForeachFunc)(void*);
/**
* @brief return the number of items in the list
* @return the number of items in the list
*/
int tr_list_size(const tr_list* list);
int tr_list_size(tr_list const* list);
/**
* @brief free the specified list and set its pointer to NULL
@ -71,7 +71,7 @@ void* tr_list_pop_front(tr_list** list);
* @param data data to remove
* @return the removed data pointer, or NULL if no match was found
*/
void* tr_list_remove_data(tr_list** list, const void* data);
void* tr_list_remove_data(tr_list** list, void const* data);
/**
* @brief remove the list's node that compares equal to "b" when compared with "compare_func"
@ -80,7 +80,7 @@ void* tr_list_remove_data(tr_list** list, const void* data);
* @param compare_func the comparison function. The arguments passed to it will be the list's pointers and the comparison key "b"
* @return the removed data pointer, or NULL if no match was found
*/
void* tr_list_remove(tr_list** list, const void* b, TrListCompareFunc compare_func);
void* tr_list_remove(tr_list** list, void const* b, TrListCompareFunc compare_func);
/**
* @brief find the list node whose data that compares equal to "b" when compared with "compare_func"
@ -89,7 +89,7 @@ void* tr_list_remove(tr_list** list, const void* b, TrListCompareFunc compare_fu
* @param compare_func the comparison function. The arguments passed to it will be the list's pointers and the comparison key "b"
* @return the matching list node, or NULL if not match was found
*/
tr_list* tr_list_find(tr_list* list, const void* b, TrListCompareFunc compare_func);
tr_list* tr_list_find(tr_list* list, void const* b, TrListCompareFunc compare_func);
/**
* @brief Insert in an ordered list

View File

@ -33,7 +33,7 @@ static inline int IsDebuggerPresent(void)
return false;
}
static inline void OutputDebugStringA(const void* unused UNUSED)
static inline void OutputDebugStringA(void const* unused UNUSED)
{
}
@ -71,7 +71,7 @@ tr_sys_file_t tr_logGetFile(void)
if (!initialized)
{
const int fd = tr_env_get_int("TR_DEBUG_FD", 0);
int const fd = tr_env_get_int("TR_DEBUG_FD", 0);
switch (fd)
{
@ -170,9 +170,9 @@ bool tr_logGetDeepEnabled(void)
return deepLoggingIsActive != 0;
}
void tr_logAddDeep(const char* file, int line, const char* name, const char* fmt, ...)
void tr_logAddDeep(char const* file, int line, char const* name, char const* fmt, ...)
{
const tr_sys_file_t fp = tr_logGetFile();
tr_sys_file_t const fp = tr_logGetFile();
if (fp != TR_BAD_SYS_FILE || IsDebuggerPresent())
{
@ -212,9 +212,9 @@ void tr_logAddDeep(const char* file, int line, const char* name, const char* fmt
****
***/
void tr_logAddMessage(const char* file, int line, tr_log_level level, const char* name, const char* fmt, ...)
void tr_logAddMessage(char const* file, int line, tr_log_level level, char const* name, char const* fmt, ...)
{
const int err = errno; /* message logging shouldn't affect errno */
int const err = errno; /* message logging shouldn't affect errno */
char buf[1024];
int buf_len;
va_list ap;

View File

@ -27,7 +27,7 @@ static inline bool tr_logLevelIsActive(tr_log_level level)
return tr_logGetLevel() >= level;
}
void tr_logAddMessage(const char* file, int line, tr_log_level level, const char* torrent, const char* 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_logAddNamedError(n, ...) \
@ -125,7 +125,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(const char* file, int line, const char* name, const char* 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);
/** @brief set the buffer with the current time formatted for deep logging. */

View File

@ -15,9 +15,9 @@
static int test1(void)
{
int i;
const char* uri;
char const* uri;
tr_magnet_info* info;
const int dec[] =
int const dec[] =
{
210, 53, 64, 16, 163, 202, 74, 222, 91, 116,
39, 187, 9, 58, 98, 163, 137, 159, 243, 129

View File

@ -23,7 +23,7 @@
/* this base32 code converted from code by Robert Kaye and Gordon Mohr
* and is public domain. see http://bitzi.com/publicdomain for more info */
static const int base32Lookup[] =
static int const base32Lookup[] =
{
0xFF, 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, /* '0', '1', '2', '3', '4', '5', '6', '7' */
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* '8', '9', ':', ';', '<', '=', '>', '?' */
@ -37,11 +37,11 @@ static const int base32Lookup[] =
0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF /* 'x', 'y', 'z', '{', '|', '}', '~', 'DEL' */
};
static const int base32LookupLen = sizeof(base32Lookup) / sizeof(base32Lookup[0]);
static int const base32LookupLen = sizeof(base32Lookup) / sizeof(base32Lookup[0]);
static void base32_to_sha1(uint8_t* out, const char* in, const size_t inlen)
static void base32_to_sha1(uint8_t* out, char const* in, size_t const inlen)
{
const size_t outlen = 20;
size_t const outlen = 20;
size_t i, index, offset;
memset(out, 0, 20);
@ -109,7 +109,7 @@ static void base32_to_sha1(uint8_t* out, const char* in, const size_t inlen)
#define MAX_TRACKERS 64
#define MAX_WEBSEEDS 64
tr_magnet_info* tr_magnetParse(const char* uri)
tr_magnet_info* tr_magnetParse(char const* uri)
{
bool got_checksum = false;
int trCount = 0;
@ -122,14 +122,14 @@ tr_magnet_info* tr_magnetParse(const char* uri)
if (uri != NULL && strncmp(uri, "magnet:?", 8) == 0)
{
const char* walk;
char const* walk;
for (walk = uri + 8; walk && *walk;)
{
const char* key = walk;
const char* delim = strchr(key, '=');
const char* val = delim == NULL ? NULL : delim + 1;
const char* next = strchr(delim == NULL ? key : val, '&');
char const* key = walk;
char const* delim = strchr(key, '=');
char const* val = delim == NULL ? NULL : delim + 1;
char const* next = strchr(delim == NULL ? key : val, '&');
size_t keylen, vallen;
if (delim != NULL)
@ -160,8 +160,8 @@ tr_magnet_info* tr_magnetParse(const char* uri)
if (keylen == 2 && memcmp(key, "xt", 2) == 0 && val != NULL && strncmp(val, "urn:btih:", 9) == 0)
{
const char* hash = val + 9;
const size_t hashlen = vallen - 9;
char const* hash = val + 9;
size_t const hashlen = vallen - 9;
if (hashlen == 40)
{
@ -242,7 +242,7 @@ void tr_magnetFree(tr_magnet_info* info)
}
}
void tr_magnetCreateMetainfo(const tr_magnet_info* info, tr_variant* top)
void tr_magnetCreateMetainfo(tr_magnet_info const* info, tr_variant* top)
{
int i;
tr_variant* d;

View File

@ -29,10 +29,10 @@ typedef struct tr_magnet_info
}
tr_magnet_info;
tr_magnet_info* tr_magnetParse(const char* uri);
tr_magnet_info* tr_magnetParse(char const* uri);
struct tr_variant;
void tr_magnetCreateMetainfo(const tr_magnet_info*, tr_variant*);
void tr_magnetCreateMetainfo(tr_magnet_info const*, tr_variant*);
void tr_magnetFree(tr_magnet_info* info);

View File

@ -16,8 +16,8 @@
#include <stdlib.h> /* mktemp() */
#include <string.h> /* strlen() */
static int test_single_file_impl(const tr_tracker_info* trackers, const size_t trackerCount, const void* payload,
const size_t payloadSize, const char* comment, bool isPrivate)
static int test_single_file_impl(tr_tracker_info const* trackers, size_t const trackerCount, void const* payload,
size_t const payloadSize, char const* comment, bool isPrivate)
{
char* sandbox;
char* input_file;
@ -90,8 +90,8 @@ static int test_single_file(void)
tr_tracker_info trackers[16];
size_t trackerCount;
bool isPrivate;
const char* comment;
const char* payload;
char const* comment;
char const* payload;
size_t payloadSize;
trackerCount = 0;
@ -110,8 +110,8 @@ static int test_single_file(void)
return 0;
}
static int test_single_directory_impl(const tr_tracker_info* trackers, const size_t trackerCount, const void** payloads,
const size_t* payloadSizes, const size_t payloadCount, const char* comment, const bool isPrivate)
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)
{
char* sandbox;
char* torrent_file;
@ -211,8 +211,8 @@ static int test_single_directory_impl(const tr_tracker_info* trackers, const siz
return 0;
}
static int test_single_directory_random_payload_impl(const tr_tracker_info* trackers, const size_t trackerCount,
const size_t maxFileCount, const size_t maxFileSize, const char* comment, const bool isPrivate)
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 i;
void** payloads;
@ -226,14 +226,14 @@ static int test_single_directory_random_payload_impl(const tr_tracker_info* trac
for (i = 0; i < payloadCount; i++)
{
const size_t n = 1 + tr_rand_int_weak(maxFileSize);
size_t const n = 1 + tr_rand_int_weak(maxFileSize);
payloads[i] = tr_new(char, n);
tr_rand_buffer(payloads[i], n);
payloadSizes[i] = n;
}
/* run the test */
test_single_directory_impl(trackers, trackerCount, (const void**)payloads, payloadSizes, payloadCount, comment, isPrivate);
test_single_directory_impl(trackers, trackerCount, (void const**)payloads, payloadSizes, payloadCount, comment, isPrivate);
/* cleanup */
for (i = 0; i < payloadCount; i++)
@ -255,7 +255,7 @@ static int test_single_directory_random_payload(void)
tr_tracker_info trackers[16];
size_t trackerCount;
bool isPrivate;
const char* comment;
char const* comment;
size_t i;
trackerCount = 0;
@ -279,7 +279,7 @@ static int test_single_directory_random_payload(void)
int main(void)
{
const testFunc tests[] =
testFunc const tests[] =
{
test_single_file,
test_single_directory_random_payload

View File

@ -36,7 +36,7 @@ struct FileList
struct FileList* next;
};
static struct FileList* getFiles(const char* dir, const char* base, struct FileList* list)
static struct FileList* getFiles(char const* dir, char const* base, struct FileList* list)
{
if (dir == NULL || base == NULL)
{
@ -60,7 +60,7 @@ static struct FileList* getFiles(const char* dir, const char* base, struct FileL
if (info.type == TR_SYS_PATH_IS_DIRECTORY && (odir = tr_sys_dir_open(buf, NULL)) != TR_BAD_SYS_DIR)
{
const char* name;
char const* name;
while ((name = tr_sys_dir_read_name(odir, NULL)) != NULL)
{
@ -87,9 +87,9 @@ static struct FileList* getFiles(const char* dir, const char* base, struct FileL
static uint32_t bestPieceSize(uint64_t totalSize)
{
const uint32_t KiB = 1024;
const uint32_t MiB = 1048576;
const uint32_t GiB = 1073741824;
uint32_t const KiB = 1024;
uint32_t const MiB = 1048576;
uint32_t const GiB = 1073741824;
if (totalSize >= (2 * GiB))
{
@ -124,15 +124,15 @@ static uint32_t bestPieceSize(uint64_t totalSize)
return 32 * KiB; /* less than 50 meg */
}
static int builderFileCompare(const void* va, const void* vb)
static int builderFileCompare(void const* va, void const* vb)
{
const tr_metainfo_builder_file* a = va;
const tr_metainfo_builder_file* b = vb;
tr_metainfo_builder_file const* a = va;
tr_metainfo_builder_file const* b = vb;
return evutil_ascii_strcasecmp(a->filename, b->filename);
}
tr_metainfo_builder* tr_metaInfoBuilderCreate(const char* topFileArg)
tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFileArg)
{
int i;
struct FileList* files;
@ -183,7 +183,7 @@ tr_metainfo_builder* tr_metaInfoBuilderCreate(const char* topFileArg)
static bool isValidPieceSize(uint32_t n)
{
const bool isPowerOfTwo = !(n == 0) && !(n & (n - 1));
bool const isPowerOfTwo = !(n == 0) && !(n & (n - 1));
return isPowerOfTwo;
}
@ -277,14 +277,14 @@ static uint8_t* getHashInfo(tr_metainfo_builder* b)
while (totalRemain)
{
uint8_t* bufptr = buf;
const uint32_t thisPieceSize = (uint32_t)MIN(b->pieceSize, totalRemain);
uint32_t const thisPieceSize = (uint32_t)MIN(b->pieceSize, totalRemain);
uint64_t leftInPiece = thisPieceSize;
assert(b->pieceIndex < b->pieceCount);
while (leftInPiece)
{
const uint64_t n_this_pass = MIN(b->files[fileIndex].size - off, leftInPiece);
uint64_t const n_this_pass = MIN(b->files[fileIndex].size - off, leftInPiece);
uint64_t n_read = 0;
tr_sys_file_read(fd, bufptr, n_this_pass, &n_read, NULL);
bufptr += n_read;
@ -342,7 +342,7 @@ static uint8_t* getHashInfo(tr_metainfo_builder* b)
return ret;
}
static void getFileInfo(const char* topFile, const tr_metainfo_builder_file* file, tr_variant* uninitialized_length,
static void getFileInfo(char const* topFile, tr_metainfo_builder_file const* file, tr_variant* uninitialized_length,
tr_variant* uninitialized_path)
{
size_t offset;
@ -365,7 +365,7 @@ static void getFileInfo(const char* topFile, const tr_metainfo_builder_file* fil
{
char* filename = tr_strdup(file->filename + offset);
char* walk = filename;
const char* token;
char const* token;
while ((token = tr_strsep(&walk, TR_PATH_DELIMITER_STR)))
{
@ -559,8 +559,8 @@ static void makeMetaWorkerFunc(void* unused UNUSED)
workerThread = NULL;
}
void tr_makeMetaInfo(tr_metainfo_builder* builder, const char* outputFile, const tr_tracker_info* trackers, int trackerCount,
const char* comment, bool isPrivate)
void tr_makeMetaInfo(tr_metainfo_builder* builder, char const* outputFile, tr_tracker_info const* trackers, int trackerCount,
char const* comment, bool isPrivate)
{
int i;
tr_lock* lock;

View File

@ -85,7 +85,7 @@ typedef struct tr_metainfo_builder
}
tr_metainfo_builder;
tr_metainfo_builder* tr_metaInfoBuilderCreate(const char* topFile);
tr_metainfo_builder* tr_metaInfoBuilderCreate(char const* topFile);
/**
* Call this before tr_makeMetaInfo() to override the builder.pieceSize
@ -114,8 +114,8 @@ void tr_metaInfoBuilderFree(tr_metainfo_builder*);
*
* @param trackerCount size of the `trackers' array
*/
void tr_makeMetaInfo(tr_metainfo_builder* builder, const char* outputFile, const tr_tracker_info* trackers, int trackerCount,
const char* comment, bool isPrivate);
void tr_makeMetaInfo(tr_metainfo_builder* builder, char const* outputFile, tr_tracker_info const* trackers, int trackerCount,
char const* comment, bool isPrivate);
#ifdef __cplusplus
}

View File

@ -16,7 +16,7 @@ static int test_magnet_link(void)
{
tr_info inf;
tr_ctor* ctor;
const char* magnet_link;
char const* magnet_link;
tr_parse_result parse_result;
/* background info @ http://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding */
@ -52,13 +52,13 @@ static int test_magnet_link(void)
static int test_metainfo(void)
{
size_t i;
const struct
struct
{
int expected_benc_err;
int expected_parse_result;
const void* benc;
}
metainfo[] =
const metainfo[] =
{
{ 0, TR_PARSE_OK, BEFORE_PATH "5:a.txt" AFTER_PATH },
@ -86,12 +86,12 @@ static int test_metainfo(void)
for (i = 0; i < (sizeof(metainfo) / sizeof(metainfo[0])); i++)
{
tr_ctor* ctor = tr_ctorNew(NULL);
const int err = tr_ctorSetMetainfo(ctor, metainfo[i].benc, strlen(metainfo[i].benc));
int const err = tr_ctorSetMetainfo(ctor, metainfo[i].benc, strlen(metainfo[i].benc));
check_int_eq(metainfo[i].expected_benc_err, err);
if (!err)
{
const tr_parse_result parse_result = tr_torrentParse(ctor, NULL);
tr_parse_result const parse_result = tr_torrentParse(ctor, NULL);
check_int_eq(metainfo[i].expected_parse_result, parse_result);
}
@ -103,7 +103,7 @@ static int test_metainfo(void)
int main(void)
{
const testFunc tests[] =
testFunc const tests[] =
{
test_magnet_link,
test_metainfo

View File

@ -36,11 +36,11 @@ static inline bool char_is_path_separator(char c)
return strchr(PATH_DELIMITER_CHARS, c) != NULL;
}
char* tr_metainfoGetBasename(const tr_info* inf)
char* tr_metainfoGetBasename(tr_info const* inf)
{
size_t i;
const char* name = inf->originalName;
const size_t name_len = strlen(name);
char const* name = inf->originalName;
size_t const name_len = strlen(name);
char* ret = tr_strdup_printf("%s.%16.16s", name, inf->hashString);
for (i = 0; i < name_len; ++i)
@ -54,7 +54,7 @@ char* tr_metainfoGetBasename(const tr_info* inf)
return ret;
}
static char* getTorrentFilename(const tr_session* session, const tr_info* inf)
static char* getTorrentFilename(tr_session const* session, tr_info const* inf)
{
char* base = tr_metainfoGetBasename(inf);
char* filename = tr_strdup_printf("%s" TR_PATH_DELIMITER_STR "%s.torrent", tr_getTorrentDir(session), base);
@ -66,13 +66,13 @@ static char* getTorrentFilename(const tr_session* session, const tr_info* inf)
****
***/
static bool path_component_is_suspicious(const char* component)
static bool path_component_is_suspicious(char const* component)
{
return (component == NULL) || (strpbrk(component, PATH_DELIMITER_CHARS) != NULL) || (strcmp(component, ".") == 0) ||
(strcmp(component, "..") == 0);
}
static bool getfile(char** setme, const char* root, tr_variant* path, struct evbuffer* buf)
static bool getfile(char** setme, char const* root, tr_variant* path, struct evbuffer* buf)
{
bool success = false;
size_t root_len = 0;
@ -85,7 +85,7 @@ static bool getfile(char** setme, const char* root, tr_variant* path, struct evb
if (tr_variantIsList(path))
{
int i;
const int n = tr_variantListSize(path);
int const n = tr_variantListSize(path);
success = true;
evbuffer_drain(buf, evbuffer_get_length(buf));
@ -95,7 +95,7 @@ static bool getfile(char** setme, const char* root, tr_variant* path, struct evb
for (i = 0; i < n; i++)
{
size_t len;
const char* str;
char const* str;
if (!tr_variantGetStr(tr_variantListChild(path, i), &str, &len) || path_component_is_suspicious(str))
{
@ -127,7 +127,7 @@ static bool getfile(char** setme, const char* root, tr_variant* path, struct evb
return success;
}
static const char* parseFiles(tr_info* inf, tr_variant* files, const tr_variant* length)
static char const* parseFiles(tr_info* inf, tr_variant* files, tr_variant const* length)
{
int64_t len;
@ -137,7 +137,7 @@ static const char* parseFiles(tr_info* inf, tr_variant* files, const tr_variant*
{
tr_file_index_t i;
struct evbuffer* buf;
const char* result;
char const* result;
if (path_component_is_suspicious(inf->name))
{
@ -214,10 +214,10 @@ static const char* parseFiles(tr_info* inf, tr_variant* files, const tr_variant*
return NULL;
}
static char* tr_convertAnnounceToScrape(const char* announce)
static char* tr_convertAnnounceToScrape(char const* announce)
{
char* scrape = NULL;
const char* s;
char const* s;
/* To derive the scrape URL use the following steps:
* Begin with the announce URL. Find the last '/' in it.
@ -227,11 +227,11 @@ static char* tr_convertAnnounceToScrape(const char* announce)
* 'announce' to find the scrape page. */
if (((s = strrchr(announce, '/')) != NULL) && strncmp(++s, "announce", 8) == 0)
{
const char* prefix = announce;
const size_t prefix_len = s - announce;
const char* suffix = s + 8;
const size_t suffix_len = strlen(suffix);
const size_t alloc_len = prefix_len + 6 + suffix_len + 1;
char const* prefix = announce;
size_t const prefix_len = s - announce;
char const* suffix = s + 8;
size_t const suffix_len = strlen(suffix);
size_t const alloc_len = prefix_len + 6 + suffix_len + 1;
char* walk = scrape = tr_new(char, alloc_len);
memcpy(walk, prefix, prefix_len);
walk += prefix_len;
@ -251,10 +251,10 @@ static char* tr_convertAnnounceToScrape(const char* announce)
return scrape;
}
static const char* getannounce(tr_info* inf, tr_variant* meta)
static char const* getannounce(tr_info* inf, tr_variant* meta)
{
size_t len;
const char* str;
char const* str;
tr_tracker_info* trackers = NULL;
int trackerCount = 0;
tr_variant* tiers;
@ -264,7 +264,7 @@ static const char* getannounce(tr_info* inf, tr_variant* meta)
{
int n;
int i, j, validTiers;
const int numTiers = tr_variantListSize(tiers);
int const numTiers = tr_variantListSize(tiers);
n = 0;
@ -278,7 +278,7 @@ static const char* getannounce(tr_info* inf, tr_variant* meta)
for (i = 0, validTiers = 0; i < numTiers; i++)
{
tr_variant* tier = tr_variantListChild(tiers, i);
const int tierSize = tr_variantListSize(tier);
int const tierSize = tr_variantListSize(tier);
bool anyAdded = false;
for (j = 0; j < tierSize; j++)
@ -357,7 +357,7 @@ static const char* getannounce(tr_info* inf, tr_variant* meta)
* mktorrent and very old versions of utorrent, that don't add the
* trailing slash for multifile torrents if omitted by the end user.
*/
static char* fix_webseed_url(const tr_info* inf, const char* url_in)
static char* fix_webseed_url(tr_info const* inf, char const* url_in)
{
size_t len;
char* url;
@ -386,12 +386,12 @@ static char* fix_webseed_url(const tr_info* inf, const char* url_in)
static void geturllist(tr_info* inf, tr_variant* meta)
{
tr_variant* urls;
const char* url;
char const* url;
if (tr_variantDictFindList(meta, TR_KEY_url_list, &urls))
{
int i;
const int n = tr_variantListSize(urls);
int const n = tr_variantListSize(urls);
inf->webseedCount = 0;
inf->webseeds = tr_new0(char*, n);
@ -422,13 +422,13 @@ static void geturllist(tr_info* inf, tr_variant* meta)
}
}
static const char* tr_metainfoParseImpl(const tr_session* session, tr_info* inf, bool* hasInfoDict, size_t* infoDictLength,
const tr_variant* meta_in)
static char const* tr_metainfoParseImpl(tr_session const* session, tr_info* inf, bool* hasInfoDict, size_t* infoDictLength,
tr_variant const* meta_in)
{
int64_t i;
size_t len;
const char* str;
const uint8_t* raw;
char const* str;
uint8_t const* raw;
tr_variant* d;
tr_variant* infoDict = NULL;
tr_variant* meta = (tr_variant*)meta_in;
@ -644,11 +644,11 @@ static const char* tr_metainfoParseImpl(const tr_session* session, tr_info* inf,
return NULL;
}
bool tr_metainfoParse(const tr_session* session, const tr_variant* meta_in, tr_info* inf, bool* hasInfoDict,
bool tr_metainfoParse(tr_session const* session, tr_variant const* meta_in, tr_info* inf, bool* hasInfoDict,
size_t* infoDictLength)
{
const char* badTag = tr_metainfoParseImpl(session, inf, hasInfoDict, infoDictLength, meta_in);
const bool success = badTag == NULL;
char const* badTag = tr_metainfoParseImpl(session, inf, hasInfoDict, infoDictLength, meta_in);
bool const success = badTag == NULL;
if (badTag)
{
@ -694,7 +694,7 @@ void tr_metainfoFree(tr_info* inf)
memset(inf, '\0', sizeof(tr_info));
}
void tr_metainfoRemoveSaved(const tr_session* session, const tr_info* inf)
void tr_metainfoRemoveSaved(tr_session const* session, tr_info const* inf)
{
char* filename;

View File

@ -15,9 +15,9 @@
#include "transmission.h"
#include "variant.h"
bool tr_metainfoParse(const tr_session* session, const tr_variant* variant, tr_info* setmeInfo, bool* setmeHasInfoDict,
bool tr_metainfoParse(tr_session const* session, tr_variant const* variant, tr_info* setmeInfo, bool* setmeHasInfoDict,
size_t* setmeInfoDictLength);
void tr_metainfoRemoveSaved(const tr_session* session, const tr_info* info);
void tr_metainfoRemoveSaved(tr_session const* session, tr_info const* info);
char* tr_metainfoGetBasename(const tr_info*);
char* tr_metainfoGetBasename(tr_info const*);

View File

@ -62,14 +62,14 @@ static void test_incomplete_dir_threadfunc(void* vdata)
data->done = true;
}
static int test_incomplete_dir_impl(const char* incomplete_dir, const char* download_dir)
static int test_incomplete_dir_impl(char const* incomplete_dir, char const* download_dir)
{
tr_file_index_t file_index;
tr_session* session;
tr_torrent* tor;
tr_completeness completeness;
const tr_completeness completeness_unset = -1;
const time_t deadline = time(NULL) + 300;
tr_completeness const completeness_unset = -1;
time_t const deadline = time(NULL) + 300;
tr_variant settings;
/* init the session */
@ -184,7 +184,7 @@ static int test_set_location(void)
char* target_dir;
tr_torrent* tor;
tr_session* session;
const time_t deadline = time(NULL) + 300;
time_t const deadline = time(NULL) + 300;
/* init the session */
session = libttest_session_init(NULL);
@ -233,7 +233,7 @@ static int test_set_location(void)
int main(void)
{
const testFunc tests[] =
testFunc const tests[] =
{
test_incomplete_dir,
test_set_location

View File

@ -25,7 +25,7 @@
#define LIFETIME_SECS 3600
#define COMMAND_WAIT_SECS 8
static const char* getKey(void)
static char const* getKey(void)
{
return _("Port Forwarding (NAT-PMP)");
}
@ -61,7 +61,7 @@ struct tr_natpmp
***
**/
static void logVal(const char* func, int ret)
static void logVal(char const* func, int ret)
{
if (ret == NATPMP_TRYAGAIN)
{
@ -100,7 +100,7 @@ void tr_natpmpClose(tr_natpmp* nat)
}
}
static bool canSendCommand(const struct tr_natpmp* nat)
static bool canSendCommand(struct tr_natpmp const* nat)
{
return tr_time() >= nat->command_time;
}
@ -128,7 +128,7 @@ int tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, bool is_enabled,
if ((nat->state == TR_NATPMP_RECV_PUB) && canSendCommand(nat))
{
natpmpresp_t response;
const int val = readnatpmpresponseorretry(&nat->natpmp, &response);
int const val = readnatpmpresponseorretry(&nat->natpmp, &response);
logVal("readnatpmpresponseorretry", val);
if (val >= 0)
@ -154,7 +154,7 @@ int tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, bool is_enabled,
if ((nat->state == TR_NATPMP_SEND_UNMAP) && canSendCommand(nat))
{
const int val = sendnewportmappingrequest(&nat->natpmp, NATPMP_PROTOCOL_TCP, nat->private_port, nat->public_port, 0);
int const val = sendnewportmappingrequest(&nat->natpmp, NATPMP_PROTOCOL_TCP, nat->private_port, nat->public_port, 0);
logVal("sendnewportmappingrequest", val);
nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_UNMAP;
setCommandTime(nat);
@ -163,12 +163,12 @@ int tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, bool is_enabled,
if (nat->state == TR_NATPMP_RECV_UNMAP)
{
natpmpresp_t resp;
const int val = readnatpmpresponseorretry(&nat->natpmp, &resp);
int const val = readnatpmpresponseorretry(&nat->natpmp, &resp);
logVal("readnatpmpresponseorretry", val);
if (val >= 0)
{
const int private_port = resp.pnu.newportmapping.privateport;
int const private_port = resp.pnu.newportmapping.privateport;
tr_logAddNamedInfo(getKey(), _("no longer forwarding port %d"), private_port);
@ -200,7 +200,7 @@ int tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, bool is_enabled,
if ((nat->state == TR_NATPMP_SEND_MAP) && canSendCommand(nat))
{
const int val = sendnewportmappingrequest(&nat->natpmp, NATPMP_PROTOCOL_TCP, private_port, private_port, LIFETIME_SECS);
int const val = sendnewportmappingrequest(&nat->natpmp, NATPMP_PROTOCOL_TCP, private_port, private_port, LIFETIME_SECS);
logVal("sendnewportmappingrequest", val);
nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_MAP;
setCommandTime(nat);
@ -209,7 +209,7 @@ int tr_natpmpPulse(struct tr_natpmp* nat, tr_port private_port, bool is_enabled,
if (nat->state == TR_NATPMP_RECV_MAP)
{
natpmpresp_t resp;
const int val = readnatpmpresponseorretry(&nat->natpmp, &resp);
int const val = readnatpmpresponseorretry(&nat->natpmp, &resp);
logVal("readnatpmpresponseorretry", val);
if (val >= 0)

View File

@ -49,8 +49,8 @@
#define IN_MULTICAST(a) (((a) & 0xf0000000) == 0xe0000000)
#endif
const tr_address tr_in6addr_any = { TR_AF_INET6, { IN6ADDR_ANY_INIT } };
const tr_address tr_inaddr_any = { TR_AF_INET, { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } };
tr_address const tr_in6addr_any = { TR_AF_INET6, { IN6ADDR_ANY_INIT } };
tr_address const tr_inaddr_any = { TR_AF_INET, { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } };
char* tr_net_strerror(char* buf, size_t buflen, int err)
{
@ -74,7 +74,7 @@ char* tr_net_strerror(char* buf, size_t buflen, int err)
return buf;
}
const char* tr_address_to_string_with_buf(const tr_address* addr, char* buf, size_t buflen)
char const* tr_address_to_string_with_buf(tr_address const* addr, char* buf, size_t buflen)
{
assert(tr_address_is_valid(addr));
@ -94,13 +94,13 @@ const char* tr_address_to_string_with_buf(const tr_address* addr, char* buf, siz
* This function is suitable to be called from libTransmission's networking code,
* which is single-threaded.
*/
const char* tr_address_to_string(const tr_address* addr)
char const* tr_address_to_string(tr_address const* addr)
{
static char buf[INET6_ADDRSTRLEN];
return tr_address_to_string_with_buf(addr, buf, sizeof(buf));
}
bool tr_address_from_string(tr_address* dst, const char* src)
bool tr_address_from_string(tr_address* dst, char const* src)
{
bool ok;
@ -127,9 +127,9 @@ bool tr_address_from_string(tr_address* dst, const char* src)
* >0 if a > b
* 0 if a == b
*/
int tr_address_compare(const tr_address* a, const tr_address* b)
int tr_address_compare(tr_address const* a, tr_address const* b)
{
static const int sizes[2] = { sizeof(struct in_addr), sizeof(struct in6_addr) };
static int const sizes[2] = { sizeof(struct in_addr), sizeof(struct in6_addr) };
/* IPv6 addresses are always "greater than" IPv4 */
if (a->type != b->type)
@ -148,7 +148,7 @@ void tr_netSetTOS(tr_socket_t s, int tos)
{
#if defined(IP_TOS) && !defined(_WIN32)
if (setsockopt(s, IPPROTO_IP, IP_TOS, (const void*)&tos, sizeof(tos)) == -1)
if (setsockopt(s, IPPROTO_IP, IP_TOS, (void const*)&tos, sizeof(tos)) == -1)
{
char err_buf[512];
tr_logAddNamedInfo("Net", "Can't set TOS '%d': %s", tos, tr_net_strerror(err_buf, sizeof(err_buf), sockerrno));
@ -162,11 +162,11 @@ void tr_netSetTOS(tr_socket_t s, int tos)
#endif
}
void tr_netSetCongestionControl(tr_socket_t s, const char* algorithm)
void tr_netSetCongestionControl(tr_socket_t s, char const* algorithm)
{
#ifdef TCP_CONGESTION
if (setsockopt(s, IPPROTO_TCP, TCP_CONGESTION, (const void*)algorithm, strlen(algorithm) + 1) == -1)
if (setsockopt(s, IPPROTO_TCP, TCP_CONGESTION, (void const*)algorithm, strlen(algorithm) + 1) == -1)
{
char err_buf[512];
tr_logAddNamedInfo("Net", "Can't set congestion control algorithm '%s': %s", algorithm, tr_net_strerror(err_buf,
@ -181,7 +181,7 @@ void tr_netSetCongestionControl(tr_socket_t s, const char* algorithm)
#endif
}
bool tr_address_from_sockaddr_storage(tr_address* setme_addr, tr_port* setme_port, const struct sockaddr_storage* from)
bool tr_address_from_sockaddr_storage(tr_address* setme_addr, tr_port* setme_port, struct sockaddr_storage const* from)
{
if (from->ss_family == AF_INET)
{
@ -204,7 +204,7 @@ bool tr_address_from_sockaddr_storage(tr_address* setme_addr, tr_port* setme_por
return false;
}
static socklen_t setup_sockaddr(const tr_address* addr, tr_port port, struct sockaddr_storage* sockaddr)
static socklen_t setup_sockaddr(tr_address const* addr, tr_port port, struct sockaddr_storage* sockaddr)
{
assert(tr_address_is_valid(addr));
@ -231,13 +231,13 @@ static socklen_t setup_sockaddr(const tr_address* addr, tr_port port, struct soc
}
}
tr_socket_t tr_netOpenPeerSocket(tr_session* session, const tr_address* addr, tr_port port, bool clientIsSeed)
tr_socket_t tr_netOpenPeerSocket(tr_session* session, tr_address const* addr, tr_port port, bool clientIsSeed)
{
static const int domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 };
static int const domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 };
tr_socket_t s;
struct sockaddr_storage sock;
socklen_t addrlen;
const tr_address* source_addr;
tr_address const* source_addr;
socklen_t sourcelen;
struct sockaddr_storage source_sock;
char err_buf[512];
@ -261,7 +261,7 @@ tr_socket_t tr_netOpenPeerSocket(tr_session* session, const tr_address* addr, tr
{
int n = 8192;
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, (const void*)&n, sizeof(n)))
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, (void const*)&n, sizeof(n)))
{
tr_logAddInfo("Unable to set SO_RCVBUF on socket %" PRIdMAX ": %s", (intmax_t)s,
tr_net_strerror(err_buf, sizeof(err_buf), sockerrno));
@ -314,23 +314,23 @@ tr_socket_t tr_netOpenPeerSocket(tr_session* session, const tr_address* addr, tr
return s;
}
struct UTPSocket* tr_netOpenPeerUTPSocket(tr_session* session, const tr_address* addr, tr_port port, bool clientIsSeed UNUSED)
struct UTPSocket* tr_netOpenPeerUTPSocket(tr_session* session, tr_address const* addr, tr_port port, bool clientIsSeed UNUSED)
{
struct UTPSocket* ret = NULL;
if (tr_address_is_valid_for_peers(addr, port))
{
struct sockaddr_storage ss;
const socklen_t sslen = setup_sockaddr(addr, port, &ss);
socklen_t const sslen = setup_sockaddr(addr, port, &ss);
ret = UTP_Create(tr_utpSendTo, session, (struct sockaddr*)&ss, sslen);
}
return ret;
}
static tr_socket_t tr_netBindTCPImpl(const tr_address* addr, tr_port port, bool suppressMsgs, int* errOut)
static tr_socket_t tr_netBindTCPImpl(tr_address const* addr, tr_port port, bool suppressMsgs, int* errOut)
{
static const int domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 };
static int const domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 };
struct sockaddr_storage sock;
tr_socket_t fd;
int addrlen;
@ -354,14 +354,14 @@ static tr_socket_t tr_netBindTCPImpl(const tr_address* addr, tr_port port, bool
}
optval = 1;
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const void*)&optval, sizeof(optval));
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void*)&optval, sizeof(optval));
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void const*)&optval, sizeof(optval));
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void const*)&optval, sizeof(optval));
#ifdef IPV6_V6ONLY
if (addr->type == TR_AF_INET6)
{
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (const void*)&optval, sizeof(optval)) == -1)
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void const*)&optval, sizeof(optval)) == -1)
{
if (sockerrno != ENOPROTOOPT) /* if the kernel doesn't support it, ignore it */
{
@ -378,12 +378,12 @@ static tr_socket_t tr_netBindTCPImpl(const tr_address* addr, tr_port port, bool
if (bind(fd, (struct sockaddr*)&sock, addrlen))
{
const int err = sockerrno;
int const err = sockerrno;
if (!suppressMsgs)
{
const char* fmt;
const char* hint;
char const* fmt;
char const* hint;
char err_buf[512];
if (err == EADDRINUSE)
@ -424,7 +424,7 @@ static tr_socket_t tr_netBindTCPImpl(const tr_address* addr, tr_port port, bool
#endif
optval = 5;
setsockopt(fd, SOL_TCP, TCP_FASTOPEN, (const void*)&optval, sizeof(optval));
setsockopt(fd, SOL_TCP, TCP_FASTOPEN, (void const*)&optval, sizeof(optval));
#endif
@ -438,7 +438,7 @@ static tr_socket_t tr_netBindTCPImpl(const tr_address* addr, tr_port port, bool
return fd;
}
tr_socket_t tr_netBindTCP(const tr_address* addr, tr_port port, bool suppressMsgs)
tr_socket_t tr_netBindTCP(tr_address const* addr, tr_port port, bool suppressMsgs)
{
int unused;
return tr_netBindTCPImpl(addr, port, suppressMsgs, &unused);
@ -503,7 +503,7 @@ void tr_netClose(tr_session* session, tr_socket_t s)
there is no official interface to get this information, we create
a connected UDP socket (connected UDP... hmm...) and check its source
address. */
static int get_source_address(const struct sockaddr* dst, socklen_t dst_len, struct sockaddr* src, socklen_t* src_len)
static int get_source_address(struct sockaddr const* dst, socklen_t dst_len, struct sockaddr* src, socklen_t* src_len)
{
tr_socket_t s;
int rc, save;
@ -546,7 +546,7 @@ static int global_unicast_address(struct sockaddr* sa)
{
if (sa->sa_family == AF_INET)
{
const unsigned char* a = (unsigned char*)&((struct sockaddr_in*)sa)->sin_addr;
unsigned char const* a = (unsigned char*)&((struct sockaddr_in*)sa)->sin_addr;
if (a[0] == 0 || a[0] == 127 || a[0] >= 224 || a[0] == 10 || (a[0] == 172 && a[1] >= 16 && a[1] <= 31) ||
(a[0] == 192 && a[1] == 168))
@ -558,7 +558,7 @@ static int global_unicast_address(struct sockaddr* sa)
}
else if (sa->sa_family == AF_INET6)
{
const unsigned char* a = (unsigned char*)&((struct sockaddr_in6*)sa)->sin6_addr;
unsigned char const* a = (unsigned char*)&((struct sockaddr_in6*)sa)->sin6_addr;
/* 2000::/3 */
return (a[0] & 0xE0) == 0x20;
}
@ -645,18 +645,18 @@ static int tr_globalAddress(int af, void* addr, int* addr_len)
}
/* Return our global IPv6 address, with caching. */
const unsigned char* tr_globalIPv6(void)
unsigned char const* tr_globalIPv6(void)
{
static unsigned char ipv6[16];
static time_t last_time = 0;
static bool have_ipv6 = false;
const time_t now = tr_time();
time_t const now = tr_time();
/* Re-check every half hour */
if (last_time < now - 1800)
{
int addrlen = 16;
const int rc = tr_globalAddress(AF_INET6, ipv6, &addrlen);
int const rc = tr_globalAddress(AF_INET6, ipv6, &addrlen);
have_ipv6 = (rc >= 0) && (addrlen == 16);
last_time = now;
}
@ -669,21 +669,21 @@ const unsigned char* tr_globalIPv6(void)
****
***/
static bool isIPv4MappedAddress(const tr_address* addr)
static bool isIPv4MappedAddress(tr_address const* addr)
{
return (addr->type == TR_AF_INET6) && IN6_IS_ADDR_V4MAPPED(&addr->addr.addr6);
}
static bool isIPv6LinkLocalAddress(const tr_address* addr)
static bool isIPv6LinkLocalAddress(tr_address const* addr)
{
return (addr->type == TR_AF_INET6) && IN6_IS_ADDR_LINKLOCAL(&addr->addr.addr6);
}
/* isMartianAddr was written by Juliusz Chroboczek,
and is covered under the same license as third-party/dht/dht.c. */
static bool isMartianAddr(const struct tr_address* a)
static bool isMartianAddr(struct tr_address const* a)
{
static const unsigned char zeroes[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static unsigned char const zeroes[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
assert(tr_address_is_valid(a));
@ -691,13 +691,13 @@ static bool isMartianAddr(const struct tr_address* a)
{
case TR_AF_INET:
{
const unsigned char* address = (const unsigned char*)&a->addr.addr4;
unsigned char const* address = (unsigned char const*)&a->addr.addr4;
return (address[0] == 0) || (address[0] == 127) || ((address[0] & 0xE0) == 0xE0);
}
case TR_AF_INET6:
{
const unsigned char* address = (const unsigned char*)&a->addr.addr6;
unsigned char const* address = (unsigned char const*)&a->addr.addr6;
return (address[0] == 0xFF) || (memcmp(address, zeroes, 15) == 0 && (address[15] == 0 || address[15] == 1));
}
@ -706,7 +706,7 @@ static bool isMartianAddr(const struct tr_address* a)
}
}
bool tr_address_is_valid_for_peers(const tr_address* addr, tr_port port)
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));

View File

@ -94,22 +94,22 @@ typedef struct tr_address
} addr;
} tr_address;
extern const tr_address tr_inaddr_any;
extern const tr_address tr_in6addr_any;
extern tr_address const tr_inaddr_any;
extern tr_address const tr_in6addr_any;
const char* tr_address_to_string(const tr_address* addr);
char const* tr_address_to_string(tr_address const* addr);
const char* tr_address_to_string_with_buf(const tr_address* addr, char* buf, size_t buflen);
char const* tr_address_to_string_with_buf(tr_address const* addr, char* buf, size_t buflen);
bool tr_address_from_string(tr_address* setme, const char* string);
bool tr_address_from_string(tr_address* setme, char const* string);
bool tr_address_from_sockaddr_storage(tr_address* setme, tr_port* port, const struct sockaddr_storage* src);
bool tr_address_from_sockaddr_storage(tr_address* setme, tr_port* port, struct sockaddr_storage const* src);
int tr_address_compare(const tr_address* a, const tr_address* b);
int tr_address_compare(tr_address const* a, tr_address const* b);
bool tr_address_is_valid_for_peers(const tr_address* addr, tr_port port);
bool tr_address_is_valid_for_peers(tr_address const* addr, tr_port port);
static inline bool tr_address_is_valid(const tr_address* a)
static inline bool tr_address_is_valid(tr_address const* a)
{
return (a != NULL) && (a->type == TR_AF_INET || a->type == TR_AF_INET6);
}
@ -120,17 +120,17 @@ static inline bool tr_address_is_valid(const tr_address* a)
struct tr_session;
tr_socket_t tr_netOpenPeerSocket(tr_session* session, const tr_address* addr, tr_port port, bool clientIsSeed);
tr_socket_t tr_netOpenPeerSocket(tr_session* session, tr_address const* addr, tr_port port, bool clientIsSeed);
struct UTPSocket* tr_netOpenPeerUTPSocket(tr_session* session, const tr_address* addr, tr_port port, bool clientIsSeed);
struct UTPSocket* tr_netOpenPeerUTPSocket(tr_session* session, tr_address const* addr, tr_port port, bool clientIsSeed);
tr_socket_t tr_netBindTCP(const tr_address* addr, tr_port port, bool suppressMsgs);
tr_socket_t tr_netBindTCP(tr_address const* addr, tr_port port, bool suppressMsgs);
tr_socket_t tr_netAccept(tr_session* session, tr_socket_t bound, tr_address* setme_addr, tr_port* setme_port);
void tr_netSetTOS(tr_socket_t s, int tos);
void tr_netSetCongestionControl(tr_socket_t s, const char* algorithm);
void tr_netSetCongestionControl(tr_socket_t s, char const* algorithm);
void tr_netClose(tr_session* session, tr_socket_t s);
@ -144,4 +144,4 @@ bool tr_net_hasIPv6(tr_port);
*/
char* tr_net_strerror(char* buf, size_t buflen, int err);
const unsigned char* tr_globalIPv6(void);
unsigned char const* tr_globalIPv6(void);

Some files were not shown because too many files have changed in this diff Show More