diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-02-07 23:54:07 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-05-10 23:43:42 +0100 |
| commit | 35a7379dda587add9d94dc4f710414a23976d6e7 (patch) | |
| tree | 523fccc8981a454001e0dac7689492ce053c5075 /src/lib | |
| parent | b7e546d9685c0a3304faa48e95516915d811ec5c (diff) | |
Support download of certificates from Qube (#1460).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/internet.cc | 40 | ||||
| -rw-r--r-- | src/lib/internet.h | 1 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/lib/internet.cc b/src/lib/internet.cc index e0af49b66..b993117bb 100644 --- a/src/lib/internet.cc +++ b/src/lib/internet.cc @@ -39,6 +39,46 @@ using boost::optional; using boost::function; using boost::algorithm::trim; +static size_t +ls_url_data (void* buffer, size_t size, size_t nmemb, void* output) +{ + string* s = reinterpret_cast<string*>(output); + char* c = reinterpret_cast<char*>(buffer); + for (size_t i = 0; i < (size * nmemb); ++i) { + *s += c[i]; + } + return nmemb; +} + +list<string> +ls_url (string url) +{ + CURL* curl = curl_easy_init (); + curl_easy_setopt (curl, CURLOPT_URL, url.c_str()); + curl_easy_setopt (curl, CURLOPT_DIRLISTONLY, 1); + + string ls; + curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ls_url_data); + curl_easy_setopt (curl, CURLOPT_WRITEDATA, &ls); + CURLcode const cr = curl_easy_perform (curl); + + if (cr != CURLE_OK) { + return list<string>(); + } + + list<string> result; + result.push_back(""); + for (size_t i = 0; i < ls.size(); ++i) { + if (ls[i] == '\n') { + result.push_back(""); + } else { + result.back() += ls[i]; + } + } + + result.pop_back (); + return result; +} static size_t get_from_url_data (void* buffer, size_t size, size_t nmemb, void* stream) diff --git a/src/lib/internet.h b/src/lib/internet.h index 125533b5d..5f9a25e3b 100644 --- a/src/lib/internet.h +++ b/src/lib/internet.h @@ -27,3 +27,4 @@ class ScopedTemporary; boost::optional<std::string> get_from_url (std::string url, bool pasv, bool skip_pasv_ip, ScopedTemporary& temp); boost::optional<std::string> get_from_url (std::string url, bool pasv, bool skip_pasv_ip, boost::function<void (boost::filesystem::path)> load); boost::optional<std::string> get_from_zip_url (std::string url, std::string file, bool pasv, bool skip_pasv_ip, boost::function<void (boost::filesystem::path)> load); +std::list<std::string> ls_url (std::string url); |
