|
|
|
@ -6,9 +6,14 @@
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
struct progress {
|
|
|
|
|
char* privat;
|
|
|
|
|
size_t size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void svg_begin(double width, double height) {
|
|
|
|
|
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
|
|
|
@ -97,15 +102,31 @@ size_t write_header(char* buffer, size_t size, size_t nitems, void* userdata)
|
|
|
|
|
return size * nitems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static size_t progress_callback(void* clientp,
|
|
|
|
|
double dltotal,
|
|
|
|
|
double dlnow,
|
|
|
|
|
double ultotal,
|
|
|
|
|
double ulnow)
|
|
|
|
|
{
|
|
|
|
|
struct progress* memory = (progress*)clientp;
|
|
|
|
|
cerr << "Progress: " << (dlnow / dltotal) * 100 << "%\n";
|
|
|
|
|
//cerr << "Progress: " << memory->privat << "\n";
|
|
|
|
|
return 0; /* all is good */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Input download(const string& address) {
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
|
|
|
|
|
struct progress data;
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
if (curl) {
|
|
|
|
|
CURLcode res;
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &data);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_header);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADERDATA, NULL);
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|