From c3f1aafb9645429c8b702c9e2ea324a3c52083fe Mon Sep 17 00:00:00 2001 From: razaq Date: Wed, 27 Oct 2021 20:25:09 +0200 Subject: [PATCH] add TR_TORRENT_TRACKERS env variable to script call (#2053) * add TR_TORRENT_TRACKERS env variable to script call --- libtransmission/torrent.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index 75cfff9e8..1b58925e3 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -2090,6 +2090,28 @@ static std::string buildLabelsString(tr_torrent const* tor) return buf.str(); } +static std::string buildTrackersString(tr_torrent const* tor) +{ + auto buf = std::stringstream{}; + + int n = 0; + tr_tracker_stat* stats = tr_torrentTrackers(tor, &n); + for (int i = 0; i < n;) + { + tr_tracker_stat const* s = &stats[i]; + + buf << s->host; + + if (++i < n) + { + buf << ','; + } + } + tr_torrentTrackersFree(stats, n); + + return buf.str(); +} + static void torrentCallScript(tr_torrent const* tor, char const* script) { if (tr_str_is_empty(script)) @@ -2116,8 +2138,9 @@ static void torrentCallScript(tr_torrent const* tor, char const* script) tr_strdup_printf("TR_TORRENT_DIR=%s", torrent_dir), tr_strdup_printf("TR_TORRENT_HASH=%s", tor->info.hashString), tr_strdup_printf("TR_TORRENT_ID=%d", tr_torrentId(tor)), - tr_strdup_printf("TR_TORRENT_NAME=%s", tr_torrentName(tor)), tr_strdup_printf("TR_TORRENT_LABELS=%s", buildLabelsString(tor).c_str()), + tr_strdup_printf("TR_TORRENT_NAME=%s", tr_torrentName(tor)), + tr_strdup_printf("TR_TORRENT_TRACKERS=%s", buildTrackersString(tor).c_str()), nullptr, };