diff options
Diffstat (limited to 'src/libs/qlicenseservice/httpclient.h')
-rw-r--r-- | src/libs/qlicenseservice/httpclient.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/libs/qlicenseservice/httpclient.h b/src/libs/qlicenseservice/httpclient.h new file mode 100644 index 0000000..a587c67 --- /dev/null +++ b/src/libs/qlicenseservice/httpclient.h @@ -0,0 +1,56 @@ +/* Copyright (C) 2022 The Qt Company Ltd. + * + * SPDX-License-Identifier: GPL-3.0-only WITH Qt-GPL-exception-1.0 +*/ +#pragma once + +#include <iostream> +#include <sstream> +#include <map> + +#define SERVER_CONN_TIMEOUT 10 + +#if _WIN32 + #include "curl/curl.h" +#else + #include <sys/types.h> + #include <sys/socket.h> + #include <netinet/in.h> + #include <arpa/inet.h> + #include <unistd.h> + #include <netdb.h> + #include <curl/curl.h> +#endif + +struct HttpRequest { + std::string payload; + std::string url; + std::string reply; + curl_slist *headers = nullptr; +}; + +/********************* + HttpClient class +*/ + +class HttpClient +{ +public: + explicit HttpClient(const std::string &serverUrl, + const std::string &requestAccessPoint, + const std::string &permanentccessPoint, + const std::string &versionAccessPoint); + ~HttpClient() {} + + int sendRequest(std::string &reply, const std::string &payload, + const std::string &server, const std::string &authKey=""); + std::string error() { return m_lastError; } +private: + std::string m_serverUrl; + std::string m_requestAccessPoint; + std::string m_permanentAccessPoint; + std::string m_versionAccessPoint; + std::string m_userAgent = "License daemon / "; + std::string m_lastError; + int doRequest(CURL *curl, HttpRequest &request); +}; |