blob: ce42fb40f3290b0b08eb67a8a6d5f302506b0d8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#pragma once
#include "util.hpp"
#include <connection_fwd.h>
#include <curl/curl.h>
#include <memory>
#include <stdexcept>
#include <string>
namespace WebStat {
class CurlError : public std::runtime_error {
public:
explicit CurlError(CURLcode code, const char * msg) : std::runtime_error {msg}, code(code) { }
CURLcode code;
};
using CurlPtr = std::unique_ptr<CURL, DeleteWith<&curl_easy_cleanup>>;
using CurlMimePtr = std::unique_ptr<curl_mime, DeleteWith<&curl_mime_free>>;
using CurlErrorBuf = std::array<char, CURL_ERROR_SIZE>;
using CurlMultiPtr = std::unique_ptr<CURLM, DeleteWith<&curl_multi_cleanup>>;
class CurlOperation {
public:
CurlOperation();
virtual ~CurlOperation() = default;
SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(CurlOperation);
void addForm(const char * name, std::string_view data);
virtual void whenComplete(DB::Connection *) const = 0;
virtual void onError(DB::Connection *) const;
CurlPtr hnd;
CurlMimePtr mime;
CurlErrorBuf err;
std::string result;
};
}
|