mirror of
https://github.com/debauchee/barrier.git
synced 2026-05-10 00:11:43 +08:00
native unix http get for premium auth
This commit is contained in:
@@ -16,9 +16,61 @@
|
||||
*/
|
||||
|
||||
#include "CArchInternetUnix.h"
|
||||
#include "Version.h"
|
||||
#include "XArch.h"
|
||||
#include "CLog.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <curl/curl.h>
|
||||
|
||||
static size_t
|
||||
curlWriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
((std::string*)userp)->append((char*)contents, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
CString
|
||||
CArchInternetUnix::get(const CString& url)
|
||||
{
|
||||
return "Not implemented";
|
||||
std::string result;
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
try {
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl == NULL) {
|
||||
throw XArch("CURL init failed.");
|
||||
}
|
||||
|
||||
try {
|
||||
std::stringstream userAgent;
|
||||
userAgent << "Synergy ";
|
||||
userAgent << kVersion;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.str().c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &result);
|
||||
|
||||
CURLcode code = curl_easy_perform(curl);
|
||||
if (code != CURLE_OK) {
|
||||
LOG((CLOG_ERR "curl perform error: %s", curl_easy_strerror(code)));
|
||||
throw XArch("CURL perform failed.");
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
catch (...) {
|
||||
curl_easy_cleanup(curl);
|
||||
throw;
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
}
|
||||
catch (...) {
|
||||
curl_global_cleanup();
|
||||
throw;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user