summaryrefslogtreecommitdiffstats
path: root/src/lib/server/ClientProxy1_0.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/server/ClientProxy1_0.cpp')
-rw-r--r--src/lib/server/ClientProxy1_0.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lib/server/ClientProxy1_0.cpp b/src/lib/server/ClientProxy1_0.cpp
index 5cbaac2..33b0f15 100644
--- a/src/lib/server/ClientProxy1_0.cpp
+++ b/src/lib/server/ClientProxy1_0.cpp
@@ -2,11 +2,11 @@
* barrier -- 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
@@ -51,6 +51,10 @@ ClientProxy1_0::ClientProxy1_0(const std::string& name, barrier::IStream* stream
stream->getEventTarget(),
new TMethodEventJob<ClientProxy1_0>(this,
&ClientProxy1_0::handleDisconnect, NULL));
+ m_events->adoptHandler(m_events->forIStream().inputFormatError(),
+ stream->getEventTarget(),
+ new TMethodEventJob<ClientProxy1_0>(this,
+ &ClientProxy1_0::handleDisconnect, NULL));
m_events->adoptHandler(m_events->forIStream().outputShutdown(),
stream->getEventTarget(),
new TMethodEventJob<ClientProxy1_0>(this,
@@ -90,6 +94,8 @@ ClientProxy1_0::removeHandlers()
getStream()->getEventTarget());
m_events->removeHandler(m_events->forIStream().outputShutdown(),
getStream()->getEventTarget());
+ m_events->removeHandler(m_events->forIStream().inputFormatError(),
+ getStream()->getEventTarget());
m_events->removeHandler(Event::kTimer, this);
// remove timer
@@ -148,9 +154,18 @@ ClientProxy1_0::handleData(const Event&, void*)
}
// parse message
- LOG((CLOG_DEBUG2 "msg from \"%s\": %c%c%c%c", getName().c_str(), code[0], code[1], code[2], code[3]));
- if (!(this->*m_parser)(code)) {
- LOG((CLOG_ERR "invalid message from client \"%s\": %c%c%c%c", getName().c_str(), code[0], code[1], code[2], code[3]));
+ try {
+ LOG((CLOG_DEBUG2 "msg from \"%s\": %c%c%c%c", getName().c_str(), code[0], code[1], code[2], code[3]));
+ if (!(this->*m_parser)(code)) {
+ LOG((CLOG_ERR "invalid message from client \"%s\": %c%c%c%c", getName().c_str(), code[0], code[1], code[2], code[3]));
+ disconnect();
+ return;
+ }
+ } catch (const XBadClient& e) {
+ // TODO: disconnect handling is currently dispersed across both parseMessage() and
+ // handleData() functions, we should collect that to a single place
+
+ LOG((CLOG_ERR "protocol error from client: %s", e.what()));
disconnect();
return;
}
@@ -173,6 +188,8 @@ ClientProxy1_0::parseHandshakeMessage(const UInt8* code)
}
else if (memcmp(code, kMsgDInfo, 4) == 0) {
// future messages get parsed by parseMessage
+ // NOTE: we're taking address of virtual function here,
+ // not ClientProxy1_0 implementation of it.
m_parser = &ClientProxy1_0::parseMessage;
if (recvInfo()) {
m_events->addEvent(Event(m_events->forClientProxy().ready(), getEventTarget()));