aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-10-15 19:57:24 +0200
committerdec05eba <dec05eba@protonmail.com>2019-10-15 19:57:27 +0200
commit56acc142c6ef9a65147acdea6737acbfaeb7eca4 (patch)
tree1b9a955bec7ed74c16e3cf663b9acca5aef8c19e /src/plugins
parent2ba21aa9aa91b975fe0c8be630dde05d0d9b5366 (diff)
Add tor support
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Plugin.cpp35
1 files changed, 19 insertions, 16 deletions
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<CommandArg> &additional_args) {
- sf::Clock timer;
- std::vector<const char*> 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<CommandArg> &additional_args) {
+ sf::Clock timer;
+ std::vector<const char*> 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