#5657 Merge core changes
This commit is contained in:
commit
d244683ac4
|
@ -35,6 +35,8 @@ endif()
|
|||
|
||||
add_library(server STATIC ${sources})
|
||||
|
||||
target_link_libraries(server shared)
|
||||
|
||||
if (UNIX)
|
||||
target_link_libraries(server synergy)
|
||||
endif()
|
||||
|
|
|
@ -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,17 @@ 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.empty()) {
|
||||
SerialKey serial(m_args.m_serial);
|
||||
if (!serial.isValid(std::time(0))) {
|
||||
LOG((CLOG_ERR "trial is expired, aborting server"));
|
||||
exit(kExitSuccess);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
{
|
||||
SInt32 dx, dy, dw, dh;
|
||||
|
@ -1706,7 +1719,7 @@ Server::onMouseUp(ButtonID id)
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_enableDragDrop) {
|
||||
if (m_args.m_enableDragDrop) {
|
||||
if (!m_screen->isOnScreen()) {
|
||||
String& file = m_screen->getDraggingFilename();
|
||||
if (!file.empty()) {
|
||||
|
@ -1791,7 +1804,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) {
|
||||
|
@ -2393,7 +2406,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;
|
||||
};
|
||||
|
|
|
@ -112,13 +112,16 @@ 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 day = 60 * 60 * 24;
|
||||
unsigned long long dayLeft = 0;
|
||||
dayLeft = timeLeft % day != 0 ? 1 : 0;
|
||||
|
||||
return timeLeft / day;
|
||||
return timeLeft / day + dayLeft;
|
||||
}
|
||||
|
||||
std::string
|
||||
|
|
|
@ -70,6 +70,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 = argv[++i];
|
||||
}
|
||||
else {
|
||||
LOG((CLOG_PRINT "%s: unrecognized option `%s'" BYE, args.m_pname, argv[i], args.m_pname));
|
||||
return false;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -28,5 +28,6 @@ public:
|
|||
|
||||
public:
|
||||
String m_configFile;
|
||||
String m_serial;
|
||||
Config* m_config;
|
||||
};
|
||||
|
|
|
@ -129,7 +129,9 @@ TEST_F(NetworkTests, sendToClient_mockData)
|
|||
ON_CALL(serverConfig, isScreen(_)).WillByDefault(Return(true));
|
||||
ON_CALL(serverConfig, getInputFilter()).WillByDefault(Return(&serverInputFilter));
|
||||
|
||||
Server server(serverConfig, &primaryClient, &serverScreen, &m_events, true);
|
||||
ServerArgs serverArgs;
|
||||
serverArgs.m_enableDragDrop = true;
|
||||
Server server(serverConfig, &primaryClient, &serverScreen, &m_events, serverArgs);
|
||||
server.m_mock = true;
|
||||
listener.setServer(&server);
|
||||
|
||||
|
@ -142,10 +144,10 @@ TEST_F(NetworkTests, sendToClient_mockData)
|
|||
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
|
||||
|
||||
|
||||
ClientArgs args;
|
||||
args.m_enableDragDrop = true;
|
||||
args.m_enableCrypto = false;
|
||||
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args);
|
||||
ClientArgs clientArgs;
|
||||
clientArgs.m_enableDragDrop = true;
|
||||
clientArgs.m_enableCrypto = false;
|
||||
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, clientArgs);
|
||||
|
||||
m_events.adoptHandler(
|
||||
m_events.forFile().fileRecieveCompleted(), &client,
|
||||
|
@ -185,7 +187,9 @@ TEST_F(NetworkTests, sendToClient_mockFile)
|
|||
ON_CALL(serverConfig, isScreen(_)).WillByDefault(Return(true));
|
||||
ON_CALL(serverConfig, getInputFilter()).WillByDefault(Return(&serverInputFilter));
|
||||
|
||||
Server server(serverConfig, &primaryClient, &serverScreen, &m_events, true);
|
||||
ServerArgs serverArgs;
|
||||
serverArgs.m_enableDragDrop = true;
|
||||
Server server(serverConfig, &primaryClient, &serverScreen, &m_events, serverArgs);
|
||||
server.m_mock = true;
|
||||
listener.setServer(&server);
|
||||
|
||||
|
@ -198,10 +202,10 @@ TEST_F(NetworkTests, sendToClient_mockFile)
|
|||
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
|
||||
|
||||
|
||||
ClientArgs args;
|
||||
args.m_enableDragDrop = true;
|
||||
args.m_enableCrypto = false;
|
||||
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args);
|
||||
ClientArgs clientArgs;
|
||||
clientArgs.m_enableDragDrop = true;
|
||||
clientArgs.m_enableCrypto = false;
|
||||
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, clientArgs);
|
||||
|
||||
m_events.adoptHandler(
|
||||
m_events.forFile().fileRecieveCompleted(), &client,
|
||||
|
@ -235,7 +239,9 @@ TEST_F(NetworkTests, sendToServer_mockData)
|
|||
ON_CALL(serverConfig, isScreen(_)).WillByDefault(Return(true));
|
||||
ON_CALL(serverConfig, getInputFilter()).WillByDefault(Return(&serverInputFilter));
|
||||
|
||||
Server server(serverConfig, &primaryClient, &serverScreen, &m_events, true);
|
||||
ServerArgs serverArgs;
|
||||
serverArgs.m_enableDragDrop = true;
|
||||
Server server(serverConfig, &primaryClient, &serverScreen, &m_events, serverArgs);
|
||||
server.m_mock = true;
|
||||
listener.setServer(&server);
|
||||
|
||||
|
@ -247,10 +253,10 @@ TEST_F(NetworkTests, sendToServer_mockData)
|
|||
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
|
||||
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
|
||||
|
||||
ClientArgs args;
|
||||
args.m_enableDragDrop = true;
|
||||
args.m_enableCrypto = false;
|
||||
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args);
|
||||
ClientArgs clientArgs;
|
||||
clientArgs.m_enableDragDrop = true;
|
||||
clientArgs.m_enableCrypto = false;
|
||||
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, clientArgs);
|
||||
|
||||
m_events.adoptHandler(
|
||||
m_events.forClientListener().connected(), &listener,
|
||||
|
@ -290,7 +296,9 @@ TEST_F(NetworkTests, sendToServer_mockFile)
|
|||
ON_CALL(serverConfig, isScreen(_)).WillByDefault(Return(true));
|
||||
ON_CALL(serverConfig, getInputFilter()).WillByDefault(Return(&serverInputFilter));
|
||||
|
||||
Server server(serverConfig, &primaryClient, &serverScreen, &m_events, true);
|
||||
ServerArgs serverArgs;
|
||||
serverArgs.m_enableDragDrop = true;
|
||||
Server server(serverConfig, &primaryClient, &serverScreen, &m_events, serverArgs);
|
||||
server.m_mock = true;
|
||||
listener.setServer(&server);
|
||||
|
||||
|
@ -302,10 +310,10 @@ TEST_F(NetworkTests, sendToServer_mockFile)
|
|||
ON_CALL(clientScreen, getShape(_, _, _, _)).WillByDefault(Invoke(getScreenShape));
|
||||
ON_CALL(clientScreen, getCursorPos(_, _)).WillByDefault(Invoke(getCursorPos));
|
||||
|
||||
ClientArgs args;
|
||||
args.m_enableDragDrop = true;
|
||||
args.m_enableCrypto = false;
|
||||
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, args);
|
||||
ClientArgs clientArgs;
|
||||
clientArgs.m_enableDragDrop = true;
|
||||
clientArgs.m_enableCrypto = false;
|
||||
Client client(&m_events, "stub", serverAddress, clientSocketFactory, &clientScreen, clientArgs);
|
||||
|
||||
m_events.adoptHandler(
|
||||
m_events.forClientListener().connected(), &listener,
|
||||
|
|
|
@ -78,3 +78,124 @@ TEST(SerialKeyTests, parse_validV2Serial_valid)
|
|||
EXPECT_EQ(true, serial.isExpiring(1));
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isValid_validV1BasicSerial_valid)
|
||||
{
|
||||
// {v1;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76313B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isValid(0));
|
||||
EXPECT_EQ(kBasic, serial.edition());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isValid_expiredV1ProSerial_valid)
|
||||
{
|
||||
// {v1;pro;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76313B70726F3B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isValid(0));
|
||||
EXPECT_EQ(kPro, serial.edition());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isValid_validV2LifetimeBasicSerial_valid)
|
||||
{
|
||||
// {v2;lifetime;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B6C69666574696D653B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isValid(0));
|
||||
EXPECT_EQ(kBasic, serial.edition());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isValid_validV2LifetimeProSerial_valid)
|
||||
{
|
||||
// {v2;lifetime;pro;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B6C69666574696D653B70726F3B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isValid(0));
|
||||
EXPECT_EQ(kPro, serial.edition());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isValid_validV2TrialBasicSerial_valid)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isValid(0));
|
||||
EXPECT_EQ(kBasic, serial.edition());
|
||||
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isValid_expiredV2TrialProSerial_invalid)
|
||||
{
|
||||
// {v2;trial;pro;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B70726F3B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_FALSE(serial.isValid(86401));
|
||||
EXPECT_EQ(kPro, serial.edition());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpiring_validV2TrialBasicSerial_returnFalse)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_FALSE(serial.isExpiring(0));
|
||||
EXPECT_EQ(kBasic, serial.edition());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpiring_expiringV2TrialBasicSerial_returnTrue)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isExpiring(1));
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpiring_expiredV2TrialBasicSerial_returnFalse)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_FALSE(serial.isExpiring(86401));
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpired_validV2TrialBasicSerial_returnFalse)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_FALSE(serial.isExpired(0));
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpired_expiringV2TrialBasicSerial_returnFalse)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_FALSE(serial.isExpired(1));
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpired_expiredV2TrialBasicSerial_returnTrue)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isExpired(86401));
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, dayLeft_validExactlyOneDayV2TrialBasicSerial_returnOne)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(1, serial.dayLeft(0));
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, dayLeft_validWithinOneDayV2TrialBasicSerial_returnOne)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(1, serial.dayLeft(1));
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, dayLeft_expiredV2TrialBasicSerial_returnZero)
|
||||
{
|
||||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(0, serial.dayLeft(86401));
|
||||
}
|
||||
|
|
|
@ -64,3 +64,17 @@ TEST(ServerArgsParsingTests, parseServerArgs_configArg_setConfigFile)
|
|||
|
||||
EXPECT_EQ("mock_configFile", serverArgs.m_configFile);
|
||||
}
|
||||
|
||||
TEST(ServerArgsParsingTests, parseServerArgs_serialArg_setSerial)
|
||||
{
|
||||
NiceMock<MockArgParser> argParser;
|
||||
ON_CALL(argParser, parseGenericArgs(_, _, _)).WillByDefault(Invoke(server_stubParseGenericArgs));
|
||||
ON_CALL(argParser, checkUnexpectedArgs()).WillByDefault(Invoke(server_stubCheckUnexpectedArgs));
|
||||
ServerArgs serverArgs;
|
||||
const int argc = 3;
|
||||
const char* kSerialCmd[argc] = { "stub", "--serial-key", "mock_serial" };
|
||||
|
||||
argParser.parseServerArgs(serverArgs, argc, kSerialCmd);
|
||||
|
||||
EXPECT_EQ("mock_serial", serverArgs.m_serial);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue