emailQt/CurlHandler.hpp

49 lines
1.1 KiB
C++
Executable File

#pragma once
#include <cstdlib>
#include <functional>
#include <memory>
#include <string>
#include <thread>
#include <vector>
#include <QObject>
#include <curl/curl.h>
#include "ParametersProvider.hpp"
constexpr long curlTimeoutSeconds{5};
// View RFC 3501 and RFC 2192 for more details
size_t cb(char *data, size_t size, size_t numberOfMembers, void *userdata);
class CurlHandler : public QObject {
Q_OBJECT
public:
CurlHandler();
~CurlHandler();
void configure(const ParametersProvider::settings &sett);
std::vector<std::string> *fetch();
void query(std::string &c, size_t count);
void setupCurl(CURL *ptr, std::string &m, const std::string &ur) const;
signals:
void threadFinished(size_t threadId, int uid);
private:
std::string url;
std::unique_ptr<CURL, decltype(&curl_easy_cleanup)> initialCurl;
CURLcode initialRes;
std::string initialChunk;
std::vector<std::string> decodedMessages;
std::vector<std::string> messagesId;
std::vector<std::thread> v;
ParametersProvider::settings setts;
};