native unix http get for premium auth
This commit is contained in:
parent
30f176b25e
commit
5ca1c17549
|
@ -163,6 +163,7 @@ if (UNIX)
|
||||||
find_library(lib_ApplicationServices ApplicationServices)
|
find_library(lib_ApplicationServices ApplicationServices)
|
||||||
find_library(lib_Foundation Foundation)
|
find_library(lib_Foundation Foundation)
|
||||||
find_library(lib_Carbon Carbon)
|
find_library(lib_Carbon Carbon)
|
||||||
|
find_library(lib_CURL CURL)
|
||||||
|
|
||||||
list(APPEND libs
|
list(APPEND libs
|
||||||
${lib_ScreenSaver}
|
${lib_ScreenSaver}
|
||||||
|
@ -170,6 +171,7 @@ if (UNIX)
|
||||||
${lib_ApplicationServices}
|
${lib_ApplicationServices}
|
||||||
${lib_Foundation}
|
${lib_Foundation}
|
||||||
${lib_Carbon}
|
${lib_Carbon}
|
||||||
|
${lib_CURL}
|
||||||
)
|
)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
|
|
|
@ -16,9 +16,61 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CArchInternetUnix.h"
|
#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
|
CString
|
||||||
CArchInternetUnix::get(const CString& url)
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,22 @@ set(src
|
||||||
CTestEventQueue.cpp
|
CTestEventQueue.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# arch
|
||||||
|
if (WIN32)
|
||||||
|
list(APPEND src
|
||||||
|
arch/CArchInternetWindowsTests.cpp
|
||||||
|
)
|
||||||
|
elseif (UNIX)
|
||||||
|
list(APPEND src
|
||||||
|
arch/CArchInternetUnixTests.cpp
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# platform
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
list(APPEND src
|
list(APPEND src
|
||||||
platform/CMSWindowsClipboardTests.cpp
|
platform/CMSWindowsClipboardTests.cpp
|
||||||
platform/CMSWindowsKeyStateTests.cpp
|
platform/CMSWindowsKeyStateTests.cpp
|
||||||
arch/CArchInternetWindowsTests.cpp
|
|
||||||
)
|
)
|
||||||
elseif (APPLE)
|
elseif (APPLE)
|
||||||
list(APPEND src
|
list(APPEND src
|
||||||
|
@ -38,7 +49,6 @@ elseif (APPLE)
|
||||||
platform/COSXKeyStateTests.cpp
|
platform/COSXKeyStateTests.cpp
|
||||||
platform/COSXScreenTests.cpp
|
platform/COSXScreenTests.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
elseif (UNIX)
|
elseif (UNIX)
|
||||||
list(APPEND src
|
list(APPEND src
|
||||||
platform/CXWindowsClipboardTests.cpp
|
platform/CXWindowsClipboardTests.cpp
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2014 Bolton Software Ltd.
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file COPYING that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include "CArchInternetUnix.h"
|
||||||
|
|
||||||
|
#define TEST_URL "https://synergy-foss.org/tests/?testString"
|
||||||
|
//#define TEST_URL "http://localhost/synergy/tests/?testString"
|
||||||
|
|
||||||
|
TEST(CArchInternetWindowsTests, openWebPage)
|
||||||
|
{
|
||||||
|
CArchInternetUnix internet;
|
||||||
|
CString result = internet.get(TEST_URL);
|
||||||
|
ASSERT_EQ("Hello world!", result);
|
||||||
|
}
|
Loading…
Reference in New Issue