mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-26 22:03:24 +08:00
native windows http get for premium auth
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
# include "CArchTaskBarWindows.h"
|
||||
# include "CArchTimeWindows.h"
|
||||
# include "CArchPluginWindows.h"
|
||||
# include "CArchInternetWindows.h"
|
||||
#elif SYSAPI_UNIX
|
||||
# include "CArchConsoleUnix.h"
|
||||
# include "CArchDaemonUnix.h"
|
||||
@@ -67,6 +68,7 @@
|
||||
# include "CArchTaskBarXWindows.h"
|
||||
# include "CArchTimeUnix.h"
|
||||
# include "CArchPluginUnix.h"
|
||||
# include "CArchInternetUnix.h"
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@@ -119,10 +121,12 @@ public:
|
||||
static CArch* getInstance();
|
||||
|
||||
ARCH_PLUGIN& plugin() const { return (ARCH_PLUGIN&)m_plugin; }
|
||||
ARCH_INTERNET& internet() const { return (ARCH_INTERNET&)m_internet; }
|
||||
|
||||
private:
|
||||
static CArch* s_instance;
|
||||
ARCH_PLUGIN m_plugin;
|
||||
ARCH_INTERNET m_internet;
|
||||
};
|
||||
|
||||
//! Convenience object to lock/unlock an arch mutex
|
||||
|
||||
24
src/lib/arch/CArchInternetUnix.cpp
Normal file
24
src/lib/arch/CArchInternetUnix.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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 "CArchInternetUnix.h"
|
||||
|
||||
CString
|
||||
CArchInternetUnix::get(const CString& url)
|
||||
{
|
||||
return "Not implemented";
|
||||
}
|
||||
27
src/lib/arch/CArchInternetUnix.h
Normal file
27
src/lib/arch/CArchInternetUnix.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARCH_INTERNET CArchInternetUnix
|
||||
|
||||
#include "CString.h"
|
||||
|
||||
class CArchInternetUnix {
|
||||
public:
|
||||
CString get(const CString& url);
|
||||
};
|
||||
119
src/lib/arch/CArchInternetWindows.cpp
Normal file
119
src/lib/arch/CArchInternetWindows.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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 "CArchInternetWindows.h"
|
||||
#include "CArch.h"
|
||||
#include "Version.h"
|
||||
#include "XArchWindows.h"
|
||||
#include <sstream>
|
||||
#include <Wininet.h>
|
||||
|
||||
CString
|
||||
CArchInternetWindows::get(const CString& url)
|
||||
{
|
||||
std::stringstream userAgent;
|
||||
userAgent << "Synergy ";
|
||||
userAgent << kVersion;
|
||||
|
||||
HINTERNET session = InternetOpen(
|
||||
userAgent.str().c_str(),
|
||||
INTERNET_OPEN_TYPE_PRECONFIG,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
if (session == NULL) {
|
||||
throw XArch(new XArchEvalWindows());
|
||||
}
|
||||
|
||||
// InternetCrackUrl didn't seem to work too well, this isn't quite
|
||||
// as robust, but it should do just fine for basic URLs.
|
||||
size_t schemeEnd = url.find("://");
|
||||
size_t hostEnd = url.find('/', schemeEnd + 3);
|
||||
CString scheme = url.substr(0, schemeEnd);
|
||||
CString host = url.substr(schemeEnd + 3, hostEnd - (schemeEnd + 3));
|
||||
CString path = url.substr(hostEnd);
|
||||
|
||||
INTERNET_PORT port = INTERNET_DEFAULT_HTTP_PORT;
|
||||
DWORD requestFlags = 0;
|
||||
|
||||
if (scheme.find("https") != CString::npos) {
|
||||
port = INTERNET_DEFAULT_HTTPS_PORT;
|
||||
requestFlags = INTERNET_FLAG_SECURE;
|
||||
}
|
||||
|
||||
HINTERNET connect = InternetConnect(
|
||||
session, host.c_str(), port, NULL, NULL,
|
||||
INTERNET_SERVICE_HTTP, NULL, NULL);
|
||||
|
||||
if (connect == NULL) {
|
||||
throw XArch(new XArchEvalWindows());
|
||||
}
|
||||
|
||||
HINTERNET request = HttpOpenRequest(
|
||||
connect, "GET", path.c_str(),
|
||||
HTTP_VERSION, NULL,
|
||||
NULL, requestFlags, NULL);
|
||||
|
||||
if (request == NULL) {
|
||||
throw XArch(new XArchEvalWindows());
|
||||
}
|
||||
|
||||
CString headers("Content-Type: text/html");
|
||||
if (!HttpSendRequest(request, headers.c_str(), (DWORD)headers.length(), NULL, NULL)) {
|
||||
int error = GetLastError();
|
||||
throw XArch(new XArchEvalWindows());
|
||||
}
|
||||
|
||||
std::stringstream result;
|
||||
CHAR buffer[1025];
|
||||
DWORD read = 0;
|
||||
|
||||
while (InternetReadFile(request, buffer, sizeof(buffer) - 1, &read) && (read != 0)) {
|
||||
buffer[read] = 0;
|
||||
result << buffer;
|
||||
read = 0;
|
||||
}
|
||||
|
||||
InternetCloseHandle(request);
|
||||
InternetCloseHandle(connect);
|
||||
InternetCloseHandle(session);
|
||||
|
||||
return result.str();
|
||||
}
|
||||
/*
|
||||
* 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 "CArchInternetWindows.h"
|
||||
|
||||
CString
|
||||
CArchInternetWindows::get(const CString& url)
|
||||
{
|
||||
return "Hello bob!";
|
||||
}
|
||||
54
src/lib/arch/CArchInternetWindows.h
Normal file
54
src/lib/arch/CArchInternetWindows.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARCH_INTERNET CArchInternetWindows
|
||||
|
||||
#include "CString.h"
|
||||
|
||||
class CArchInternetWindows {
|
||||
public:
|
||||
CString get(const CString& url);
|
||||
};
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARCH_INTERNET CArchInternetWindows
|
||||
|
||||
#include "CString.h"
|
||||
|
||||
class CArchInternetWindows {
|
||||
public:
|
||||
CString get(const CString& url);
|
||||
};
|
||||
@@ -43,6 +43,7 @@ if (WIN32)
|
||||
XArch.h
|
||||
IArchPlugin.h
|
||||
CArchPluginWindows.h
|
||||
CArchInternetWindows.h
|
||||
)
|
||||
|
||||
list(APPEND src
|
||||
@@ -61,6 +62,7 @@ if (WIN32)
|
||||
CArchTimeWindows.cpp
|
||||
XArchWindows.cpp
|
||||
CArchPluginWindows.cpp
|
||||
CArchInternetWindows.cpp
|
||||
)
|
||||
|
||||
elseif (UNIX)
|
||||
@@ -80,6 +82,7 @@ elseif (UNIX)
|
||||
XArchUnix.cpp
|
||||
CArchDaemonNone.cpp
|
||||
CArchPluginUnix.cpp
|
||||
CArchInternetUnix.cpp
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user