FileInStream.cxx
HexInStream.cxx
HexOutStream.cxx
- InStream.cxx
RandomStream.cxx
TLSException.cxx
TLSInStream.cxx
+++ /dev/null
-/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
- *
- * This is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This software 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
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this software; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- * USA.
- */
-
-#include <rdr/InStream.h>
-#include <rdr/Exception.h>
-
-using namespace rdr;
-
-U32 InStream::maxStringLength = 65535;
-
-char* InStream::readString()
-{
- U32 len = readU32();
- if (len > maxStringLength)
- throw Exception("InStream max string length exceeded");
- char* str = new char[len+1];
- readBytes(str, len);
- str[len] = 0;
- return str;
-}
inline S16 readS16() { return (S16)readU16(); }
inline S32 readS32() { return (S32)readU32(); }
- // readString() reads a string - a U32 length followed by the data.
- // Returns a null-terminated string - the caller should delete[] it
- // afterwards.
-
- char* readString();
-
- // maxStringLength protects against allocating a huge buffer. Set it
- // higher if you need longer strings.
-
- static U32 maxStringLength;
-
inline void skip(size_t bytes) {
while (bytes > 0) {
size_t n = check(1, bytes);
inline void writeS16(S16 s) { writeU16((U16)s); }
inline void writeS32(S32 s) { writeU32((U32)s); }
- // writeString() writes a string - a U32 length followed by the data. The
- // given string should be null-terminated (but the terminating null is not
- // written to the stream).
-
- inline void writeString(const char* str) {
- U32 len = strlen(str);
- writeU32(len);
- writeBytes(str, len);
- }
-
inline void pad(size_t bytes) {
while (bytes-- > 0) writeU8(0);
}
state_ = RFBSTATE_INVALID;
if (server.beforeVersion(3,8))
throw AuthFailureException();
- CharArray reason(is->readString());
+ rdr::U32 len = is->readU32();
+ CharArray reason(len + 1);
+ is->readBytes(reason.buf, len);
+ reason.buf[len] = '\0';
throw AuthFailureException(reason.buf);
}
void CConnection::throwConnFailedException()
{
state_ = RFBSTATE_INVALID;
- CharArray reason;
- reason.buf = is->readString();
+ rdr::U32 len = is->readU32();
+ CharArray reason(len + 1);
+ is->readBytes(reason.buf, len);
+ reason.buf[len] = '\0';
throw ConnFailedException(reason.buf);
}
int height = is->readU16();
PixelFormat pf;
pf.read(is);
- CharArray name(is->readString());
+ rdr::U32 len = is->readU32();
+ CharArray name(len + 1);
+ is->readBytes(name.buf, len);
+ name.buf[len] = '\0';
handler->serverInit(width, height, pf, name.buf);
}
void CMsgReader::readSetDesktopName(int x, int y, int w, int h)
{
- char* name = is->readString();
+ rdr::U32 len = is->readU32();
+ CharArray name(len + 1);
+ is->readBytes(name.buf, len);
+ name.buf[len] = '\0';
if (x || y || w || h) {
vlog.error("Ignoring DesktopName rect with non-zero position/size");
} else {
- handler->setName(name);
+ handler->setName(name.buf);
}
-
- delete [] name;
}
void CMsgReader::readExtendedDesktopSize(int x, int y, int w, int h)
try {
os->writeU32(secResultFailed);
- if (!client.beforeVersion(3,8)) // 3.8 onwards have failure message
- os->writeString(authFailureMsg.buf);
+ if (!client.beforeVersion(3,8)) { // 3.8 onwards have failure message
+ const char* reason = authFailureMsg.buf;
+ os->writeU32(strlen(reason));
+ os->writeBytes(reason, strlen(reason));
+ }
os->flush();
} catch (rdr::Exception& e) {
close(e.str());
if (state_ == RFBSTATE_PROTOCOL_VERSION) {
if (client.majorVersion == 3 && client.minorVersion == 3) {
os->writeU32(0);
- os->writeString(str);
+ os->writeU32(strlen(str));
+ os->writeBytes(str, strlen(str));
os->flush();
} else {
os->writeU8(0);
- os->writeString(str);
+ os->writeU32(strlen(str));
+ os->writeBytes(str, strlen(str));
os->flush();
}
}
} else {
os->writeU32(secResultFailed);
if (!client.beforeVersion(3,8)) { // 3.8 onwards have failure message
- if (reason)
- os->writeString(reason);
- else
- os->writeString("Authentication failure");
+ if (!reason)
+ reason = "Authentication failure";
+ os->writeU32(strlen(reason));
+ os->writeBytes(reason, strlen(reason));
}
}
os->flush();
os->writeU16(width);
os->writeU16(height);
pf.write(os);
- os->writeString(name);
+ os->writeU32(strlen(name));
+ os->writeBytes(name, strlen(name));
endMsg();
}
os->writeU16(0);
os->writeU16(0);
os->writeU32(pseudoEncodingDesktopName);
- os->writeString(name);
+ os->writeU32(strlen(name));
+ os->writeBytes(name, strlen(name));
}
void SMsgWriter::writeSetCursorRect(int width, int height,
// Shortest possible way to tell a client it is not welcome
os.writeBytes("RFB 003.003\n", 12);
os.writeU32(0);
- os.writeString("Too many security failures");
+ const char* reason = "Too many security failures";
+ os.writeU32(strlen(reason));
+ os.writeBytes(reason, strlen(reason));
os.flush();
} catch (rdr::Exception&) {
}