native unix http get for premium auth

This commit is contained in:
Nick Bolton
2014-02-05 14:29:50 +00:00
parent 30f176b25e
commit 5ca1c17549
4 changed files with 96 additions and 3 deletions

View File

@@ -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;
}