Commit Graph

260 Commits

Author SHA1 Message Date
Charles Kerr 41f225df7b
Remove posix memalign (#1520)
* refactor: remove unnecessary func tr_valloc()

We're only using it in a handful of places, and none of them need the
kind of alignment that posix_memalign() provide. So we can drop a few
dozen lines by removing the portability wrapper.
2020-11-15 15:53:42 -06:00
Chrool cfce6e2e3a
configure anti brute force (#1447)
* add brute force configuration options
2020-11-14 12:43:42 -06:00
Charles Kerr 7f147c65fb
refactor: fix more sonarcloud warnings (#1508)
* refactor: const correctness

* refactor: use getpwuid_r instead of getpwuid

* chore: simplify dict walking loop logic

* refactor: remove dead store assignment in announcer

* refactor: use std::make_shared
2020-11-05 16:46:21 -06:00
Charles Kerr 73fdd722a7
Sonarcloud warnings 3 (#1498)
* chore: use ClassName:: for calling static methods

* chore: prefer to initialize member data in the class initializer
2020-11-01 19:13:32 -06:00
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 f59118d1fe
feat: add torrent-get 'primary-mime-type' to RPC. (#1464)
* feat: add torrent-get 'primary-mime-type' to RPC.

This is a cheap way for RPC clients to know what type of content is in a
torrent. This info can be used to display the torrent, e.g. by using an
icon that corresponds to the mime type.

* use size_t for content byte count

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>

* explicit boolean expressions

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>

* use uint64_t for content byte counts

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>

* avoid unnecessary logic branches

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>

* explicit cast

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>

* refactor: add an autogenerated mime-type.h header

* chore: maybe fix the win32 FTBFS

* chore: add mime-types.[ch] to xcode

* Squashed commit of the following:

commit 4c7153fa48
Author: Mike Gelfand <mikedld@users.noreply.github.com>
Date:   Tue Oct 13 03:15:19 2020 +0300

    Remove autotools-based build system (#1465)

    * Support .git files (e.g. for worktrees, submodules)
    * Fix symlinks in source tarball, switch to TXZ, adjust non-release name
    * Remove autotools stuff

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
2020-10-13 10:33:56 -05:00
Charles Kerr d3323ddee0
fix: Coverity warnings (#1443)
* fix: coverity warnings
2020-09-10 18:50:46 -05:00
Mike Gelfand b7a8bd45b7 Reformat affected code after recent changes 2020-08-18 20:31:06 +03: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
Charles Kerr 44fc571a67
feat: add editDate to RPC (#1056)
* feat: add tr_stat.infoDate to note tr_info changes

The last time during this session that any tr_info field changed
(e.g. trackers/filenames edited or magnet torrent got metadata).
RPC clients can monitor this to know when to reload fields which
don't usually change.
2019-11-12 17:13:42 -06:00
Charles Kerr 96f76999aa
feat: add "table" format in torrent-get RPC (#1049)
* feat: add optional "format" arg to torrent-get RPC

If the "format" request was "objects" (default), "torrents" will be an
array of objects, each of which contains the key/value pairs matching
the request's "fields" arg. This is unchanged from previous versions.

If the format was "table", then "torrents" will be an array of arrays.
The first row holds the keys and each remaining row holds a torrent's
values for those keys. This format is more efficient in terms of JSON
generation and JSON parsing.
2019-11-09 17:02:23 -06: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
Mike Gelfand 17307e7484 Extract assignments from expression
Assignments explicitly enclosed in parentheses are ignored.

* MISRA C:2004, 13.1 - Assignment operators shall not be used in expressions
  that yield a Boolean value
* MISRA C++:2008, 6-2-1 - Assignment operators shall not be used in
  sub-expressions
* MISRA C:2012, 13.4 - The result of an assignment operator should not be used
* MITRE, CWE-481 - Assigning instead of Comparing
* CERT, EXP45-C. - Do not perform assignments in selection statements
* CERT, EXP51-J. - Do not perform assignments in conditional expressions
2019-03-17 08:00:15 +03:00
Charles Kerr 309d97c578
fix: Coverity warnings (#842)
* Silence coverity CHECKED_RETURN on added.f load

The existing code behaved alright since added.f is optional.
However, by testing for success we can both silence the warning
and prevent a useless initialization of NULL/0 to added_f and
added_f_length.

* Silence coverity CHECKED_RETURN on added6.f load

ipv6 variant of previous commit.

* Silence coverity CHECKED_RETURN writing benc strs

saveStringFunc() gets the target string by calling tr_variantGetStr().
It previously didn't check to see if this function succeeded because
saveStringFunc() isn't reached without the type already being known.
However, checking the return value costs nothing and makes Coverity happy.

* Silence coverity CHECKED_RETURN on ut metadata

Like earlier few Coverity commits in this PR, we're handling optional
values by declaring stack locals set to the default (e.g. -1) and then
trying to read the variant.

Unlike the earlier commits, there is a two-part step to thise read:
checking for the metadata, then checking for the individual fields.
The earlier fixes' aproach -- e.g. initializing to -1 only if the reads
failed -- would involve new nested conditionals. I find the new complexity
to outweigh the benefit of removing the dead store, so in this case I'm
casting the return value to `(void)` to tell Coverity to shush.

* Silence coverity CHECKED_RETURN on scrape

Check the return value of tr_variantGetInt() when showing
seeder and leecher counts in transmission-show.

* Silence CHECKED_RETURN on rpc recently-active

When building a list of removed torrent IDs from variants, confirm that
we can read the IDs from the variants before adding them to the list.
I don't _think_ this would have failed before, but Coverity's right that
it's reasonable to add a safeguard here.

* fix: better fix to serializing benc strings

The approach in 33e2ece7e5 was
a little problematic: GetString() shouldn't fail here; but if
it somehow did, we still want to encode a zero-length benc string here.

* chore: make uncrustify happy
2019-02-18 22:38:24 +00:00
qu1ck 7aa12a025d Add labels feature (#822)
* applied changes from https://github.com/Elbandi/transmission/tree/elbandi/labels to official transmission repo

* Fix compilation errors

* Address review comments

Changed `tr_ptrArray* labels` to `tr_ptrArray labels`;
Removed tr_ptrArrayNew() tr_ptrArrayDup() tr_ptrArrayFree()
Use tr_strsep() to split string by delimiters
Update transmission-remote.1
Update rpc-spec.txt

* Fix warning, address comments

* Rebase, fix formatting and address comments

Use uncrustify to format changed files
Fix "const <type>" -> "<type> const"
Fix small comments

* Lock torrent for setLabels, check for duplicates

* Check for empty labels in daemon

* Stop on first error
2019-02-17 04:33:57 -05:00
Mike Gelfand 13bbaeec76 Use field initializers for readability 2017-06-24 13:30:33 +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 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
Markus Amalthea Magnuson 5b9ba3be0d HTTPS links for trac, forum, portcheck, and build subdomains. 2016-11-02 20:50:22 +01:00
Mike Gelfand 661e2b513d Return session ID as part of "session-get" response 2016-09-27 21:18:36 +03:00
Mike Gelfand ff73e65069 Handle "fields" argument in "session-get" RPC request
If "fields" array is present in arguments, only return session fields
specified. Otherwise return all the fields as before.
2016-09-27 21:18:32 +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 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
Mike Gelfand e3c5ab74ed #5963: Fix two more places where int is used in boolean context 2015-12-27 15:19:03 +00:00
Mike Gelfand 4a4badd4af Ongoing refactoring (use size_t instead of int) 2015-12-25 10:19:50 +00:00
Mike Gelfand 505561c055 #5802: Require absolute paths in "session-set" and "free-space" requests as well 2015-11-05 21:48:00 +00:00
Mike Gelfand 650db1f46e #5802: Don't make assumptions of remote path validity in transmission-remote
Defer validity checks until path gets to the remote side, where they
actually make sense. Add simple checks for download directory path to
ensure it's not relative, since one cannot know what current working
directory of the remote process is.
2015-10-20 21:22:19 +00:00
Mike Gelfand ca21c1f230 Always invoke async RPC callback, even if operation failed to start 2015-10-20 21:06:01 +00:00
Mike Gelfand 18ea8c429a Improve RPC performance for local sessions
Don't unnecessarily de-/serialize JSON data if local session is used.
2015-07-13 00:32:48 +00:00
Mike Gelfand cdf3cf62f9 Fix some issues revealed by coverity 2015-05-09 11:56:35 +00:00
Mike Gelfand 0c01e6e19d #5937: Don't send TR_RPC_TORRENT_ADDED notification if torrent wasn't actually added (patch by xzcvczx) 2015-04-29 19:42:05 +00:00
Mike Gelfand 440f482d01 Replace tabs with spaces; remove trailing spaces 2015-01-02 11:15:31 +00:00
Mike Gelfand 5c43b5c23c #4400, #5462: Move BASE64 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 BASE64 encoding and decoding to crypto-utils.{c,h}. OpenSSL-
related functionality is moved to crypto-utils-openssl.c.

Add new functions to be implemented by crypto backends:
* tr_base64_encode_impl - encode from binary to BASE64,
* tr_base64_decode_impl - decode from BASE64 to binary.

Change `tr_base64_encode` and `tr_base64_decode` functions to expect
non-negative input data length which is considered real and never adjusted.
To process null-terminated strings (which was achieved before by passing 0
or -1 as input data length), add new `tr_base64_encode_str` and
`tr_base64_decode_str` functions which do not accept input data length as
an argument but calculate it on their own.
2014-12-04 19:58:34 +00:00
Jordan Lee b33a7d4dc1 (trunk, libt) #4160 - the slow slog to catch trunk up to mike.dld's 4160 diff continues. This step applies 4160-03b-file.patch, which replaces native file operations with the tr_sys_file_*() portability wrappers added in r14321. 2014-07-28 04:13:38 +00:00
Jordan Lee 2e3ffdc6ec since libz's been required in rpcimpl.c for ages and nobody's complained, remove the HAVE_ZLIB cruft for conditional-compiling with and without zlib. 2014-07-13 21:50:56 +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
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
Jordan Lee f470ab3210 (trunk, libT) #5583 'blockfile.tmp file descriptor is leaked when importing blocklist' -- fix by rb07. 2014-01-19 02:03:41 +00:00