tr_makeMetaInfo: new anonymize option (closes #3420) (#3452)

This commit is contained in:
David Miguel Susano Pinto 2022-07-19 22:48:24 +01:00 committed by GitHub
parent 94eeebc5b3
commit f8b3514c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 3 deletions

View File

@ -315,6 +315,7 @@ void MakeDialog::Impl::onResponse(int response)
0, 0,
useComment ? comment.c_str() : nullptr, useComment ? comment.c_str() : nullptr,
isPrivate, isPrivate,
false,
useSource ? source.c_str() : nullptr); useSource ? source.c_str() : nullptr);
} }
} }

View File

@ -501,8 +501,11 @@ static void tr_realMakeMetaInfo(tr_metainfo_builder* builder)
tr_variantDictAddStr(&top, TR_KEY_comment, builder->comment); tr_variantDictAddStr(&top, TR_KEY_comment, builder->comment);
} }
tr_variantDictAddStrView(&top, TR_KEY_created_by, TR_NAME "/" LONG_VERSION_STRING); if (!builder->anonymize)
tr_variantDictAddInt(&top, TR_KEY_creation_date, time(nullptr)); {
tr_variantDictAddStrView(&top, TR_KEY_created_by, TR_NAME "/" LONG_VERSION_STRING);
tr_variantDictAddInt(&top, TR_KEY_creation_date, time(nullptr));
}
tr_variantDictAddStrView(&top, TR_KEY_encoding, "UTF-8"); tr_variantDictAddStrView(&top, TR_KEY_encoding, "UTF-8");
makeInfoDict(tr_variantDictAddDict(&top, TR_KEY_info, 666), builder); makeInfoDict(tr_variantDictAddDict(&top, TR_KEY_info, 666), builder);
} }
@ -577,6 +580,7 @@ void tr_makeMetaInfo(
int webseedCount, int webseedCount,
char const* comment, char const* comment,
bool isPrivate, bool isPrivate,
bool anonymize,
char const* source) char const* source)
{ {
/* free any variables from a previous run */ /* free any variables from a previous run */
@ -613,6 +617,7 @@ void tr_makeMetaInfo(
builder->comment = tr_strdup(comment); builder->comment = tr_strdup(comment);
builder->isPrivate = isPrivate; builder->isPrivate = isPrivate;
builder->anonymize = anonymize;
builder->source = tr_strdup(source); builder->source = tr_strdup(source);
builder->outputFile = !tr_str_is_empty(outputFile) ? tr_strdup(outputFile) : builder->outputFile = !tr_str_is_empty(outputFile) ? tr_strdup(outputFile) :

View File

@ -62,6 +62,7 @@ struct tr_metainfo_builder
char* outputFile; char* outputFile;
bool isPrivate; bool isPrivate;
char* source; char* source;
bool anonymize;
/** /**
*** These are set inside tr_makeMetaInfo() so the client *** These are set inside tr_makeMetaInfo() so the client
@ -128,4 +129,5 @@ void tr_makeMetaInfo(
int n_webseeds, int n_webseeds,
char const* comment, char const* comment,
bool is_private, bool is_private,
bool anonymize,
char const* source); char const* source);

View File

@ -626,6 +626,7 @@ NSMutableSet* creatorWindowControllerSet = nil;
0, 0,
self.fCommentView.string.UTF8String, self.fCommentView.string.UTF8String,
self.fPrivateCheck.state == NSControlStateValueOn, self.fPrivateCheck.state == NSControlStateValueOn,
NO,
self.fSource.stringValue.UTF8String); self.fSource.stringValue.UTF8String);
tr_free(trackerInfo); tr_free(trackerInfo);

View File

@ -193,6 +193,7 @@ void MakeDialog::makeTorrent()
0, 0,
comment.isEmpty() ? nullptr : comment.toUtf8().constData(), comment.isEmpty() ? nullptr : comment.toUtf8().constData(),
ui_.privateCheck->isChecked(), ui_.privateCheck->isChecked(),
false,
source.isNull() ? nullptr : source.toUtf8().constData()); source.isNull() ? nullptr : source.toUtf8().constData());
// pop up the dialog // pop up the dialog

View File

@ -42,6 +42,7 @@ protected:
size_t const payloadSize, size_t const payloadSize,
char const* comment, char const* comment,
bool isPrivate, bool isPrivate,
bool anonymize,
std::string_view source) std::string_view source)
{ {
@ -69,8 +70,10 @@ protected:
webseedCount, webseedCount,
comment, comment,
isPrivate, isPrivate,
anonymize,
std::string(source).c_str()); std::string(source).c_str());
EXPECT_EQ(isPrivate, builder->isPrivate); EXPECT_EQ(isPrivate, builder->isPrivate);
EXPECT_EQ(anonymize, builder->anonymize);
EXPECT_EQ(torrent_file, builder->outputFile); EXPECT_EQ(torrent_file, builder->outputFile);
EXPECT_STREQ(comment, builder->comment); EXPECT_STREQ(comment, builder->comment);
EXPECT_EQ(source, builder->source); EXPECT_EQ(source, builder->source);
@ -110,6 +113,7 @@ protected:
size_t const payload_count, size_t const payload_count,
char const* comment, char const* comment,
bool const is_private, bool const is_private,
bool const anonymize,
char const* source) char const* source)
{ {
// create the top temp directory // create the top temp directory
@ -158,8 +162,10 @@ protected:
webseed_count, webseed_count,
comment, comment,
is_private, is_private,
anonymize,
source); source);
EXPECT_EQ(is_private, builder->isPrivate); EXPECT_EQ(is_private, builder->isPrivate);
EXPECT_EQ(anonymize, builder->anonymize);
EXPECT_EQ(torrent_file, builder->outputFile); EXPECT_EQ(torrent_file, builder->outputFile);
EXPECT_STREQ(comment, builder->comment); EXPECT_STREQ(comment, builder->comment);
EXPECT_STREQ(source, builder->source); EXPECT_STREQ(source, builder->source);
@ -197,6 +203,7 @@ protected:
size_t const max_file_size, size_t const max_file_size,
char const* comment, char const* comment,
bool const is_private, bool const is_private,
bool const anonymize,
char const* source) char const* source)
{ {
// build random payloads // build random payloads
@ -223,6 +230,7 @@ protected:
payload_count, payload_count,
comment, comment,
is_private, is_private,
anonymize,
source); source);
// cleanup // cleanup
@ -249,6 +257,7 @@ TEST_F(MakemetaTest, singleFile)
auto const payload = std::string{ "Hello, World!\n" }; auto const payload = std::string{ "Hello, World!\n" };
char const* const comment = "This is the comment"; char const* const comment = "This is the comment";
bool const is_private = false; bool const is_private = false;
bool const anonymize = false;
auto metainfo = tr_torrent_metainfo{}; auto metainfo = tr_torrent_metainfo{};
testSingleFileImpl( testSingleFileImpl(
metainfo, metainfo,
@ -260,6 +269,7 @@ TEST_F(MakemetaTest, singleFile)
payload.size(), payload.size(),
comment, comment,
is_private, is_private,
anonymize,
"TESTME"sv); "TESTME"sv);
} }
@ -273,6 +283,7 @@ TEST_F(MakemetaTest, webseed)
auto const payload = std::string{ "Hello, World!\n" }; auto const payload = std::string{ "Hello, World!\n" };
char const* const comment = "This is the comment"; char const* const comment = "This is the comment";
bool const is_private = false; bool const is_private = false;
bool const anonymize = false;
auto metainfo = tr_torrent_metainfo{}; auto metainfo = tr_torrent_metainfo{};
testSingleFileImpl( testSingleFileImpl(
metainfo, metainfo,
@ -284,6 +295,7 @@ TEST_F(MakemetaTest, webseed)
payload.size(), payload.size(),
comment, comment,
is_private, is_private,
anonymize,
"TESTME"sv); "TESTME"sv);
} }
@ -300,6 +312,7 @@ TEST_F(MakemetaTest, singleFileDifferentSourceFlags)
auto const payload = std::string{ "Hello, World!\n" }; auto const payload = std::string{ "Hello, World!\n" };
char const* const comment = "This is the comment"; char const* const comment = "This is the comment";
bool const is_private = false; bool const is_private = false;
bool const anonymize = false;
auto metainfo_foobar = tr_torrent_metainfo{}; auto metainfo_foobar = tr_torrent_metainfo{};
testSingleFileImpl( testSingleFileImpl(
@ -312,6 +325,7 @@ TEST_F(MakemetaTest, singleFileDifferentSourceFlags)
payload.size(), payload.size(),
comment, comment,
is_private, is_private,
anonymize,
"FOOBAR"sv); "FOOBAR"sv);
auto metainfo_testme = tr_torrent_metainfo{}; auto metainfo_testme = tr_torrent_metainfo{};
@ -325,6 +339,7 @@ TEST_F(MakemetaTest, singleFileDifferentSourceFlags)
payload.size(), payload.size(),
comment, comment,
is_private, is_private,
anonymize,
"TESTME"sv); "TESTME"sv);
EXPECT_NE(metainfo_foobar.infoHash(), metainfo_testme.infoHash()); EXPECT_NE(metainfo_foobar.infoHash(), metainfo_testme.infoHash());
@ -345,6 +360,7 @@ TEST_F(MakemetaTest, singleDirectoryRandomPayload)
++tracker_count; ++tracker_count;
char const* const comment = "This is the comment"; char const* const comment = "This is the comment";
bool const is_private = false; bool const is_private = false;
bool const anonymize = false;
char const* const source = "TESTME"; char const* const source = "TESTME";
for (size_t i = 0; i < 10; ++i) for (size_t i = 0; i < 10; ++i)
@ -358,6 +374,7 @@ TEST_F(MakemetaTest, singleDirectoryRandomPayload)
DefaultMaxFileSize, DefaultMaxFileSize,
comment, comment,
is_private, is_private,
anonymize,
source); source);
} }
} }

View File

@ -35,7 +35,7 @@ char constexpr Usage[] = "Usage: transmission-create [options] <file|directory>"
uint32_t constexpr KiB = 1024; uint32_t constexpr KiB = 1024;
auto constexpr Options = std::array<tr_option, 9>{ auto constexpr Options = std::array<tr_option, 10>{
{ { 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", false, nullptr }, { { 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", false, nullptr },
{ 'r', "source", "Set the source for private trackers", "r", true, "<source>" }, { 'r', "source", "Set the source for private trackers", "r", true, "<source>" },
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", true, "<file>" }, { 'o', "outfile", "Save the generated .torrent to this filename", "o", true, "<file>" },
@ -43,6 +43,7 @@ auto constexpr Options = std::array<tr_option, 9>{
{ 'c', "comment", "Add a comment", "c", true, "<comment>" }, { 'c', "comment", "Add a comment", "c", true, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", true, "<url>" }, { 't', "tracker", "Add a tracker's announce URL", "t", true, "<url>" },
{ 'w', "webseed", "Add a webseed URL", "w", true, "<url>" }, { 'w', "webseed", "Add a webseed URL", "w", true, "<url>" },
{ 'x', "anonymize", "Omit \"Creation date\" and \"Created by\" info", nullptr, false, nullptr },
{ 'V', "version", "Show version number and exit", "V", false, nullptr }, { 'V', "version", "Show version number and exit", "V", false, nullptr },
{ 0, nullptr, nullptr, nullptr, false, nullptr } } { 0, nullptr, nullptr, nullptr, false, nullptr } }
}; };
@ -58,6 +59,7 @@ struct app_options
uint32_t piecesize_kib = 0; uint32_t piecesize_kib = 0;
bool is_private = false; bool is_private = false;
bool show_version = false; bool show_version = false;
bool anonymize = false;
}; };
int parseCommandLine(app_options& options, int argc, char const* const* argv) int parseCommandLine(app_options& options, int argc, char const* const* argv)
@ -111,6 +113,10 @@ int parseCommandLine(app_options& options, int argc, char const* const* argv)
options.source = optarg; options.source = optarg;
break; break;
case 'x':
options.anonymize = true;
break;
case TR_OPT_UNK: case TR_OPT_UNK:
options.infile = optarg; options.infile = optarg;
break; break;
@ -241,6 +247,7 @@ int tr_main(int argc, char* argv[])
static_cast<int>(std::size(options.webseeds)), static_cast<int>(std::size(options.webseeds)),
options.comment, options.comment,
options.is_private, options.is_private,
options.anonymize,
options.source); options.source);
uint32_t last = UINT32_MAX; uint32_t last = UINT32_MAX;

View File

@ -38,6 +38,10 @@ Add a tracker's
to the .torrent. Most torrents will have at least one to the .torrent. Most torrents will have at least one
.Ar announce URL. .Ar announce URL.
To add more than one, use this option multiple times. To add more than one, use this option multiple times.
.It Fl -anonymize
Omit the optional "created by" and "created date" keys from the
generated torrent which otherwise default to the Transmission version
number and the current date.
.El .El
.Sh AUTHORS .Sh AUTHORS
.An -nosplit .An -nosplit