From 3e924126b56c4d421e8263d25f6b14aa4ceed047 Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Sun, 13 Nov 2011 09:27:51 +0100 Subject: Imported nxcomp-3.1.0-4.tar.gz Summary: Imported nxcomp-3.1.0-4.tar.gz Keywords: Imported nxcomp-3.1.0-4.tar.gz into Git repository --- nxcomp/ServerReadBuffer.cpp | 235 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100755 nxcomp/ServerReadBuffer.cpp (limited to 'nxcomp/ServerReadBuffer.cpp') diff --git a/nxcomp/ServerReadBuffer.cpp b/nxcomp/ServerReadBuffer.cpp new file mode 100755 index 000000000..68513bb6b --- /dev/null +++ b/nxcomp/ServerReadBuffer.cpp @@ -0,0 +1,235 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */ +/* */ +/* NXCOMP, NX protocol compression and NX extensions to this software */ +/* are copyright of NoMachine. Redistribution and use of the present */ +/* software is allowed according to terms specified in the file LICENSE */ +/* which comes in the source distribution. */ +/* */ +/* Check http://www.nomachine.com/licensing.html for applicability. */ +/* */ +/* NX and NoMachine are trademarks of NoMachine S.r.l. */ +/* */ +/* All rights reserved. */ +/* */ +/**************************************************************************/ + +#include "ServerReadBuffer.h" +#include "ServerChannel.h" + +// +// Set the verbosity level. +// + +#define PANIC +#define WARNING +#undef TEST +#undef DEBUG + +unsigned int ServerReadBuffer::suggestedLength(unsigned int pendingLength) +{ + // + // Always read all the data that + // is available. + // + + int readable = transport_ -> readable(); + + unsigned int readLength = (readable == -1 ? 0 : (unsigned int) readable); + + if (readLength < pendingLength) + { + readLength = pendingLength; + } + + // + // Even if the readable data is not + // enough to make a complete message, + // resize the buffer to accomodate + // it all. + // + + if (pendingLength < remaining_) + { + readLength = remaining_; + } + + return readLength; +} + +int ServerReadBuffer::locateMessage(const unsigned char *start, + const unsigned char *end, + unsigned int &controlLength, + unsigned int &dataLength, + unsigned int &trailerLength) +{ + unsigned int size = end - start; + + #ifdef TEST + *logofs << "ServerReadBuffer: Locating message for FD#" + << transport_ -> fd() << " with " << size + << " bytes.\n" << logofs_flush; + #endif + + if (firstMessage_) + { + if (size < 8) + { + remaining_ = 8 - size; + + #ifdef TEST + *logofs << "ServerReadBuffer: No message was located " + << "with remaining " << remaining_ << ".\n" + << logofs_flush; + #endif + + return 0; + } + + dataLength = 8 + (GetUINT(start + 6, bigEndian_) << 2); + } + else + { + if (size < 32) + { + remaining_ = 32 - size; + + #ifdef TEST + *logofs << "ServerReadBuffer: No message was located " + << "with remaining " << remaining_ << ".\n" + << logofs_flush; + #endif + + return 0; + } + + if (*start == 1) + { + dataLength = 32 + (GetULONG(start + 4, bigEndian_) << 2); + } + else + { + dataLength = 32; + } + + if (dataLength < 32) + { + #ifdef TEST + *logofs << "ServerReadBuffer: WARNING! Assuming length 32 " + << "for suspicious message of length " << dataLength + << ".\n" << logofs_flush; + #endif + + dataLength = 32; + } + } + + #ifdef TEST + *logofs << "ServerReadBuffer: Length of the next message is " + << dataLength << ".\n" << logofs_flush; + #endif + + if (size < dataLength) + { + remaining_ = dataLength - size; + + #ifdef TEST + *logofs << "ServerReadBuffer: No message was located " + << "with remaining " << remaining_ << ".\n" + << logofs_flush; + #endif + + return 0; + } + + firstMessage_ = 0; + + controlLength = 0; + trailerLength = 0; + + remaining_ = 0; + + #ifdef TEST + *logofs << "ServerReadBuffer: Located message with " + << "remaining " << remaining_ << ".\n" + << logofs_flush; + #endif + + return 1; +} + +// +// Check if the data already read contains a +// message matching the opcode and sequence, +// starting at the given offset. +// + +unsigned char *ServerReadBuffer::peekMessage(unsigned int &offset, unsigned char opcode, + unsigned short sequence) +{ + #ifdef TEST + *logofs << "ServerReadBuffer: Peeking message " + << "for FD#" << transport_ -> fd() << " with size " + << length_ << " offset " << offset << " opcode " + << (unsigned int) opcode << " and sequence " + << sequence << ".\n" << logofs_flush; + #endif + + if (firstMessage_) + { + return NULL; + } + + unsigned char *next = buffer_ + start_ + offset; + unsigned char *end = buffer_ + start_ + length_; + + int found = 0; + + while (end - next >= 32) + { + #ifdef DEBUG + *logofs << "ServerReadBuffer: Checking opcode " + << (unsigned int) *next << " sequence " + << GetUINT(next + 2, bigEndian_) + << " at " << next - buffer_ + start_ + << ".\n" << logofs_flush; + #endif + + if (*next == opcode && GetUINT(next + 2, bigEndian_) == sequence) + { + found = 1; + + break; + } + else if (*next == 1) + { + next += (32 + (GetULONG(next + 4, bigEndian_) << 2)); + } + else + { + next += 32; + } + } + + offset = next - buffer_ + start_; + + if (found == 1) + { + #ifdef TEST + *logofs << "ServerReadBuffer: Found message at " + << "offset " << next - buffer_ + start_ + << ".\n" << logofs_flush; + #endif + + return next; + } + + #ifdef TEST + *logofs << "ServerReadBuffer: Quitting loop at " + << "offset " << next - buffer_ + start_ + << ".\n" << logofs_flush; + #endif + + return NULL; +} -- cgit v1.2.3 From 799bf672a3588f205bd18ef39d9908069e0cd6d5 Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Sun, 13 Nov 2011 09:27:52 +0100 Subject: Imported nxcomp-3.4.0-1.tar.gz Summary: Imported nxcomp-3.4.0-1.tar.gz Keywords: Imported nxcomp-3.4.0-1.tar.gz into Git repository --- nxcomp/ServerReadBuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 nxcomp/ServerReadBuffer.cpp (limited to 'nxcomp/ServerReadBuffer.cpp') diff --git a/nxcomp/ServerReadBuffer.cpp b/nxcomp/ServerReadBuffer.cpp old mode 100755 new mode 100644 index 68513bb6b..0b3c7747e --- a/nxcomp/ServerReadBuffer.cpp +++ b/nxcomp/ServerReadBuffer.cpp @@ -1,6 +1,6 @@ /**************************************************************************/ /* */ -/* Copyright (c) 2001, 2007 NoMachine, http://www.nomachine.com/. */ +/* Copyright (c) 2001, 2009 NoMachine, http://www.nomachine.com/. */ /* */ /* NXCOMP, NX protocol compression and NX extensions to this software */ /* are copyright of NoMachine. Redistribution and use of the present */ @@ -9,7 +9,7 @@ /* */ /* Check http://www.nomachine.com/licensing.html for applicability. */ /* */ -/* NX and NoMachine are trademarks of NoMachine S.r.l. */ +/* NX and NoMachine are trademarks of Medialogic S.p.A. */ /* */ /* All rights reserved. */ /* */ -- cgit v1.2.3 From 477961678194817aaf1aaf3602f1c91d288a539d Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Sun, 13 Nov 2011 09:27:53 +0100 Subject: Imported nxcomp-3.4.0-6.tar.gz Summary: Imported nxcomp-3.4.0-6.tar.gz Keywords: Imported nxcomp-3.4.0-6.tar.gz into Git repository --- nxcomp/ServerReadBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nxcomp/ServerReadBuffer.cpp') diff --git a/nxcomp/ServerReadBuffer.cpp b/nxcomp/ServerReadBuffer.cpp index 0b3c7747e..53c1dec57 100644 --- a/nxcomp/ServerReadBuffer.cpp +++ b/nxcomp/ServerReadBuffer.cpp @@ -1,6 +1,6 @@ /**************************************************************************/ /* */ -/* Copyright (c) 2001, 2009 NoMachine, http://www.nomachine.com/. */ +/* Copyright (c) 2001, 2010 NoMachine, http://www.nomachine.com/. */ /* */ /* NXCOMP, NX protocol compression and NX extensions to this software */ /* are copyright of NoMachine. Redistribution and use of the present */ -- cgit v1.2.3