Commit Graph

387 Commits

Author SHA1 Message Date
Charles Kerr 19e52d8b9a
chore: sonarcloud warnings 2 (#1496)
* fix "merge nested if" sonarcloud warnings

* fix explicit constructor warnings in qt client
2020-11-01 15:47:57 -06:00
Charles Kerr a4dd67ae45
chore: fix some fixmes (#1449)
* chore: remove assertions that were flagged for removal

* chore: remove unneeded check

* refactor: move tr_peerIoAddrStr to net.h

* refactor: formatter API now takes size_t args

* chore: remove out-of-date FIXME comment

* refactor: cleanup logging win32 ifdefs
2020-09-13 16:43:29 -05:00
Charles Kerr d3323ddee0
fix: Coverity warnings (#1443)
* fix: coverity warnings
2020-09-10 18:50:46 -05:00
Mike Gelfand ff8d0dbf3b Switch from UNUSED macro to TR_UNUSED macro
Since there is no way to mark parameters as [potentially] unused in
standard C and when using MSVC compiler, use the widely accepted
cast-to-void approach instead.
2020-08-18 14:19:55 +03:00
Charles Kerr 677dc73eac
refactor: use GTest for running tests (#1383)
* refactor: use google-test on libtransmission tests
2020-08-11 13:11:55 -05:00
Pedro Scarapicchia Junior 5be8bd50f9
Check if log deep is enabled before tr_logAddDeep (#1329)
Co-authored-by: Charles Kerr <charles@charleskerr.com>
2020-07-28 12:31:36 -05:00
Charles Kerr 00be8d00d7
refactor: make variant_headers reusable to qt app. (#1369)
* refactor: make variant_headers reusable to qt app.

Torrent.cc's `change()` template methods are generically useful to deal
with tr_variant wrangling, but previously were only used in Torrent.cc.
This PR moves them into a new API `VariantHelpers.h` for use by Prefs,
Session, TorrentModel, etc.
2020-07-26 23:30:58 -05:00
Charles Kerr fa6df52d58
chore: remove unused methods (#1207)
* chore: remove unused methods in qt client

* chore: remove unused libtransmission methods

* chore: remove unused gtk methods

* chore: remove more unused libtransmission methods

* chore: remove more unused code found by @reardonia
2020-05-11 17:20:46 -05:00
Mingye Wang bcf8128400 Unify/Modernize TOS to DSCP standards (#737)
* Unify/Modernize TOS to DSCP standards

The set of pre-named TOS values are now renamed to the latest DSCP
standards, with traffic classes and everything exciting. To keep
everything in the same place, a segment has been added to net.h to keep
the currently named values.

A result of these changes is that "lowcost" is probably no longer
harmless, as it now encourages the router to preferentially drop the
packages when bandwidth requires so. "lowdelay" is assigned to a pretty
high AF class for SIP and stuff. I am not sure at all about the
"throughput" assignment. I mean, the whole point of DSCP-fication is
translating from the old ToS bits to a more precedence-based notation,
and precedence is supposed to lie beside the old 4 ToS bits...

A funny interaction between the AFxy and the old ToS fields lies in
the old "reliability" (0x08) field. All odd numbers of y (1, 3 : low,
high) switches it on. If you spend 5 more minutes on it you can probably
come up with "pun" values that hold similar meanings in DSCP and
Prec/ToS.

By removing the IPv6 override, I should have kind of satisfied the #692
request.

Fixes: #692
2019-07-21 14:09:04 +03:00
Mike Gelfand 10cdd7f790 Use explicit boolean conversions 2019-07-14 16:25:07 +03:00
Mike Gelfand a3e4919385 Introduce `tr_str_is_empty` to relay intent better 2019-07-13 12:00:06 +03:00
Mike Gelfand 97a0fed734 Remove side effects from right hand operands of && or ||
* MISRA C:2004, 12.4 - The right-hand operand of a logical && or || operator
  shall not contain side effects.
* MISRA C++:2008, 5-14-1 - The right hand operand of a logical && or ||
  operator shall not contain side effects.
* MISRA C:2012, 13.5 - The right hand operand of a logical && or || operator
  shall not contain persistent side effects
* CERT, EXP02-C. - Be aware of the short-circuit behavior of the logical AND
  and OR operators
2019-03-17 09:09:08 +03:00
Tavis Ormandy cf7173df93 mitigate dns rebinding attacks against daemon 2018-01-15 23:31:25 +03:00
Mike Gelfand 18aabdeb06 Introduce peer socket struct to improve readability 2017-06-28 18:50:05 +03:00
Mike Gelfand deea6fc6a2 Bring assertions closer to the beginning of blocks 2017-06-13 07:44:09 +03:00
Mike Gelfand 98695fe3c1 Introduce our own assertion macros with finer control 2017-06-08 10:24:12 +03:00
Mike Gelfand f27596238d Include stdbool.h unconditionally
All the compilers should provide the header file by now. Remove `tr_isBool`
sanity checks along the way as compiler should guarantee that bool (_Bool)
values are 0 or 1 and nothing else.
2017-05-24 22:53:06 +03:00
Mike Gelfand 501be27972 Reduce code duplication in logging macros 2017-05-22 23:20:28 +03:00
Mike Gelfand 1e3d20422a Reduce for loop variables scope 2017-05-14 01:38:31 +03:00
Mike Gelfand e1d53855f4 Avoid declaring multiple variables on the same line 2017-05-01 18:46:41 +03:00
Mike Gelfand fbd8d4c79f Fix a number of other style inconsistencies met along the way 2017-04-30 19:33:55 +03:00
Mike Gelfand a762c770f2 Make conditional expressions explicitly boolean 2017-04-30 19:26:01 +03:00
Mike Gelfand 4f9d9ad92b Code style change leftovers
For some reason, GTK client wasn't fully processed. All the rest of changes
are mostly in comments.
2017-04-21 10:40:57 +03:00
Mike Gelfand dadffa2c0f 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".
2017-04-20 19:53:20 +03:00
Mike Gelfand d7930984ef Adjust uncrustify config, reformat all but Mac client
There're places where manual intervention is still required as uncrustify
is not ideal (unfortunately), but at least one may rely on it to do the
right thing most of the time (e.g. when sending in a patch).

The style itself is quite different from what we had before but making it
uniform across all the codebase is the key. I also hope that it'll make the
code more readable (YMMV) and less sensitive to further changes.
2017-04-20 10:01:22 +03:00
Mike Gelfand 1cc67b31dd Use PRIdMAX instead of TR_PRI_SOCK to accomodate intltool 2017-01-27 04:50:14 +03:00
Mike Gelfand c1f08edf79 Fix memory leaks found by GCC's -address=sanitize (reported by milloni)
Fixes: #56
2017-01-17 23:55:34 +03:00
Mike Gelfand 67bda2dcb8 Handle two more cases where dirname/basename may have returned NULL (adds to 91f8ceb20d) 2017-01-17 02:22:31 +03:00
Mike Gelfand 26b0a041cc Factor out session ID into a standalone entity 2016-09-21 22:29:56 +03:00
Mike Gelfand 2248d3670f Get rid of $Id$ SVN keywords in source files 2016-09-02 23:10:15 +03:00
Mike Gelfand c955c04d8f Explicitly compare result of str(n)cmp/memcmp to signify that it's not boolean 2016-03-13 22:11:01 +00:00
Mike Gelfand 13a98a02b8 Use `TR_BAD_SIZE` instead of -1 in `tr_quark_new()` calls
Extend quark test to improve branch coverage.
2016-01-07 19:20:14 +00:00
Mike Gelfand 7d30ad3ff6 #5891: Move UDP shutdown timer setup to sessionCloseImplStart 2015-12-31 14:24:15 +00:00
Mike Gelfand d3f5b5d5ab #5891: Fix crash on session shutdown (evdns_getaddrinfo_cancel) 2015-12-31 14:17:37 +00:00
Mike Gelfand eb8fc35ac6 Remove useless checks and definitions (C99)
Now that MSVC support for C99 is quite good, remove previously needed but
now unused checks and definitions, like PRI* format macros (including
PRIdMAX and TR_PRIuSIZE, replaced with %jd and %zu) and inline macro.
Also, remove ssize_t typedef and replace few occurences with ev_ssize_t.
Also, remove check for stdbool.h availability (guaranteed by C99) and
include it unconditionally (except when in C++ mode).
2015-12-29 19:37:31 +00:00
Jordan Lee b559a20029 const correctness
silence some qual-cast warnings by sprinkling more consts throughout,
e.g. casting a const void* to a const struct foo * const *
2015-12-06 22:13:10 +00:00
Mike Gelfand f89fab72f9 Remove unused session tag 2015-10-18 18:39:14 +00:00
Mike Gelfand 0420699ad6 Initialise networking in daemon before making libevent calls 2015-10-11 16:35:51 +00:00
Mike Gelfand cdf3cf62f9 Fix some issues revealed by coverity 2015-05-09 11:56:35 +00:00
Mike Gelfand df98031294 #5946: Save "prefetch-enabled" setting as boolean (spotted by cfpp2p) 2015-05-07 06:45:35 +00:00
Mike Gelfand 3b129a72d8 #5908: Check for `tr_loadFile` return value instead of `errno` in `tr_variantFromFile`
Seems like there could be a defect in uClibc making errno not
thread-local. Don't rely on errno value but check function return value
instead which is a better failure indicator.

Return errors from `tr_loadFile` and `tr_variantFromFile` via tr_error.
Fix `tr_sessionLoadSettings` to not fail on Windows if settings.json
does not exist.
2015-04-11 10:51:59 +00:00
Mike Gelfand 949e02b933 Define and use tr_socket_t and TR_BAD_SOCKET instead of int and -1.
Test socket validity by comparing to TR_BAD_SOCKET instead of various
(and sometimes wrong) other tests like `x >= 0`, `x != -1`, `x > 0`,
`x > -1`, `x` (valid), and `x < 0`, `x == -1` (invalid).
2015-03-18 07:34:26 +00:00
Mike Gelfand 440f482d01 Replace tabs with spaces; remove trailing spaces 2015-01-02 11:15:31 +00:00
Mike Gelfand 52a9d774e4 Fix compilation on Windows
This should not affect non-Win32 platforms in any way.
As for Win32 (both MinGW and MSVC), this should hopefully allow for
unpatched compilation. Correct functioning is not yet guaranteed though.
2014-12-13 15:22:39 +00:00
Mike Gelfand f6f7bf8227 #4400, #5462: Move random helpers to crypto-utils
On a way to factoring out OpenSSL support to a standalone file to ease
addition of other crypto libraries support in the future, move helpers
providing random numbers/data generation to crypto-utils.{c,h}. OpenSSL-
related functionality (generation of cryptographically strong random
data) is moved to crypto-utils-openssl.c.

Rename functions to follow currently accepted style:
* tr_cryptoRandBuf -> tr_rand_buffer
* tr_cryptoRandInt -> tr_rand_int
* tr_cryptoWeakRandInt -> tr_rand_int_weak

Fix rare case of invalid value being returned from tr_rand_int. Return
value for abs(INT_MIN) may be undefined and thus negative, and so
tr_rand_int will return negative value which is incorrect (out of
requested and expected range).
2014-12-04 11:27:38 +00:00
Jordan Lee d9d66e3e42 (trunk, libt) #4160 - the slow slog to catch trunk up to mike.dld's 4160 diff continues. This step applies 4160-04b-dir.patch, which replaces native file operations with the tr_sys_dir_*() portability wrappers added in the previous commit. 2014-09-21 17:55:39 +00:00
Jordan Lee 0323639e57 (trunk, libT) #4160 'foreign character support' -- merge mike.dld's 4160-02b-path.patch, which updates the codebase to use the new tr_sys_path_*() portability wrappers introduced in 4160-02a 2014-07-08 00:08:43 +00:00
Mitchell Livingston 0e01879974 Use built-in _WIN32 macro instead of WIN32 2014-07-04 00:00:07 +00:00
Jordan Lee 5a2268289e (trunk, libT) #5651 'int to bool patch' -- fixed, patch by rajmannugetr 2014-04-27 23:10:01 +00:00
Jordan Lee 02cff80c2d Copyedit the license's revised text: (1) remove unnecessary repitition use of the word 'license' from the top of the header and source files (2) add the standard 'we hope it's useful, but no warranty' clause to COPYING (3) make explicit that linking OpenSSL is allowed (see https://people.gnome.org/~markmc/openssl-and-the-gpl.html for background) (4) sync the Qt and GTK+ clients' license popups with COPYING's revised text 2014-01-21 03:10:30 +00:00