From b0549601a56a805f163a63f3d46e8845ec7e0795 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Mon, 16 Nov 2020 08:37:53 +0100 Subject: [PATCH] helpers.h/cpp: add default timeout parameter with value 1 For flexible usage of timeout in related downloadUrl methods if required. Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/7cabce4b80e50ab481613e2da990f54fcb3bc3c8 Author: Thilo Graf Date: 2020-11-16 (Mon, 16 Nov 2020) --- src/system/helpers.cpp | 8 ++++---- src/system/helpers.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 185ef38a3..026fdcae9 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -1802,18 +1802,18 @@ std::string randomFile(std::string suffix, std::string directory, unsigned int l return directory + "/" + randomString(length) + "." + suffix; } -std::string downloadUrlToRandomFile(std::string url, std::string directory, unsigned int length) +std::string downloadUrlToRandomFile(std::string url, std::string directory, unsigned int length, unsigned int timeout) { if (strstr(url.c_str(), "://")) { std::string file = randomFile(url.substr(url.find_last_of(".") + 1), directory, length); - if (downloadUrl(url, file, " ", 1)) + if (downloadUrl(url, file, " ", timeout)) return file; } return url; } -std::string downloadUrlToLogo(std::string url, std::string directory, t_channel_id channel_id) +std::string downloadUrlToLogo(std::string url, std::string directory, t_channel_id channel_id, unsigned int timeout) { if (channel_id == 0) @@ -1829,7 +1829,7 @@ std::string downloadUrlToLogo(std::string url, std::string directory, t_channel_ std::string file = directory + "/" + strChnId + url.substr(url.find_last_of(".")); if (file_exists(file)) return file; - if (downloadUrl(url, file, " ", 1)) + if (downloadUrl(url, file, " ", timeout)) return file; } return url; diff --git a/src/system/helpers.h b/src/system/helpers.h index 75e3e4107..7b0bb8213 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -173,8 +173,8 @@ bool utf8_check_is_valid(const std::string &str); std::string randomString(unsigned int length = 10); std::string randomFile(std::string suffix = "tmp", std::string directory = "/tmp", unsigned int length = 10); -std::string downloadUrlToRandomFile(std::string url, std::string directory = "/tmp", unsigned int length = 10); -std::string downloadUrlToLogo(std::string url, std::string directory = "/tmp", t_channel_id channel_id = 0); +std::string downloadUrlToRandomFile(std::string url, std::string directory = "/tmp", unsigned int length = 10, unsigned int timeout = 1); +std::string downloadUrlToLogo(std::string url, std::string directory = "/tmp", t_channel_id channel_id = 0, unsigned int timeout = 1); // curl struct MemoryStruct {