diff --git a/client/CClient.cpp b/client/CClient.cpp index 3f8ec103..4447d295 100644 --- a/client/CClient.cpp +++ b/client/CClient.cpp @@ -294,6 +294,10 @@ void CClient::runSession(void*) onErrorBusy(); break; } + else if (memcmp(code, kMsgEUnknown, 4) == 0) { + onErrorUnknown(); + break; + } else if (memcmp(code, kMsgEBad, 4) == 0) { onErrorBad(); break; @@ -606,6 +610,11 @@ void CClient::onErrorBusy() log((CLOG_ERR "server already has a connected client with name \"%s\"", m_name.c_str())); } +void CClient::onErrorUnknown() +{ + log((CLOG_ERR "server refused client with name \"%s\"", m_name.c_str())); +} + void CClient::onErrorBad() { log((CLOG_ERR "server disconnected due to a protocol error")); diff --git a/client/CClient.h b/client/CClient.h index a6c0cea1..9920a45c 100644 --- a/client/CClient.h +++ b/client/CClient.h @@ -53,6 +53,7 @@ private: void onMouseWheel(); void onErrorIncompatible(); void onErrorBusy(); + void onErrorUnknown(); void onErrorBad(); private: diff --git a/server/CServer.cpp b/server/CServer.cpp index e7cf497f..d7c71da6 100644 --- a/server/CServer.cpp +++ b/server/CServer.cpp @@ -992,6 +992,11 @@ void CServer::handshakeClient(void* vsocket) log((CLOG_WARN "a client with name \"%s\" is already connected", e.getName().c_str())); CProtocolUtil::writef(output.get(), kMsgEBusy); } + catch (XUnknownClient& e) { + // client has unknown name + log((CLOG_WARN "a client with name \"%s\" is not in the map", e.getName().c_str())); + CProtocolUtil::writef(output.get(), kMsgEUnknown); + } catch (XIncompatibleClient& e) { // client is incompatible // FIXME -- could print network address if socket had suitable method @@ -1278,7 +1283,10 @@ CServer::CScreenInfo* CServer::addConnection( throw XDuplicateClient(name); } - // FIXME -- throw if the name is not in our map + // name must be in our configuration + if (!m_config.isScreen(name)) { + throw XUnknownClient(name); + } // save screen info CScreenInfo* newScreen = new CScreenInfo(name, protocol); diff --git a/synergy/ProtocolTypes.h b/synergy/ProtocolTypes.h index c8194961..e06093fa 100644 --- a/synergy/ProtocolTypes.h +++ b/synergy/ProtocolTypes.h @@ -131,6 +131,11 @@ static const char kMsgEIncompatible[] = "EICV%2i%2i"; // name provided when connecting is already in use: primary -> secondary static const char kMsgEBusy[] = "EBSY"; +// unknown client: primary -> secondary +// name provided when connecting is not in primary's screen +// configuration map. +static const char kMsgEUnknown[] = "EUNK"; + // protocol violation: primary -> secondary // primary should disconnect after sending this message. static const char kMsgEBad[] = "EBAD"; diff --git a/synergy/XSynergy.cpp b/synergy/XSynergy.cpp index d07c727c..94159f9a 100644 --- a/synergy/XSynergy.cpp +++ b/synergy/XSynergy.cpp @@ -55,3 +55,23 @@ CString XDuplicateClient::getWhat() const throw() { return "XDuplicateClient"; } + + +// +// XUnknownClient +// + +XUnknownClient::XUnknownClient(const CString& name) : m_name(name) +{ + // do nothing +} + +const CString& XUnknownClient::getName() const throw() +{ + return m_name; +} + +CString XUnknownClient::getWhat() const throw() +{ + return "XUnknownClient"; +} diff --git a/synergy/XSynergy.h b/synergy/XSynergy.h index f3dde1f6..dda1d106 100644 --- a/synergy/XSynergy.h +++ b/synergy/XSynergy.h @@ -50,4 +50,23 @@ private: CString m_name; }; +// client has unknown name (i.e. name is not in server's screen map) +class XUnknownClient : public XSynergy { +public: + XUnknownClient(const CString& name); + + // manipulators + + // accessors + + virtual const CString& + getName() const throw(); + +protected: + virtual CString getWhat() const throw(); + +private: + CString m_name; +}; + #endif