mirror of
https://github.com/transmission/transmission
synced 2025-01-30 19:03:04 +00:00
parent
cf9b81eb7d
commit
e127b20c05
17 changed files with 85 additions and 98 deletions
25
gtk/hig.c
25
gtk/hig.c
|
@ -84,14 +84,13 @@ void hig_workarea_add_label_w(GtkWidget* t, guint row, GtkWidget* w)
|
|||
gtk_widget_set_margin_left(w, 18);
|
||||
#endif
|
||||
|
||||
if (GTK_IS_MISC(w))
|
||||
{
|
||||
g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL);
|
||||
}
|
||||
|
||||
if (GTK_IS_LABEL(w))
|
||||
{
|
||||
gtk_label_set_use_markup(GTK_LABEL(w), TRUE);
|
||||
g_object_set(w,
|
||||
"halign", GTK_ALIGN_START,
|
||||
"valign", GTK_ALIGN_CENTER,
|
||||
"use-markup", TRUE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gtk_grid_attach(GTK_GRID(t), w, 0, row, 1, 1);
|
||||
|
@ -99,9 +98,12 @@ void hig_workarea_add_label_w(GtkWidget* t, guint row, GtkWidget* w)
|
|||
|
||||
static void hig_workarea_add_tall_control(GtkWidget* t, guint row, GtkWidget* control)
|
||||
{
|
||||
if (GTK_IS_MISC(control))
|
||||
if (GTK_IS_LABEL(control))
|
||||
{
|
||||
g_object_set(control, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL);
|
||||
g_object_set(control,
|
||||
"halign", GTK_ALIGN_START,
|
||||
"valign", GTK_ALIGN_CENTER,
|
||||
NULL);
|
||||
}
|
||||
|
||||
g_object_set(control, "expand", TRUE, NULL);
|
||||
|
@ -110,9 +112,12 @@ static void hig_workarea_add_tall_control(GtkWidget* t, guint row, GtkWidget* co
|
|||
|
||||
static void hig_workarea_add_control(GtkWidget* t, guint row, GtkWidget* control)
|
||||
{
|
||||
if (GTK_IS_MISC(control))
|
||||
if (GTK_IS_LABEL(control))
|
||||
{
|
||||
g_object_set(control, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL);
|
||||
g_object_set(control,
|
||||
"halign", GTK_ALIGN_START,
|
||||
"valign", GTK_ALIGN_CENTER,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gtk_widget_set_hexpand(control, TRUE);
|
||||
|
|
|
@ -46,6 +46,10 @@ static void popup(GtkStatusIcon* self, guint button, guint when, gpointer data)
|
|||
|
||||
#if GTK_CHECK_VERSION(3, 22, 0)
|
||||
gtk_menu_popup_at_pointer(GTK_MENU(w), NULL);
|
||||
|
||||
TR_UNUSED(self);
|
||||
TR_UNUSED(button);
|
||||
TR_UNUSED(when);
|
||||
#else
|
||||
gtk_menu_popup(GTK_MENU(w), NULL, NULL, gtk_status_icon_position_menu, self, button, when);
|
||||
#endif
|
||||
|
|
|
@ -1931,8 +1931,9 @@ static void copy_tier_attributes(struct tr_torrent_tiers* tt, tr_tier const* src
|
|||
{
|
||||
for (int j = 0; !found && j < tt->tiers[i].tracker_count; ++j)
|
||||
{
|
||||
if ((found = tr_strcmp0(src->currentTracker->announce, tt->tiers[i].trackers[j].announce) == 0))
|
||||
if ((tr_strcmp0(src->currentTracker->announce, tt->tiers[i].trackers[j].announce) == 0))
|
||||
{
|
||||
found = true;
|
||||
copy_tier_attributes_impl(&tt->tiers[i], j, src);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -445,11 +445,11 @@ tr_sys_file_t tr_fdFileGetCached(tr_session* s, int torrent_id, tr_file_index_t
|
|||
|
||||
bool tr_fdFileGetCachedMTime(tr_session* s, int torrent_id, tr_file_index_t i, time_t* mtime)
|
||||
{
|
||||
bool success;
|
||||
tr_sys_path_info info;
|
||||
struct tr_cached_file* o = fileset_lookup(get_fileset(s), torrent_id, i);
|
||||
struct tr_cached_file const* o = fileset_lookup(get_fileset(s), torrent_id, i);
|
||||
tr_sys_path_info info = { 0 };
|
||||
bool const success = o != NULL && tr_sys_file_get_info(o->fd, &info, NULL);
|
||||
|
||||
if ((success = o != NULL && tr_sys_file_get_info(o->fd, &info, NULL)))
|
||||
if (success)
|
||||
{
|
||||
*mtime = info.last_modified_at;
|
||||
}
|
||||
|
|
|
@ -114,22 +114,20 @@ char const* tr_address_to_string(tr_address const* addr)
|
|||
|
||||
bool tr_address_from_string(tr_address* dst, char const* src)
|
||||
{
|
||||
bool ok;
|
||||
bool success = false;
|
||||
|
||||
if ((ok = evutil_inet_pton(AF_INET, src, &dst->addr) == 1))
|
||||
if (evutil_inet_pton(AF_INET, src, &dst->addr) == 1)
|
||||
{
|
||||
dst->type = TR_AF_INET;
|
||||
success = true;
|
||||
}
|
||||
|
||||
if (!ok) /* try IPv6 */
|
||||
else if (evutil_inet_pton(AF_INET6, src, &dst->addr) == 1)
|
||||
{
|
||||
if ((ok = evutil_inet_pton(AF_INET6, src, &dst->addr) == 1))
|
||||
{
|
||||
dst->type = TR_AF_INET6;
|
||||
}
|
||||
dst->type = TR_AF_INET6;
|
||||
success = true;
|
||||
}
|
||||
|
||||
return ok;
|
||||
return success;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1055,13 +1055,15 @@ void tr_peerIoSetPeersId(tr_peerIo* io, uint8_t const* peer_id)
|
|||
{
|
||||
TR_ASSERT(tr_isPeerIo(io));
|
||||
|
||||
if ((io->peerIdIsSet = peer_id != NULL))
|
||||
if (peer_id == NULL)
|
||||
{
|
||||
memcpy(io->peerId, peer_id, 20);
|
||||
memset(io->peerId, '\0', sizeof(io->peerId));
|
||||
io->peerIdIsSet = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(io->peerId, '\0', 20);
|
||||
memcpy(io->peerId, peer_id, sizeof(io->peerId));
|
||||
io->peerIdIsSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -226,14 +226,16 @@ static void start_timer(tr_shared* s)
|
|||
set_evtimer_from_status(s);
|
||||
}
|
||||
|
||||
void tr_sharedTraversalEnable(tr_shared* s, bool isEnabled)
|
||||
void tr_sharedTraversalEnable(tr_shared* s, bool enable)
|
||||
{
|
||||
if ((s->isEnabled = isEnabled))
|
||||
if (enable)
|
||||
{
|
||||
s->isEnabled = true;
|
||||
start_timer(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
s->isEnabled = false;
|
||||
stop_forwarding(s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <limits.h> /* INT_MAX */
|
||||
#include <string.h> /* memcpy(), memset(), memcmp() */
|
||||
|
||||
#include <event2/buffer.h>
|
||||
|
@ -268,7 +269,6 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in
|
|||
if (m->piecesNeededCount == 0)
|
||||
{
|
||||
bool success = false;
|
||||
bool checksumPassed = false;
|
||||
bool metainfoParsed = false;
|
||||
uint8_t sha1[SHA_DIGEST_LENGTH];
|
||||
|
||||
|
@ -276,14 +276,16 @@ void tr_torrentSetMetadataPiece(tr_torrent* tor, int piece, void const* data, in
|
|||
dbgmsg(tor, "metainfo piece %d was the last one", piece);
|
||||
tr_sha1(sha1, m->metadata, m->metadata_size, NULL);
|
||||
|
||||
if ((checksumPassed = memcmp(sha1, tor->info.hash, SHA_DIGEST_LENGTH) == 0))
|
||||
bool const checksumPassed = memcmp(sha1, tor->info.hash, SHA_DIGEST_LENGTH) == 0;
|
||||
if (checksumPassed)
|
||||
{
|
||||
/* checksum passed; now try to parse it as benc */
|
||||
tr_variant infoDict;
|
||||
int const err = tr_variantFromBenc(&infoDict, m->metadata, m->metadata_size);
|
||||
dbgmsg(tor, "err is %d", err);
|
||||
|
||||
if ((metainfoParsed = err == 0))
|
||||
metainfoParsed = err == 0;
|
||||
if (metainfoParsed)
|
||||
{
|
||||
/* yay we have bencoded metainfo... merge it into our .torrent file */
|
||||
tr_variant newMetainfo;
|
||||
|
|
|
@ -3511,7 +3511,7 @@ bool tr_torrentFindFile2(tr_torrent const* tor, tr_file_index_t fileNum, char co
|
|||
tr_file const* file;
|
||||
char const* b = NULL;
|
||||
char const* s = NULL;
|
||||
tr_sys_path_info file_info;
|
||||
tr_sys_path_info file_info = { 0 };
|
||||
|
||||
file = &tor->info.files[fileNum];
|
||||
|
||||
|
|
|
@ -326,8 +326,8 @@ int tr_dhtInit(tr_session* ss)
|
|||
uint8_t* nodes = NULL;
|
||||
uint8_t* nodes6 = NULL;
|
||||
uint8_t const* raw;
|
||||
size_t len;
|
||||
size_t len6;
|
||||
size_t len = 0;
|
||||
size_t len6 = 0;
|
||||
struct bootstrap_closure* cl;
|
||||
|
||||
if (session_ != NULL) /* already initialized */
|
||||
|
|
|
@ -57,6 +57,8 @@ typedef uint16_t in_port_t; /* all missing */
|
|||
#include "utils.h"
|
||||
#include "version.h"
|
||||
|
||||
#define SIZEOF_HASH_STRING (sizeof(((struct tr_info*)0)->hashString))
|
||||
|
||||
/**
|
||||
* @brief Local Peer Discovery
|
||||
* @file tr-lpd.c
|
||||
|
@ -80,7 +82,6 @@ static tr_socket_t lpd_socket2; /**<and multicast send socket */
|
|||
static struct event* lpd_event = NULL;
|
||||
static tr_port lpd_port;
|
||||
|
||||
static tr_torrent* lpd_torStaticType; /* just a helper for static type analysis */
|
||||
static tr_session* session;
|
||||
|
||||
enum
|
||||
|
@ -299,6 +300,12 @@ int tr_lpdInit(tr_session* ss, tr_address* tr_addr)
|
|||
{
|
||||
TR_UNUSED(tr_addr);
|
||||
|
||||
/* if this check fails (i.e. the definition of hashString changed), update
|
||||
* string handling in tr_lpdSendAnnounce() and tr_lpdConsiderAnnounce().
|
||||
* However, the code should work as long as interfaces to the rest of
|
||||
* libtransmission are compatible with char* strings. */
|
||||
TR_STATIC_ASSERT(sizeof(((struct tr_info*)0)->hashString[0]) == sizeof(char), "");
|
||||
|
||||
struct ip_mreq mcastReq;
|
||||
int const opt_on = 1;
|
||||
int const opt_off = 0;
|
||||
|
@ -454,21 +461,6 @@ bool tr_lpdEnabled(tr_session const* ss)
|
|||
return ss != NULL && ss == session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @cond
|
||||
* @brief Performs some (internal) software consistency checks at compile time.
|
||||
* @remark Declared inline for the compiler not to allege us of feeding unused
|
||||
* functions. In any other respect, lpd_consistencyCheck is an orphaned function.
|
||||
*/
|
||||
static inline void lpd_consistencyCheck(void)
|
||||
{
|
||||
/* if the following check fails, the definition of a hash string has changed
|
||||
* without our knowledge; revise string handling in functions tr_lpdSendAnnounce
|
||||
* and tr_lpdConsiderAnnounce. However, the code is designed to function as long
|
||||
* as interfaces to the rest of the lib remain compatible with char* strings. */
|
||||
TR_STATIC_ASSERT(sizeof(lpd_torStaticType->info.hashString[0]) == sizeof(char), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @endcond */
|
||||
|
||||
|
@ -497,7 +489,7 @@ bool tr_lpdSendAnnounce(tr_torrent const* t)
|
|||
CRLF
|
||||
CRLF;
|
||||
|
||||
char hashString[lengthof(t->info.hashString)];
|
||||
char hashString[SIZEOF_HASH_STRING];
|
||||
char query[lpd_maxDatagramLength + 1] = { 0 };
|
||||
|
||||
if (t == NULL)
|
||||
|
@ -553,7 +545,7 @@ static int tr_lpdConsiderAnnounce(tr_pex* peer, char const* const msg)
|
|||
enum
|
||||
{
|
||||
maxValueLen = 25,
|
||||
maxHashLen = lengthof(lpd_torStaticType->info.hashString)
|
||||
maxHashLen = SIZEOF_HASH_STRING
|
||||
};
|
||||
|
||||
struct lpd_protocolVersion ver = { .major = -1, .minor = -1 };
|
||||
|
|
|
@ -31,16 +31,5 @@ void tr_lpdUninit(tr_session*);
|
|||
bool tr_lpdEnabled(tr_session const*);
|
||||
bool tr_lpdSendAnnounce(tr_torrent const*);
|
||||
|
||||
/**
|
||||
* @defgroup Preproc Helper macros
|
||||
* @{
|
||||
*
|
||||
* @def lengthof
|
||||
* @brief returns the static length of a C array type
|
||||
* @note A lower case macro name is tolerable here since this definition of lengthof()
|
||||
* is intimately related to sizeof semantics.
|
||||
* Meaningful return values are only guaranteed for true array types. */
|
||||
#define lengthof(arr) (sizeof(*(arr)) > 0 ? sizeof(arr) / sizeof(*(arr)) : 0)
|
||||
|
||||
/**
|
||||
* @} */
|
||||
|
|
|
@ -55,7 +55,8 @@
|
|||
****
|
||||
***/
|
||||
|
||||
#define TR_UNUSED(x) (void)(x)
|
||||
// http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/
|
||||
#define TR_UNUSED(x) do { ((void)sizeof(x)); } while(0)
|
||||
|
||||
/***
|
||||
****
|
||||
|
@ -138,7 +139,7 @@
|
|||
#elif __has_feature(c_static_assert) || __has_extension(c_static_assert) || TR_GNUC_CHECK_VERSION(4, 6)
|
||||
#define TR_STATIC_ASSERT _Static_assert
|
||||
#else
|
||||
#define TR_STATIC_ASSERT(x, msg) (void)(x)
|
||||
#define TR_STATIC_ASSERT(x, msg) do { ((void)sizeof(x)); } while(0)
|
||||
#endif
|
||||
|
||||
/* Sometimes the system defines MAX/MIN, sometimes not.
|
||||
|
|
|
@ -55,15 +55,12 @@ struct tr_watchdir
|
|||
static bool is_regular_file(char const* dir, char const* name)
|
||||
{
|
||||
char* const path = tr_buildPath(dir, name, NULL);
|
||||
tr_sys_path_info path_info;
|
||||
tr_sys_path_info path_info = { 0 };
|
||||
tr_error* error = NULL;
|
||||
bool ret;
|
||||
|
||||
if ((ret = tr_sys_path_get_info(path, 0, &path_info, &error)))
|
||||
{
|
||||
ret = path_info.type == TR_SYS_PATH_IS_FILE;
|
||||
}
|
||||
else
|
||||
bool const ret = tr_sys_path_get_info(path, 0, &path_info, &error) && (path_info.type == TR_SYS_PATH_IS_FILE);
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
if (!TR_ERROR_IS_ENOENT(error->code))
|
||||
{
|
||||
|
|
|
@ -154,6 +154,9 @@ static int sockoptfunction(void* vtask, curl_socket_t fd, curlsocktype purpose)
|
|||
|
||||
static CURLcode ssl_context_func(CURL* curl, void* ssl_ctx, void* user_data)
|
||||
{
|
||||
TR_UNUSED(curl);
|
||||
TR_UNUSED(user_data);
|
||||
|
||||
tr_x509_store_t const cert_store = tr_ssl_get_x509_store(ssl_ctx);
|
||||
if (cert_store == NULL)
|
||||
{
|
||||
|
@ -205,11 +208,6 @@ static CURLcode ssl_context_func(CURL* curl, void* ssl_ctx, void* user_data)
|
|||
CertCloseStore(sys_cert_store, 0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
TR_UNUSED(curl);
|
||||
TR_UNUSED(user_data);
|
||||
|
||||
#endif
|
||||
|
||||
return CURLE_OK;
|
||||
|
@ -599,9 +597,18 @@ void tr_webClose(tr_session* session, tr_web_close_mode close_mode)
|
|||
}
|
||||
}
|
||||
|
||||
void tr_webGetTaskInfo(struct tr_web_task* task, tr_web_task_info info, void* dst)
|
||||
long tr_webGetTaskResponseCode(struct tr_web_task* task)
|
||||
{
|
||||
curl_easy_getinfo(task->curl_easy, (CURLINFO)info, dst);
|
||||
long code = 0;
|
||||
curl_easy_getinfo(task->curl_easy, CURLINFO_RESPONSE_CODE, &code);
|
||||
return code;
|
||||
}
|
||||
|
||||
char const* tr_webGetTaskRealUrl(struct tr_web_task* task)
|
||||
{
|
||||
char* url = NULL;
|
||||
curl_easy_getinfo(task->curl_easy, CURLINFO_EFFECTIVE_URL, &url);
|
||||
return url;
|
||||
}
|
||||
|
||||
/*****
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "tr-macros.h"
|
||||
|
||||
TR_BEGIN_DECLS
|
||||
|
@ -17,14 +15,6 @@ TR_BEGIN_DECLS
|
|||
struct tr_address;
|
||||
struct tr_web_task;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TR_WEB_GET_CODE = CURLINFO_RESPONSE_CODE,
|
||||
TR_WEB_GET_REDIRECTS = CURLINFO_REDIRECT_COUNT,
|
||||
TR_WEB_GET_REAL_URL = CURLINFO_EFFECTIVE_URL
|
||||
}
|
||||
tr_web_task_info;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TR_WEB_CLOSE_WHEN_IDLE,
|
||||
|
@ -49,7 +39,9 @@ struct evbuffer;
|
|||
struct tr_web_task* tr_webRunWebseed(tr_torrent* tor, char const* url, char const* range, tr_web_done_func done_func,
|
||||
void* done_func_user_data, struct evbuffer* buffer);
|
||||
|
||||
void tr_webGetTaskInfo(struct tr_web_task* task, tr_web_task_info info, void* dst);
|
||||
long tr_webGetTaskResponseCode(struct tr_web_task* task);
|
||||
|
||||
char const* tr_webGetTaskRealUrl(struct tr_web_task* task);
|
||||
|
||||
void tr_http_escape(struct evbuffer* out, char const* str, size_t len, bool escape_slashes);
|
||||
|
||||
|
|
|
@ -242,19 +242,14 @@ static void on_content_changed(struct evbuffer* buf, struct evbuffer_cb_info con
|
|||
|
||||
if (task->response_code == 0)
|
||||
{
|
||||
tr_webGetTaskInfo(task->web_task, TR_WEB_GET_CODE, &task->response_code);
|
||||
task->response_code = tr_webGetTaskResponseCode(task->web_task);
|
||||
|
||||
if (task->response_code == 206)
|
||||
{
|
||||
char const* url;
|
||||
struct connection_succeeded_data* data;
|
||||
|
||||
url = NULL;
|
||||
tr_webGetTaskInfo(task->web_task, TR_WEB_GET_REAL_URL, &url);
|
||||
|
||||
data = tr_new(struct connection_succeeded_data, 1);
|
||||
data->webseed = w;
|
||||
data->real_url = tr_strdup(url);
|
||||
data->real_url = tr_strdup(tr_webGetTaskRealUrl(task->web_task));
|
||||
data->piece_index = task->piece_index;
|
||||
data->piece_offset = task->piece_offset + task->blocks_done * task->block_size + len - 1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue