From 56acc142c6ef9a65147acdea6737acbfaeb7eca4 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 15 Oct 2019 19:57:24 +0200 Subject: Add tor support --- src/plugins/Plugin.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'src/plugins/Plugin.cpp') diff --git a/src/plugins/Plugin.cpp b/src/plugins/Plugin.cpp index c56ff67..d1490d5 100644 --- a/src/plugins/Plugin.cpp +++ b/src/plugins/Plugin.cpp @@ -28,22 +28,6 @@ namespace QuickMedia { return {}; } - DownloadResult download_to_string(const std::string &url, std::string &result, const std::vector &additional_args) { - sf::Clock timer; - std::vector args = { "curl", "-f", "-H", "Accept-Language: en-US,en;q=0.5", "--compressed", "-s", "-L" }; - for(const CommandArg &arg : additional_args) { - args.push_back(arg.option.c_str()); - args.push_back(arg.value.c_str()); - } - args.push_back("--"); - args.push_back(url.c_str()); - args.push_back(nullptr); - if(exec_program(args.data(), accumulate_string, &result) != 0) - return DownloadResult::NET_ERR; - fprintf(stderr, "Download duration for %s: %d ms\n", url.c_str(), timer.getElapsedTime().asMilliseconds()); - return DownloadResult::OK; - } - static bool is_whitespace(char c) { return c == ' ' || c == '\n' || c == '\t' || c == '\v'; } @@ -112,4 +96,23 @@ namespace QuickMedia { return result.str(); } + + DownloadResult Plugin::download_to_string(const std::string &url, std::string &result, const std::vector &additional_args) { + sf::Clock timer; + std::vector args; + if(use_tor) + args.push_back("torsocks"); + args.insert(args.end(), { "curl", "-f", "-H", "Accept-Language: en-US,en;q=0.5", "--compressed", "-s", "-L" }); + for(const CommandArg &arg : additional_args) { + args.push_back(arg.option.c_str()); + args.push_back(arg.value.c_str()); + } + args.push_back("--"); + args.push_back(url.c_str()); + args.push_back(nullptr); + if(exec_program(args.data(), accumulate_string, &result) != 0) + return DownloadResult::NET_ERR; + fprintf(stderr, "Download duration for %s: %d ms\n", url.c_str(), timer.getElapsedTime().asMilliseconds()); + return DownloadResult::OK; + } } \ No newline at end of file -- cgit v1.2.3