2001-10-06 14:13:28 +00:00
|
|
|
#include "CServerProtocol.h"
|
|
|
|
#include "CServerProtocol1_0.h"
|
|
|
|
#include "ProtocolTypes.h"
|
2002-06-10 22:06:45 +00:00
|
|
|
#include "XSynergy.h"
|
2001-10-06 14:13:28 +00:00
|
|
|
#include "IOutputStream.h"
|
2002-06-10 22:06:45 +00:00
|
|
|
#include <cstdio>
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// CServerProtocol
|
|
|
|
//
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CServerProtocol::CServerProtocol(
|
|
|
|
CServer* server,
|
|
|
|
const CString& client,
|
|
|
|
IInputStream* input,
|
|
|
|
IOutputStream* output) :
|
|
|
|
m_server(server),
|
|
|
|
m_client(client),
|
|
|
|
m_input(input),
|
|
|
|
m_output(output)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
assert(m_server != NULL);
|
|
|
|
assert(m_input != NULL);
|
|
|
|
assert(m_output != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
CServerProtocol::~CServerProtocol()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CServer*
|
|
|
|
CServerProtocol::getServer() const
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
return m_server;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
|
|
|
CServerProtocol::getClient() const
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
return m_client;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
IInputStream*
|
|
|
|
CServerProtocol::getInputStream() const
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
return m_input;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
IOutputStream*
|
|
|
|
CServerProtocol::getOutputStream() const
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
return m_output;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
IServerProtocol*
|
|
|
|
CServerProtocol::create(
|
|
|
|
SInt32 major,
|
|
|
|
SInt32 minor,
|
|
|
|
CServer* server,
|
|
|
|
const CString& client,
|
|
|
|
IInputStream* input,
|
|
|
|
IOutputStream* output)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2002-05-23 14:56:03 +00:00
|
|
|
// disallow invalid version numbers
|
|
|
|
if (major < 0 || minor < 0) {
|
|
|
|
throw XIncompatibleClient(major, minor);
|
|
|
|
}
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// disallow connection from test versions to release versions
|
2002-06-04 11:06:26 +00:00
|
|
|
if (major == 0 && kProtocolMajorVersion != 0) {
|
2001-10-06 14:13:28 +00:00
|
|
|
throw XIncompatibleClient(major, minor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// hangup (with error) if version isn't supported
|
2002-06-04 11:06:26 +00:00
|
|
|
if (major > kProtocolMajorVersion ||
|
|
|
|
(major == kProtocolMajorVersion && minor > kProtocolMinorVersion)) {
|
2001-10-06 14:13:28 +00:00
|
|
|
throw XIncompatibleClient(major, minor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// create highest version protocol object not higher than the
|
|
|
|
// given version.
|
|
|
|
return new CServerProtocol1_0(server, client, input, output);
|
|
|
|
}
|