コード例 #1
0
ファイル: Client.cpp プロジェクト: 335/synergy
void
Client::handleHello(const Event&, void*)
{
	SInt16 major, minor;
	if (!ProtocolUtil::readf(m_stream, kMsgHello, &major, &minor)) {
		sendConnectionFailedEvent("Protocol error from server, check encryption settings");
		cleanupTimer();
		cleanupConnection();
		return;
	}

	// check versions
	LOG((CLOG_DEBUG1 "got hello version %d.%d", major, minor));
	if (major < kProtocolMajorVersion ||
		(major == kProtocolMajorVersion && minor < kProtocolMinorVersion)) {
		sendConnectionFailedEvent(XIncompatibleClient(major, minor).what());
		cleanupTimer();
		cleanupConnection();
		return;
	}

	// say hello back
	LOG((CLOG_DEBUG1 "say hello version %d.%d", kProtocolMajorVersion, kProtocolMinorVersion));
	ProtocolUtil::writef(m_stream, kMsgHelloBack,
							kProtocolMajorVersion,
							kProtocolMinorVersion, &m_name);

	// now connected but waiting to complete handshake
	setupScreen();
	cleanupTimer();

	// make sure we process any remaining messages later.  we won't
	// receive another event for already pending messages so we fake
	// one.
	if (m_stream->isReady()) {
		m_events->addEvent(Event(m_events->forIStream().inputReady(),
							m_stream->getEventTarget()));
	}
}
コード例 #2
0
void
CClientProxyUnknown::handleData(const CEvent&, void*)
{
	LOG((CLOG_DEBUG1 "parsing hello reply"));

	CString name("<unknown>");
	try {
		// limit the maximum length of the hello
		UInt32 n = m_stream->getSize();
		if (n > kMaxHelloLength) {
			LOG((CLOG_DEBUG1 "hello reply too long"));
			throw XBadClient();
		}

		// parse the reply to hello
		SInt16 major, minor;
		if (!CProtocolUtil::readf(m_stream, kMsgHelloBack,
									&major, &minor, &name)) {
			throw XBadClient();
		}

		// disallow invalid version numbers
		if (major <= 0 || minor < 0) {
			throw XIncompatibleClient(major, minor);
		}

		// remove stream event handlers.  the proxy we're about to create
		// may install its own handlers and we don't want to accidentally
		// remove those later.
		removeHandlers();

		// create client proxy for highest version supported by the client
		if (major == 1) {
			switch (minor) {
			case 0:
				m_proxy = new CClientProxy1_0(name, m_stream);
				break;

			case 1:
				m_proxy = new CClientProxy1_1(name, m_stream);
				break;

			case 2:
				m_proxy = new CClientProxy1_2(name, m_stream);
				break;

			case 3:
				m_proxy = new CClientProxy1_3(name, m_stream);
				break;
			}
		}

		// hangup (with error) if version isn't supported
		if (m_proxy == NULL) {
			throw XIncompatibleClient(major, minor);
		}

		// the proxy is created and now proxy now owns the stream
		LOG((CLOG_DEBUG1 "created proxy for client \"%s\" version %d.%d", name.c_str(), major, minor));
		m_stream = NULL;

		// wait until the proxy signals that it's ready or has disconnected
		addProxyHandlers();
		return;
	}
	catch (XIncompatibleClient& e) {
		// client is incompatible
		LOG((CLOG_WARN "client \"%s\" has incompatible version %d.%d)", name.c_str(), e.getMajor(), e.getMinor()));
		CProtocolUtil::writef(m_stream,
							kMsgEIncompatible,
							kProtocolMajorVersion, kProtocolMinorVersion);
	}
	catch (XBadClient&) {
		// client not behaving
		LOG((CLOG_WARN "protocol error from client \"%s\"", name.c_str()));
		CProtocolUtil::writef(m_stream, kMsgEBad);
	}
	catch (XBase& e) {
		// misc error
		LOG((CLOG_WARN "error communicating with client \"%s\": %s", name.c_str(), e.what()));
	}
	sendFailure();
}