mirror of
https://github.com/debauchee/barrier.git
synced 2026-07-16 11:01:53 +08:00
Merge changes from v1.8.5
This commit is contained in:
@@ -25,7 +25,7 @@ add_subdirectory(net)
|
||||
add_subdirectory(platform)
|
||||
add_subdirectory(server)
|
||||
add_subdirectory(synergy)
|
||||
|
||||
add_subdirectory(shared)
|
||||
|
||||
if (WIN32)
|
||||
add_subdirectory(synwinhk)
|
||||
|
||||
@@ -116,7 +116,6 @@ CurlFacade::urlEncode(const String& url)
|
||||
char* resultCStr = curl_easy_escape(m_curl, url.c_str(), 0);
|
||||
|
||||
if (resultCStr == NULL) {
|
||||
curl_free(resultCStr);
|
||||
throw XArch("CURL escape failed.");
|
||||
}
|
||||
|
||||
|
||||
@@ -41,14 +41,7 @@ public:
|
||||
*/
|
||||
virtual IDataSocket*
|
||||
accept() = 0;
|
||||
|
||||
//! Delete connection socket
|
||||
/*!
|
||||
This is used when the socket was created but not adopted by a client
|
||||
proxy.
|
||||
*/
|
||||
virtual void deleteSocket(void*) = 0;
|
||||
|
||||
|
||||
//@}
|
||||
|
||||
// ISocket overrides
|
||||
|
||||
@@ -93,14 +93,3 @@ SecureListenSocket::accept()
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SecureListenSocket::deleteSocket(void* socket)
|
||||
{
|
||||
SecureSocketSet::iterator it;
|
||||
it = m_secureSocketSet.find((IDataSocket*)socket);
|
||||
if (it != m_secureSocketSet.end()) {
|
||||
delete *it;
|
||||
m_secureSocketSet.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
// IListenSocket overrides
|
||||
virtual IDataSocket*
|
||||
accept();
|
||||
void deleteSocket(void*);
|
||||
|
||||
private:
|
||||
typedef std::set<IDataSocket*> SecureSocketSet;
|
||||
|
||||
@@ -43,7 +43,6 @@ public:
|
||||
// IListenSocket overrides
|
||||
virtual IDataSocket*
|
||||
accept();
|
||||
virtual void deleteSocket(void*) { }
|
||||
|
||||
protected:
|
||||
void setListeningJob();
|
||||
|
||||
@@ -19,7 +19,7 @@ if (WIN32)
|
||||
file(GLOB sources "MSWindows*.cpp")
|
||||
elseif (APPLE)
|
||||
file(GLOB headers "OSX*.h" "IOSX*.h")
|
||||
file(GLOB sources "OSX*.cpp" "IOSX*.cpp" "OSX*.m")
|
||||
file(GLOB sources "OSX*.cpp" "IOSX*.cpp" "OSX*.m" "OSX*.mm")
|
||||
elseif (UNIX)
|
||||
file(GLOB headers "XWindows*.h")
|
||||
file(GLOB sources "XWindows*.cpp")
|
||||
|
||||
@@ -122,7 +122,7 @@ OSXClipboard::add(EFormat format, const String & data)
|
||||
|
||||
PasteboardPutItemFlavor(
|
||||
m_pboard,
|
||||
(PasteboardItemID) 0,
|
||||
nullptr,
|
||||
flavorType,
|
||||
dataRef,
|
||||
kPasteboardFlavorNoFlags);
|
||||
|
||||
@@ -344,4 +344,6 @@ private:
|
||||
Mutex* m_carbonLoopMutex;
|
||||
CondVar<bool>* m_carbonLoopReady;
|
||||
#endif
|
||||
|
||||
class OSXScreenImpl* m_impl;
|
||||
};
|
||||
|
||||
@@ -101,7 +101,8 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso
|
||||
m_lastSingleClickYCursor(0),
|
||||
m_autoShowHideCursor(autoShowHideCursor),
|
||||
m_events(events),
|
||||
m_getDropTargetThread(NULL)
|
||||
m_getDropTargetThread(NULL),
|
||||
m_impl(NULL)
|
||||
{
|
||||
try {
|
||||
m_displayID = CGMainDisplayID();
|
||||
@@ -515,9 +516,7 @@ OSXScreen::fakeMouseButton(ButtonID id, bool press)
|
||||
// we define our own defaults.
|
||||
const double maxDiff = sqrt(2) + 0.0001;
|
||||
|
||||
|
||||
NXEventHandle handle = NXOpenEventStatus();
|
||||
double clickTime = NXClickTime(handle);
|
||||
double clickTime = [NSEvent doubleClickInterval];
|
||||
|
||||
// As long as the click is within the time window and distance window
|
||||
// increase clickState (double click, triple click, etc)
|
||||
@@ -35,6 +35,8 @@ endif()
|
||||
|
||||
add_library(server STATIC ${sources})
|
||||
|
||||
target_link_libraries(server shared)
|
||||
|
||||
if (UNIX)
|
||||
target_link_libraries(server synergy)
|
||||
endif()
|
||||
|
||||
@@ -106,12 +106,6 @@ ClientListener::setServer(Server* server)
|
||||
m_server = server;
|
||||
}
|
||||
|
||||
void
|
||||
ClientListener::deleteSocket(void* socket)
|
||||
{
|
||||
m_listen->deleteSocket(socket);
|
||||
}
|
||||
|
||||
ClientProxy*
|
||||
ClientListener::getNextClient()
|
||||
{
|
||||
@@ -213,10 +207,6 @@ ClientListener::handleUnknownClient(const Event&, void* vclient)
|
||||
}
|
||||
|
||||
delete unknownClient;
|
||||
|
||||
if (m_useSecureNetwork && !handshakeOk) {
|
||||
deleteSocket(socket);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -48,8 +48,6 @@ public:
|
||||
|
||||
//@}
|
||||
|
||||
void deleteSocket(void* socket);
|
||||
|
||||
//! @name accessors
|
||||
//@{
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2012-2016 Symless Ltd.
|
||||
* Copyright (C) 2002 Chris Schoeneman
|
||||
*
|
||||
*
|
||||
* 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 LICENSE 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
|
||||
@@ -45,11 +45,13 @@
|
||||
#include "base/Log.h"
|
||||
#include "base/TMethodEventJob.h"
|
||||
#include "common/stdexcept.h"
|
||||
#include "shared/SerialKey.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
|
||||
//
|
||||
// Server
|
||||
@@ -60,7 +62,7 @@ Server::Server(
|
||||
PrimaryClient* primaryClient,
|
||||
synergy::Screen* screen,
|
||||
IEventQueue* events,
|
||||
bool enableDragDrop) :
|
||||
ServerArgs const& args) :
|
||||
m_mock(false),
|
||||
m_primaryClient(primaryClient),
|
||||
m_active(primaryClient),
|
||||
@@ -91,10 +93,10 @@ Server::Server(
|
||||
m_sendFileThread(NULL),
|
||||
m_writeToDropDirThread(NULL),
|
||||
m_ignoreFileTransfer(false),
|
||||
m_enableDragDrop(enableDragDrop),
|
||||
m_enableClipboard(true),
|
||||
m_sendDragInfoThread(NULL),
|
||||
m_waitDragInfoThread(true)
|
||||
m_waitDragInfoThread(true),
|
||||
m_args(args)
|
||||
{
|
||||
// must have a primary client and it must have a canonical name
|
||||
assert(m_primaryClient != NULL);
|
||||
@@ -184,7 +186,7 @@ Server::Server(
|
||||
new TMethodEventJob<Server>(this,
|
||||
&Server::handleFakeInputEndEvent));
|
||||
|
||||
if (m_enableDragDrop) {
|
||||
if (m_args.m_enableDragDrop) {
|
||||
m_events->adoptHandler(m_events->forFile().fileChunkSending(),
|
||||
this,
|
||||
new TMethodEventJob<Server>(this,
|
||||
@@ -451,6 +453,13 @@ Server::switchScreen(BaseClientProxy* dst,
|
||||
SInt32 x, SInt32 y, bool forScreensaver)
|
||||
{
|
||||
assert(dst != NULL);
|
||||
|
||||
// if trial is expired, exit the process
|
||||
if (m_args.m_serial.isExpired(std::time(0))) {
|
||||
LOG((CLOG_ERR "trial has expired, aborting server"));
|
||||
exit(kExitSuccess);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
SInt32 dx, dy, dw, dh;
|
||||
@@ -534,7 +543,7 @@ Server::jumpToScreen(BaseClientProxy* newScreen)
|
||||
// get the last cursor position on the target screen
|
||||
SInt32 x, y;
|
||||
newScreen->getJumpCursorPos(x, y);
|
||||
|
||||
|
||||
switchScreen(newScreen, x, y, false);
|
||||
}
|
||||
|
||||
@@ -884,14 +893,14 @@ Server::isSwitchOkay(BaseClientProxy* newScreen,
|
||||
|
||||
if (!preventSwitch && (
|
||||
(this->m_switchNeedsShift && ((mods & KeyModifierShift) != KeyModifierShift)) ||
|
||||
(this->m_switchNeedsControl && ((mods & KeyModifierControl) != KeyModifierControl)) ||
|
||||
(this->m_switchNeedsControl && ((mods & KeyModifierControl) != KeyModifierControl)) ||
|
||||
(this->m_switchNeedsAlt && ((mods & KeyModifierAlt) != KeyModifierAlt))
|
||||
)) {
|
||||
LOG((CLOG_DEBUG1 "need modifiers to switch"));
|
||||
preventSwitch = true;
|
||||
stopSwitch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return !preventSwitch;
|
||||
}
|
||||
|
||||
@@ -1171,7 +1180,7 @@ Server::processOptions()
|
||||
}
|
||||
else if (id == kOptionClipboardSharing) {
|
||||
m_enableClipboard = (value != 0);
|
||||
|
||||
|
||||
if (m_enableClipboard == false) {
|
||||
LOG((CLOG_NOTE "clipboard sharing is disabled"));
|
||||
}
|
||||
@@ -1378,10 +1387,7 @@ Server::handleClientDisconnected(const Event&, void* vclient)
|
||||
removeActiveClient(client);
|
||||
removeOldClient(client);
|
||||
|
||||
PacketStreamFilter* streamFileter = dynamic_cast<PacketStreamFilter*>(client->getStream());
|
||||
TCPSocket* socket = dynamic_cast<TCPSocket*>(streamFileter->getStream());
|
||||
delete client;
|
||||
m_clientListener->deleteSocket(socket);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1391,16 +1397,14 @@ Server::handleClientCloseTimeout(const Event&, void* vclient)
|
||||
BaseClientProxy* client = static_cast<BaseClientProxy*>(vclient);
|
||||
LOG((CLOG_NOTE "forced disconnection of client \"%s\"", getName(client).c_str()));
|
||||
removeOldClient(client);
|
||||
PacketStreamFilter* streamFileter = dynamic_cast<PacketStreamFilter*>(client->getStream());
|
||||
TCPSocket* socket = dynamic_cast<TCPSocket*>(streamFileter->getStream());
|
||||
|
||||
delete client;
|
||||
m_clientListener->deleteSocket(socket);
|
||||
}
|
||||
|
||||
void
|
||||
Server::handleSwitchToScreenEvent(const Event& event, void*)
|
||||
{
|
||||
SwitchToScreenInfo* info =
|
||||
SwitchToScreenInfo* info =
|
||||
static_cast<SwitchToScreenInfo*>(event.getData());
|
||||
|
||||
ClientList::const_iterator index = m_clients.find(info->m_screen);
|
||||
@@ -1415,7 +1419,7 @@ Server::handleSwitchToScreenEvent(const Event& event, void*)
|
||||
void
|
||||
Server::handleSwitchInDirectionEvent(const Event& event, void*)
|
||||
{
|
||||
SwitchInDirectionInfo* info =
|
||||
SwitchInDirectionInfo* info =
|
||||
static_cast<SwitchInDirectionInfo*>(event.getData());
|
||||
|
||||
// jump to screen in chosen direction from center of this screen
|
||||
@@ -1705,8 +1709,8 @@ Server::onMouseUp(ButtonID id)
|
||||
m_ignoreFileTransfer = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_enableDragDrop) {
|
||||
|
||||
if (m_args.m_enableDragDrop) {
|
||||
if (!m_screen->isOnScreen()) {
|
||||
String& file = m_screen->getDraggingFilename();
|
||||
if (!file.empty()) {
|
||||
@@ -1791,7 +1795,7 @@ Server::onMouseMovePrimary(SInt32 x, SInt32 y)
|
||||
|
||||
// should we switch or not?
|
||||
if (isSwitchOkay(newScreen, dir, x, y, xc, yc)) {
|
||||
if (m_enableDragDrop
|
||||
if (m_args.m_enableDragDrop
|
||||
&& m_screen->isDraggingStarted()
|
||||
&& m_active != newScreen
|
||||
&& m_waitDragInfoThread) {
|
||||
@@ -1810,7 +1814,7 @@ Server::onMouseMovePrimary(SInt32 x, SInt32 y)
|
||||
m_waitDragInfoThread = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1826,7 +1830,7 @@ Server::sendDragInfoThread(void* arg)
|
||||
di.setFilename(dragFileList);
|
||||
m_dragFileList.push_back(di);
|
||||
}
|
||||
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// on mac it seems that after faking a LMB up, system would signal back
|
||||
// to synergy a mouse up event, which doesn't happen on windows. as a
|
||||
@@ -1849,7 +1853,7 @@ Server::sendDragInfo(BaseClientProxy* newScreen)
|
||||
{
|
||||
String infoString;
|
||||
UInt32 fileCount = DragInformation::setupDragInfo(m_dragFileList, infoString);
|
||||
|
||||
|
||||
if (fileCount > 0) {
|
||||
char* info = NULL;
|
||||
size_t size = infoString.size();
|
||||
@@ -2059,7 +2063,7 @@ Server::onFileChunkSending(const void* data)
|
||||
assert(m_active != NULL);
|
||||
|
||||
// relay
|
||||
m_active->fileChunkSending(chunk->m_chunk[0], &chunk->m_chunk[1], chunk->m_dataSize);
|
||||
m_active->fileChunkSending(chunk->m_chunk[0], &chunk->m_chunk[1], chunk->m_dataSize);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -2368,7 +2372,7 @@ Server::sendFileToClient(const char* filename)
|
||||
if (m_sendFileThread != NULL) {
|
||||
StreamChunker::interruptFile();
|
||||
}
|
||||
|
||||
|
||||
m_sendFileThread = new Thread(
|
||||
new TMethodJob<Server>(
|
||||
this, &Server::sendFileThread,
|
||||
@@ -2393,7 +2397,7 @@ Server::sendFileThread(void* data)
|
||||
void
|
||||
Server::dragInfoReceived(UInt32 fileNum, String content)
|
||||
{
|
||||
if (!m_enableDragDrop) {
|
||||
if (!m_args.m_enableDragDrop) {
|
||||
LOG((CLOG_DEBUG "drag drop not enabled, ignoring drag info."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "synergy/mouse_types.h"
|
||||
#include "synergy/INode.h"
|
||||
#include "synergy/DragInformation.h"
|
||||
#include "synergy/ServerArgs.h"
|
||||
#include "base/Event.h"
|
||||
#include "base/Stopwatch.h"
|
||||
#include "base/EventTypes.h"
|
||||
@@ -106,7 +107,7 @@ public:
|
||||
ownership of \p primaryClient.
|
||||
*/
|
||||
Server(Config& config, PrimaryClient* primaryClient,
|
||||
synergy::Screen* screen, IEventQueue* events, bool enableDragDrop);
|
||||
synergy::Screen* screen, IEventQueue* events, ServerArgs const& args);
|
||||
~Server();
|
||||
|
||||
#ifdef TEST_ENV
|
||||
@@ -472,11 +473,11 @@ private:
|
||||
Thread* m_writeToDropDirThread;
|
||||
String m_dragFileExt;
|
||||
bool m_ignoreFileTransfer;
|
||||
bool m_enableDragDrop;
|
||||
bool m_enableClipboard;
|
||||
|
||||
Thread* m_sendDragInfoThread;
|
||||
bool m_waitDragInfoThread;
|
||||
|
||||
ClientListener* m_clientListener;
|
||||
ServerArgs m_args;
|
||||
};
|
||||
|
||||
32
src/lib/shared/CMakeLists.txt
Normal file
32
src/lib/shared/CMakeLists.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
# synergy -- mouse and keyboard sharing utility
|
||||
# Copyright (C) 2016 Symless 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 LICENSE 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/>.
|
||||
|
||||
file(GLOB headers "*.h")
|
||||
file(GLOB sources "*.cpp")
|
||||
|
||||
if (SYNERGY_ADD_HEADERS)
|
||||
list(APPEND sources ${headers})
|
||||
endif()
|
||||
|
||||
add_library(shared STATIC ${sources})
|
||||
|
||||
include_directories(
|
||||
../
|
||||
../../../ext
|
||||
../../../ext/gtest-1.6.0/include
|
||||
)
|
||||
|
||||
target_link_libraries(shared arch base)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2015 Synergy Seamless Inc.
|
||||
*
|
||||
* Copyright (C) 2015-2016 Symless 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 LICENSE 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
|
||||
@@ -15,16 +15,16 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef EDITIONTYPE_H
|
||||
#define EDITIONTYPE_H
|
||||
|
||||
#include "base/String.h"
|
||||
/* Do not reorder these! */
|
||||
|
||||
struct SubscriptionKey {
|
||||
String m_name;
|
||||
String m_type;
|
||||
String m_email;
|
||||
String m_company;
|
||||
int m_userLimit;
|
||||
int m_warnTime;
|
||||
int m_expireTime;
|
||||
enum Edition {
|
||||
kBasic,
|
||||
kPro,
|
||||
Trial_DO_NOT_USE_OR_THERE_WILL_BE_PAIN,
|
||||
kUnregistered
|
||||
};
|
||||
|
||||
#endif // EDITIONTYPE_H
|
||||
264
src/lib/shared/SerialKey.cpp
Normal file
264
src/lib/shared/SerialKey.cpp
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2016 Symless 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 LICENSE 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 "SerialKey.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <climits>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace std;
|
||||
|
||||
SerialKey::SerialKey(Edition edition):
|
||||
m_userLimit(1),
|
||||
m_warnTime(ULLONG_MAX),
|
||||
m_expireTime(ULLONG_MAX),
|
||||
m_edition(edition),
|
||||
m_trial(false)
|
||||
{
|
||||
}
|
||||
|
||||
SerialKey::SerialKey(std::string serial) :
|
||||
m_userLimit(1),
|
||||
m_warnTime(0),
|
||||
m_expireTime(0),
|
||||
m_edition(kBasic),
|
||||
m_trial(true)
|
||||
{
|
||||
string plainText = decode(serial);
|
||||
bool valid = false;
|
||||
if (!plainText.empty()) {
|
||||
valid = parse(plainText);
|
||||
}
|
||||
if (!valid) {
|
||||
throw std::runtime_error ("Invalid serial key");
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
SerialKey::isExpiring(time_t currentTime) const
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (m_trial) {
|
||||
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
SerialKey::isExpired(time_t currentTime) const
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (m_trial) {
|
||||
if (m_expireTime <= currentTime) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
SerialKey::isTrial() const
|
||||
{
|
||||
return m_trial;
|
||||
}
|
||||
|
||||
Edition
|
||||
SerialKey::edition() const
|
||||
{
|
||||
return m_edition;
|
||||
}
|
||||
|
||||
std::string
|
||||
SerialKey::editionString() const
|
||||
{
|
||||
switch (edition()) {
|
||||
case kBasic:
|
||||
return "basic";
|
||||
case kPro:
|
||||
return "pro";
|
||||
default: {
|
||||
std::ostringstream oss;
|
||||
oss << static_cast<int>(edition());
|
||||
return oss.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static std::string
|
||||
hexEncode (std::string const& str) {
|
||||
std::ostringstream oss;
|
||||
for (size_t i = 0; i < str.size(); ++i) {
|
||||
int c = str[i];
|
||||
oss << std::setfill('0') << std::hex << std::setw(2)
|
||||
<< std::uppercase;
|
||||
oss << c;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::string
|
||||
SerialKey::toString() const
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "{";
|
||||
if (isTrial()) {
|
||||
oss << "v2;trial;";
|
||||
} else {
|
||||
oss << "v1;";
|
||||
}
|
||||
oss << editionString() << ";";
|
||||
oss << m_name << ";";
|
||||
oss << m_userLimit << ";";
|
||||
oss << m_email << ";";
|
||||
oss << m_company << ";";
|
||||
oss << (isTrial() ? m_warnTime : 0) << ";";
|
||||
oss << (isTrial() ? m_expireTime : 0);
|
||||
oss << "}";
|
||||
return hexEncode(oss.str());
|
||||
}
|
||||
|
||||
time_t
|
||||
SerialKey::daysLeft(time_t currentTime) const
|
||||
{
|
||||
unsigned long long timeLeft = 0;
|
||||
unsigned long long const day = 60 * 60 * 24;
|
||||
|
||||
if (currentTime < m_expireTime) {
|
||||
timeLeft = m_expireTime - currentTime;
|
||||
}
|
||||
|
||||
unsigned long long daysLeft = 0;
|
||||
daysLeft = timeLeft % day != 0 ? 1 : 0;
|
||||
|
||||
return timeLeft / day + daysLeft;
|
||||
}
|
||||
|
||||
std::string
|
||||
SerialKey::email() const
|
||||
{
|
||||
return m_email;
|
||||
}
|
||||
|
||||
std::string
|
||||
SerialKey::decode(const std::string& serial)
|
||||
{
|
||||
static const char* const lut = "0123456789ABCDEF";
|
||||
string output;
|
||||
size_t len = serial.length();
|
||||
if (len & 1) {
|
||||
return output;
|
||||
}
|
||||
|
||||
output.reserve(len / 2);
|
||||
for (size_t i = 0; i < len; i += 2) {
|
||||
|
||||
char a = serial[i];
|
||||
char b = serial[i + 1];
|
||||
|
||||
const char* p = std::lower_bound(lut, lut + 16, a);
|
||||
const char* q = std::lower_bound(lut, lut + 16, b);
|
||||
|
||||
if (*q != b || *p != a) {
|
||||
return output;
|
||||
}
|
||||
|
||||
output.push_back(static_cast<char>(((p - lut) << 4) | (q - lut)));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
bool
|
||||
SerialKey::parse(std::string plainSerial)
|
||||
{
|
||||
string parityStart = plainSerial.substr(0, 1);
|
||||
string parityEnd = plainSerial.substr(plainSerial.length() - 1, 1);
|
||||
|
||||
bool valid = false;
|
||||
|
||||
// check for parity chars { and }, record parity result, then remove them.
|
||||
if (parityStart == "{" && parityEnd == "}") {
|
||||
plainSerial = plainSerial.substr(1, plainSerial.length() - 2);
|
||||
|
||||
// tokenize serialised subscription.
|
||||
vector<string> parts;
|
||||
std::string::size_type pos = 0;
|
||||
bool look = true;
|
||||
while (look) {
|
||||
std::string::size_type start = pos;
|
||||
pos = plainSerial.find(";", pos);
|
||||
if (pos == string::npos) {
|
||||
pos = plainSerial.length();
|
||||
look = false;
|
||||
}
|
||||
parts.push_back(plainSerial.substr(start, pos - start));
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
if ((parts.size() == 8)
|
||||
&& (parts.at(0).find("v1") != string::npos)) {
|
||||
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||
m_edition = parseEdition(parts.at(1));
|
||||
m_name = parts.at(2);
|
||||
m_trial = false;
|
||||
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
|
||||
m_email = parts.at(4);
|
||||
m_company = parts.at(5);
|
||||
sscanf(parts.at(6).c_str(), "%lld", &m_warnTime);
|
||||
sscanf(parts.at(7).c_str(), "%lld", &m_expireTime);
|
||||
valid = true;
|
||||
}
|
||||
else if ((parts.size() == 9)
|
||||
&& (parts.at(0).find("v2") != string::npos)) {
|
||||
// e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||
m_trial = parts.at(1) == "trial" ? true : false;
|
||||
m_edition = parseEdition(parts.at(2));
|
||||
m_name = parts.at(3);
|
||||
sscanf(parts.at(4).c_str(), "%d", &m_userLimit);
|
||||
m_email = parts.at(5);
|
||||
m_company = parts.at(6);
|
||||
sscanf(parts.at(7).c_str(), "%lld", &m_warnTime);
|
||||
sscanf(parts.at(8).c_str(), "%lld", &m_expireTime);
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
Edition
|
||||
SerialKey::parseEdition(std::string const& editionStr)
|
||||
{
|
||||
Edition e = kBasic;
|
||||
if (editionStr == "pro") {
|
||||
e = kPro;
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
84
src/lib/shared/SerialKey.h
Normal file
84
src/lib/shared/SerialKey.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2016 Symless 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 LICENSE 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
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include "EditionType.h"
|
||||
|
||||
#ifdef TEST_ENV
|
||||
#include "gtest/gtest_prod.h"
|
||||
#endif
|
||||
|
||||
class SerialKey {
|
||||
friend bool operator== (SerialKey const&, SerialKey const&);
|
||||
public:
|
||||
explicit SerialKey(Edition edition = kUnregistered);
|
||||
explicit SerialKey(std::string serial);
|
||||
|
||||
bool isExpiring(time_t currentTime) const;
|
||||
bool isExpired(time_t currentTime) const;
|
||||
bool isTrial() const;
|
||||
time_t daysLeft(time_t currentTime) const;
|
||||
std::string email() const;
|
||||
Edition edition() const;
|
||||
std::string toString() const;
|
||||
|
||||
static std::string decode(const std::string& serial);
|
||||
static Edition parseEdition(const std::string& editionStr);
|
||||
|
||||
private:
|
||||
bool parse(std::string plainSerial);
|
||||
std::string editionString() const;
|
||||
|
||||
#ifdef TEST_ENV
|
||||
private:
|
||||
FRIEND_TEST(SerialKeyTests, parse_noParty_invalid);
|
||||
FRIEND_TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid);
|
||||
FRIEND_TEST(SerialKeyTests, parse_validV1Serial_valid);
|
||||
FRIEND_TEST(SerialKeyTests, parse_validV2Serial_valid);
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_email;
|
||||
std::string m_company;
|
||||
unsigned m_userLimit;
|
||||
unsigned long long m_warnTime;
|
||||
unsigned long long m_expireTime;
|
||||
Edition m_edition;
|
||||
bool m_trial;
|
||||
};
|
||||
|
||||
|
||||
inline bool
|
||||
operator== (SerialKey const& lhs, SerialKey const& rhs) {
|
||||
return (lhs.m_name == rhs.m_name) &&
|
||||
(lhs.m_email == rhs.m_email) &&
|
||||
(lhs.m_company == rhs.m_company) &&
|
||||
(lhs.m_userLimit == rhs.m_userLimit) &&
|
||||
(lhs.m_warnTime == rhs.m_warnTime) &&
|
||||
(lhs.m_expireTime == rhs.m_expireTime) &&
|
||||
(lhs.m_edition == rhs.m_edition) &&
|
||||
(lhs.m_trial == rhs.m_trial);
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator!= (SerialKey const& lhs, SerialKey const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014-2016 Symless 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 LICENSE 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
|
||||
@@ -74,6 +74,9 @@ ArgParser::parseServerArgs(ServerArgs& args, int argc, const char* const* argv)
|
||||
else if (isArg(i, argc, argv, "", "--prm-hc", 1)) {
|
||||
DpiHelper::s_primaryHeightCenter = synergy::string::stringToSizeType(argv[++i]);
|
||||
}
|
||||
else if (isArg(i, argc, argv, "", "--serial-key", 1)) {
|
||||
args.m_serial = SerialKey(argv[++i]);
|
||||
}
|
||||
else {
|
||||
LOG((CLOG_PRINT "%s: unrecognized option `%s'" BYE, args.m_pname, argv[i], args.m_pname));
|
||||
return false;
|
||||
@@ -111,7 +114,7 @@ ArgParser::parseClientArgs(ClientArgs& args, int argc, const char* const* argv)
|
||||
// ignore -- included for backwards compatibility
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--yscroll", 1)) {
|
||||
// define scroll
|
||||
// define scroll
|
||||
args.m_yscroll = atoi(argv[++i]);
|
||||
}
|
||||
else {
|
||||
@@ -193,18 +196,10 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
|
||||
args.m_loginAuthenticate = true;
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--get-plugin-list", 0)) {
|
||||
args.m_getPluginList = true;
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--get-installed-dir", 0)) {
|
||||
args.m_getInstalledDir = true;
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--get-plugin-dir", 0)) {
|
||||
args.m_getPluginDir = true;
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--get-profile-dir", 0)) {
|
||||
args.m_getProfileDir = true;
|
||||
return true;
|
||||
@@ -213,26 +208,14 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
|
||||
args.m_getArch = true;
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--subscription-serial", 1)) {
|
||||
args.m_subscriptionSerial = argv[++i];
|
||||
if (args.m_subscriptionSerial.empty()) {
|
||||
LOG((CLOG_CRIT "subscription error: serial was not provided"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--get-subscription-filename", 0)) {
|
||||
args.m_getSubscriptionFilename = true;
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--check-subscription", 0)) {
|
||||
args.m_checkSubscription = true;
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--notify-activation", 0)) {
|
||||
args.m_notifyActivation = true;
|
||||
return true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--notify-update", 0)) {
|
||||
args.m_notifyUpdate = true;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
@@ -296,10 +279,10 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
|
||||
argsBase().m_enableIpc = true;
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--server")) {
|
||||
// HACK: stop error happening when using portable (synergyp)
|
||||
// HACK: stop error happening when using portable (synergyp)
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--client")) {
|
||||
// HACK: stop error happening when using portable (synergyp)
|
||||
// HACK: stop error happening when using portable (synergyp)
|
||||
}
|
||||
else if (isArg(i, argc, argv, NULL, "--enable-drag-drop")) {
|
||||
bool useDragDrop = true;
|
||||
@@ -398,7 +381,7 @@ ArgParser::splitCommandString(String& command, std::vector<String>& argv)
|
||||
else if (space > rightDoubleQuote){
|
||||
searchDoubleQuotes(command, leftDoubleQuote, rightDoubleQuote, rightDoubleQuote + 1);
|
||||
}
|
||||
|
||||
|
||||
if (!ignoreThisSpace) {
|
||||
String subString = command.substr(startPos, space - startPos);
|
||||
|
||||
@@ -464,7 +447,7 @@ ArgParser::getArgv(std::vector<String>& argsArray)
|
||||
// them to the inner array. So caller only need to use
|
||||
// delete[] to delete the outer array
|
||||
const char** argv = new const char*[argc];
|
||||
|
||||
|
||||
for (size_t i = 0; i < argc; i++) {
|
||||
argv[i] = argsArray[i].c_str();
|
||||
}
|
||||
@@ -496,7 +479,7 @@ ArgParser::assembleCommand(std::vector<String>& argsArray, String ignoreArg, in
|
||||
|
||||
if (!result.empty()) {
|
||||
// remove the tail space
|
||||
result = result.substr(0, result.size() - 1);
|
||||
result = result.substr(0, result.size() - 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -513,13 +496,13 @@ bool
|
||||
ArgParser::checkUnexpectedArgs()
|
||||
{
|
||||
#if SYSAPI_WIN32
|
||||
// suggest that user installs as a windows service. when launched as
|
||||
// suggest that user installs as a windows service. when launched as
|
||||
// service, process should automatically detect that it should run in
|
||||
// daemon mode.
|
||||
if (argsBase().m_daemon) {
|
||||
LOG((CLOG_ERR
|
||||
LOG((CLOG_ERR
|
||||
"the --daemon argument is not supported on windows. "
|
||||
"instead, install %s as a service (--service install)",
|
||||
"instead, install %s as a service (--service install)",
|
||||
argsBase().m_pname));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ ServerApp::openClientListener(const NetworkAddress& address)
|
||||
Server*
|
||||
ServerApp::openServer(Config& config, PrimaryClient* primaryClient)
|
||||
{
|
||||
Server* server = new Server(config, primaryClient, m_serverScreen, m_events, args().m_enableDragDrop);
|
||||
Server* server = new Server(config, primaryClient, m_serverScreen, m_events, args());
|
||||
try {
|
||||
m_events->adoptHandler(
|
||||
m_events->forServer().disconnected(), server,
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
ServerArgs::ServerArgs() :
|
||||
m_configFile(),
|
||||
m_serial(),
|
||||
m_config(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014-2016 Symless 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 LICENSE 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
|
||||
@@ -18,6 +18,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "synergy/ArgsBase.h"
|
||||
#include "shared/SerialKey.h"
|
||||
|
||||
class NetworkAddress;
|
||||
class Config;
|
||||
@@ -28,5 +29,6 @@ public:
|
||||
|
||||
public:
|
||||
String m_configFile;
|
||||
SerialKey m_serial;
|
||||
Config* m_config;
|
||||
};
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2015 Synergy Seamless Inc.
|
||||
*
|
||||
* 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 LICENSE 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 "synergy/SubscriptionManager.h"
|
||||
|
||||
#include "synergy/XSynergy.h"
|
||||
#include "arch/Arch.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/String.h"
|
||||
#include "common/Version.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <ctime>
|
||||
//#include <stdexcept>
|
||||
|
||||
#if SYSAPI_WIN32
|
||||
const char* kFile = "Synergy.subkey";
|
||||
#else
|
||||
const char* kFile = ".synergy.subkey";
|
||||
#endif
|
||||
|
||||
//
|
||||
// SubscriptionManager
|
||||
//
|
||||
|
||||
SubscriptionManager::SubscriptionManager() :
|
||||
m_key()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SubscriptionManager::checkFile(const String& filename_)
|
||||
{
|
||||
String filename = filename_;
|
||||
if (filename.empty()) {
|
||||
filename = getFilename();
|
||||
}
|
||||
|
||||
std::ifstream stream(filename.c_str());
|
||||
if (!stream.is_open()) {
|
||||
throw XSubscription(synergy::string::sprintf(
|
||||
"Could not open, path=%s", filename.c_str()));
|
||||
}
|
||||
|
||||
String serial;
|
||||
stream >> serial;
|
||||
|
||||
String plainText = decode(serial);
|
||||
parsePlainSerial(plainText, m_key);
|
||||
|
||||
LOG((CLOG_DEBUG "subscription is valid"));
|
||||
}
|
||||
|
||||
void
|
||||
SubscriptionManager::activate(const String& serial)
|
||||
{
|
||||
String plainText = decode(serial);
|
||||
parsePlainSerial(plainText, m_key);
|
||||
|
||||
String filename = getFilename();
|
||||
std::ofstream stream(filename.c_str());
|
||||
if (!stream.is_open()) {
|
||||
throw XSubscription(synergy::string::sprintf(
|
||||
"Could not open, file=%s", filename.c_str()));
|
||||
}
|
||||
|
||||
stream << serial << std::endl;
|
||||
LOG((CLOG_DEBUG "subscription file created, path=%s", filename.c_str()));
|
||||
}
|
||||
|
||||
String
|
||||
SubscriptionManager::decode(const String& input)
|
||||
{
|
||||
static const char* const lut = "0123456789ABCDEF";
|
||||
size_t len = input.length();
|
||||
if (len & 1) {
|
||||
throw XSubscription("Invalid serial, wrong length.");
|
||||
}
|
||||
|
||||
String output;
|
||||
output.reserve(len / 2);
|
||||
for (size_t i = 0; i < len; i += 2) {
|
||||
|
||||
char a = input[i];
|
||||
char b = input[i + 1];
|
||||
|
||||
const char* p = std::lower_bound(lut, lut + 16, a);
|
||||
const char* q = std::lower_bound(lut, lut + 16, b);
|
||||
|
||||
if (*q != b || *p != a) {
|
||||
throw XSubscription("Invalid serial, unrecognized digit.");
|
||||
}
|
||||
|
||||
output.push_back(static_cast<char>(((p - lut) << 4) | (q - lut)));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void
|
||||
SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey& key)
|
||||
{
|
||||
String serial;
|
||||
String parityStart = plainText.substr(0, 1);
|
||||
String parityEnd = plainText.substr(plainText.length() - 1, 1);
|
||||
|
||||
// check for parity chars { and }, record parity result, then remove them.
|
||||
if (parityStart == "{" && parityEnd == "}") {
|
||||
serial = plainText.substr(1, plainText.length() - 2);
|
||||
|
||||
// tokenize serialised subscription.
|
||||
std::vector<String> parts;
|
||||
std::string::size_type pos = 0;
|
||||
bool look = true;
|
||||
while (look) {
|
||||
std::string::size_type start = pos;
|
||||
pos = serial.find(";", pos);
|
||||
if (pos == String::npos) {
|
||||
pos = plainText.length();
|
||||
look = false;
|
||||
}
|
||||
parts.push_back(serial.substr(start, pos - start));
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
// e.g.: {v1;trial;Bob;1;email;company name;1398297600;1398384000}
|
||||
if ((parts.size() == 8)
|
||||
&& (parts.at(0).find("v1") != String::npos)) {
|
||||
key.m_type = parts.at(1);
|
||||
key.m_name = parts.at(2);
|
||||
sscanf(parts.at(3).c_str(), "%d", &key.m_userLimit);
|
||||
key.m_email = parts.at(4);
|
||||
key.m_company = parts.at(5);
|
||||
sscanf(parts.at(6).c_str(), "%d", &key.m_warnTime);
|
||||
sscanf(parts.at(7).c_str(), "%d", &key.m_expireTime);
|
||||
|
||||
// only limit to trial version
|
||||
if (key.m_type == "trial") {
|
||||
if (time(0) > key.m_expireTime) {
|
||||
throw XSubscription("trial has expired");
|
||||
}
|
||||
else if (time(0) > key.m_warnTime) {
|
||||
int secLeft = key.m_expireTime - static_cast<int>(time(0));
|
||||
const int spd = 60 * 60 * 24;
|
||||
int dayLeft = secLeft / spd + 1;
|
||||
LOG((CLOG_NOTE "trial will end in %d %s",
|
||||
dayLeft,
|
||||
dayLeft == 1 ? "day" : "days"));
|
||||
}
|
||||
}
|
||||
|
||||
const char* userText = (key.m_userLimit == 1) ? "user" : "users";
|
||||
LOG((CLOG_INFO "%s subscription valid is for %d %s, registered to %s",
|
||||
key.m_type.c_str(),
|
||||
key.m_userLimit,
|
||||
userText,
|
||||
key.m_name.c_str()));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw XSubscription(synergy::string::sprintf("Serial is invalid."));
|
||||
}
|
||||
|
||||
String
|
||||
SubscriptionManager::getFilename()
|
||||
{
|
||||
String path = ARCH->getProfileDirectory();
|
||||
path = ARCH->concatPath(path, kFile);
|
||||
if (path.empty()) {
|
||||
throw XSubscription("Could not get filename.");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void
|
||||
SubscriptionManager::printFilename()
|
||||
{
|
||||
std::cout << getFilename() << std::endl;
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2015 Synergy Seamless Inc.
|
||||
*
|
||||
* 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 LICENSE 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
|
||||
|
||||
#include "SubscriptionKey.h"
|
||||
#include "common/common.h"
|
||||
|
||||
#include "gtest/gtest_prod.h"
|
||||
|
||||
class SubscriptionManager {
|
||||
public:
|
||||
SubscriptionManager();
|
||||
|
||||
//! Check the subscription activation file
|
||||
void checkFile(const String& filename);
|
||||
|
||||
//! Create a subscription activation file based on a serial
|
||||
void activate(const String& serial);
|
||||
|
||||
//! Use standard output to return subscription filename to gui
|
||||
void printFilename();
|
||||
|
||||
private:
|
||||
FRIEND_TEST(SubscriptionTests, decode_invalidLength_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, decode_invalidSerial_outputPlainText);
|
||||
FRIEND_TEST(SubscriptionTests, decode_unrecognizedDigit_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_noParity_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerialWithoutCompany_validSubscriptionKey);
|
||||
|
||||
private:
|
||||
String decode(const String& input);
|
||||
void parsePlainSerial(const String& plainText, SubscriptionKey& key);
|
||||
String getFilename();
|
||||
|
||||
SubscriptionKey m_key;
|
||||
};
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014-2016 Symless 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 LICENSE 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
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "synergy/ToolApp.h"
|
||||
|
||||
#include "synergy/ArgParser.h"
|
||||
#include "synergy/SubscriptionManager.h"
|
||||
#include "arch/Arch.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/String.h"
|
||||
@@ -72,50 +71,17 @@ ToolApp::run(int argc, char** argv)
|
||||
else if (m_args.m_loginAuthenticate) {
|
||||
loginAuth();
|
||||
}
|
||||
else if (m_args.m_getPluginList) {
|
||||
getPluginList();
|
||||
}
|
||||
else if (m_args.m_getInstalledDir) {
|
||||
std::cout << ARCH->getInstalledDirectory() << std::endl;
|
||||
}
|
||||
else if (m_args.m_getPluginDir) {
|
||||
std::cout << ARCH->getPluginDirectory() << std::endl;
|
||||
}
|
||||
else if (m_args.m_getProfileDir) {
|
||||
std::cout << ARCH->getProfileDirectory() << std::endl;
|
||||
}
|
||||
else if (m_args.m_getArch) {
|
||||
std::cout << ARCH->getPlatformName() << std::endl;
|
||||
}
|
||||
else if (!m_args.m_subscriptionSerial.empty()) {
|
||||
try {
|
||||
SubscriptionManager subscriptionManager;
|
||||
subscriptionManager.activate(m_args.m_subscriptionSerial);
|
||||
}
|
||||
catch (XSubscription& e) {
|
||||
LOG((CLOG_CRIT "subscription error: %s", e.what()));
|
||||
return kExitSubscription;
|
||||
}
|
||||
}
|
||||
else if (m_args.m_getSubscriptionFilename) {
|
||||
try {
|
||||
SubscriptionManager subscriptionManager;
|
||||
subscriptionManager.printFilename();
|
||||
}
|
||||
catch (XSubscription& e) {
|
||||
LOG((CLOG_CRIT "subscription error: %s", e.what()));
|
||||
return kExitSubscription;
|
||||
}
|
||||
}
|
||||
else if (m_args.m_checkSubscription) {
|
||||
try {
|
||||
SubscriptionManager subscriptionManager;
|
||||
subscriptionManager.checkFile("");
|
||||
}
|
||||
catch (XSubscription& e) {
|
||||
LOG((CLOG_CRIT "subscription error: %s", e.what()));
|
||||
return kExitSubscription;
|
||||
}
|
||||
else if (m_args.m_notifyUpdate) {
|
||||
notifyUpdate();
|
||||
}
|
||||
else if (m_args.m_notifyActivation) {
|
||||
notifyActivation();
|
||||
@@ -172,11 +138,29 @@ ToolApp::loginAuth()
|
||||
}
|
||||
|
||||
void
|
||||
ToolApp::getPluginList()
|
||||
ToolApp::notifyUpdate()
|
||||
{
|
||||
String data;
|
||||
std::cin >> data;
|
||||
|
||||
std::vector<String> parts = synergy::string::splitString(data, ':');
|
||||
size_t count = parts.size();
|
||||
|
||||
if (count == 3) {
|
||||
std::stringstream ss;
|
||||
ss << JSON_URL << "notify/update";
|
||||
ss << "?from=" << parts[0];
|
||||
ss << "&to=" << parts[1];
|
||||
ss << "&serial=" << parts[2];
|
||||
|
||||
std::cout << ARCH->internet().get(ss.str()) << std::endl;
|
||||
}
|
||||
else {
|
||||
throw XSynergy("Invalid update data.");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
ToolApp::notifyActivation()
|
||||
{
|
||||
String info;
|
||||
|
||||
@@ -29,8 +29,8 @@ public:
|
||||
|
||||
private:
|
||||
void loginAuth();
|
||||
void getPluginList();
|
||||
void notifyActivation();
|
||||
void notifyUpdate();
|
||||
|
||||
private:
|
||||
ToolArgs m_args;
|
||||
|
||||
@@ -20,14 +20,10 @@
|
||||
ToolArgs::ToolArgs() :
|
||||
m_printActiveDesktopName(false),
|
||||
m_loginAuthenticate(false),
|
||||
m_getPluginList(false),
|
||||
m_getPluginDir(false),
|
||||
m_getInstalledDir(false),
|
||||
m_getProfileDir(false),
|
||||
m_getArch(false),
|
||||
m_getSubscriptionFilename(false),
|
||||
m_checkSubscription(false),
|
||||
m_notifyActivation(false),
|
||||
m_subscriptionSerial()
|
||||
m_notifyUpdate(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,13 +26,9 @@ public:
|
||||
public:
|
||||
bool m_printActiveDesktopName;
|
||||
bool m_loginAuthenticate;
|
||||
bool m_getPluginList;
|
||||
bool m_getPluginDir;
|
||||
bool m_getInstalledDir;
|
||||
bool m_getProfileDir;
|
||||
bool m_getArch;
|
||||
bool m_getSubscriptionFilename;
|
||||
bool m_checkSubscription;
|
||||
bool m_notifyActivation;
|
||||
String m_subscriptionSerial;
|
||||
bool m_notifyUpdate;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user