diff --git a/CMakeLists.txt b/CMakeLists.txt index f27a5abe..d80fd1c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,7 @@ if (UNIX) find_library(lib_ApplicationServices ApplicationServices) find_library(lib_Foundation Foundation) find_library(lib_Carbon Carbon) + find_library(lib_CURL CURL) list(APPEND libs ${lib_ScreenSaver} @@ -170,6 +171,7 @@ if (UNIX) ${lib_ApplicationServices} ${lib_Foundation} ${lib_Carbon} + ${lib_CURL} ) else() diff --git a/src/lib/arch/CArchInternetUnix.cpp b/src/lib/arch/CArchInternetUnix.cpp index 3cb9b2a9..93a69c37 100644 --- a/src/lib/arch/CArchInternetUnix.cpp +++ b/src/lib/arch/CArchInternetUnix.cpp @@ -16,9 +16,61 @@ */ #include "CArchInternetUnix.h" +#include "Version.h" +#include "XArch.h" +#include "CLog.h" + +#include +#include + +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; } diff --git a/src/test/integtests/CMakeLists.txt b/src/test/integtests/CMakeLists.txt index 8e6e4569..714709f8 100644 --- a/src/test/integtests/CMakeLists.txt +++ b/src/test/integtests/CMakeLists.txt @@ -26,11 +26,22 @@ set(src CTestEventQueue.cpp ) +# arch +if (WIN32) + list(APPEND src + arch/CArchInternetWindowsTests.cpp + ) +elseif (UNIX) + list(APPEND src + arch/CArchInternetUnixTests.cpp + ) +endif() + +# platform if (WIN32) list(APPEND src platform/CMSWindowsClipboardTests.cpp platform/CMSWindowsKeyStateTests.cpp - arch/CArchInternetWindowsTests.cpp ) elseif (APPLE) list(APPEND src @@ -38,7 +49,6 @@ elseif (APPLE) platform/COSXKeyStateTests.cpp platform/COSXScreenTests.cpp ) - elseif (UNIX) list(APPEND src platform/CXWindowsClipboardTests.cpp diff --git a/src/test/integtests/arch/CArchInternetUnixTests.cpp b/src/test/integtests/arch/CArchInternetUnixTests.cpp new file mode 100644 index 00000000..be4d0795 --- /dev/null +++ b/src/test/integtests/arch/CArchInternetUnixTests.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 . + */ + +#include +#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); +}