diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-02-07 23:54:07 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-05-06 21:30:22 +0100 |
| commit | ed850c9ce413ef8dd9fbff53a2d2d6788a162e0c (patch) | |
| tree | a40b5bcc918125099b56d9fcc7e35cd0cfad1544 /src/lib/internet.cc | |
| parent | aeff661ee81b9a7674c6f63b3a1ff145bb6593a4 (diff) | |
Support download of certificates from Qube (#1460).
Diffstat (limited to 'src/lib/internet.cc')
| -rw-r--r-- | src/lib/internet.cc | 40 |
1 files changed, 40 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) |
