aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/qlicenseservice/httpclient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/qlicenseservice/httpclient.cpp')
-rw-r--r--src/libs/qlicenseservice/httpclient.cpp47
1 files changed, 17 insertions, 30 deletions
diff --git a/src/libs/qlicenseservice/httpclient.cpp b/src/libs/qlicenseservice/httpclient.cpp
index 7f5d1fc..8d07674 100644
--- a/src/libs/qlicenseservice/httpclient.cpp
+++ b/src/libs/qlicenseservice/httpclient.cpp
@@ -16,45 +16,34 @@ size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
return size * nmemb;
}
-HttpClient::HttpClient( const std::string &serverUrl,
- const std::string &requestAccessPoint,
- const std::string &permanentAccessPoint,
- const std::string &versionAccessPoint) :
- m_serverUrl(serverUrl),
- m_requestAccessPoint(requestAccessPoint),
- m_permanentAccessPoint(permanentAccessPoint),
- m_versionAccessPoint(versionAccessPoint)
+HttpClient::HttpClient(const std::string &serverUrl)
+ : m_serverUrl(serverUrl)
{
m_userAgent += DAEMON_VERSION;
}
-int HttpClient::sendRequest(std::string &reply, const std::string &payload,
- const std::string &server, const std::string &authKey)
+int HttpClient::sendAndReceive(std::string &reply, const std::string &payload,
+ const std::string &accessPoint, const std::string &server,
+ const std::string &authKey)
{
+ if (accessPoint.empty()) {
+ std::cout << "[HttpClient] error: No server endpoint given\n";
+ return 1;
+ }
HttpRequest request;
- m_lastError = "No errors";
-
- /* specify URL to POST */
- request.url = server;
- request.payload = payload;
+ // specify URL
if (server.empty()) {
// If server URL is not given as param, we use the default
request.url = m_serverUrl;
}
+ request.url += accessPoint;
+ request.payload = payload;
+
if (!authKey.empty()) {
- // normal request
- request.url += m_requestAccessPoint;
+ // Add auth key in headers
std::string auth = "Authorization: " + authKey;
request.headers = curl_slist_append(request.headers, auth.c_str());
- } else {
- if (payload.empty()) {
- // version query
- request.url += m_versionAccessPoint;
- } else {
- // permanentrequest
- request.url += m_permanentAccessPoint;
- }
}
std::string agent = "User-Agent: " + m_userAgent;
@@ -73,13 +62,11 @@ int HttpClient::sendRequest(std::string &reply, const std::string &payload,
retVal = 1;
}
} catch(...) {
- m_lastError = "Connection failed";
+ std::cout << "Connection failed\n";
retVal = 1;
}
if (retVal == 0) {
std::cout << request.reply.length() << " bytes retrieved from license server\n";
- } else {
- std::cout << m_lastError << std::endl;
}
/* cleanup curl stuff */
@@ -108,7 +95,7 @@ int HttpClient::doRequest(CURL *curl, HttpRequest &request)
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.payload.c_str());
}
else {
- curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
+ curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); // for server ping
}
if (curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL) != CURLE_OK) {
std::cout << "Warning! No SSL support available\n";
@@ -122,7 +109,7 @@ int HttpClient::doRequest(CURL *curl, HttpRequest &request)
// check for errors
if (res != CURLE_OK) {
std::cout << "HTTP transfer failed, URL: " << request.url << std::endl;
- m_lastError = curl_easy_strerror(res);
+ std::cout << curl_easy_strerror(res) << std::endl;
return 1;
}
request.reply = readBuffer;