aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/network/TcpSocket.cxx21
-rw-r--r--common/network/TcpSocket.h5
-rw-r--r--common/rfb/CConnection.cxx15
-rw-r--r--common/rfb/CMsgHandler.cxx5
-rw-r--r--common/rfb/CMsgReader.cxx4
-rw-r--r--common/rfb/CSecurityDH.cxx17
-rw-r--r--common/rfb/CSecurityMSLogonII.cxx17
-rw-r--r--common/rfb/CSecurityPlain.cxx15
-rw-r--r--common/rfb/CSecurityRSAAES.cxx33
-rw-r--r--common/rfb/CSecurityVncAuth.cxx10
-rw-r--r--common/rfb/ComparingUpdateTracker.cxx8
-rw-r--r--common/rfb/Configuration.cxx46
-rw-r--r--common/rfb/Configuration.h28
-rw-r--r--common/rfb/DecodeManager.cxx21
-rw-r--r--common/rfb/EncodeManager.cxx30
-rw-r--r--common/rfb/Hostname.h15
-rw-r--r--common/rfb/LogWriter.cxx2
-rw-r--r--common/rfb/SConnection.cxx15
-rw-r--r--common/rfb/SMsgHandler.cxx5
-rw-r--r--common/rfb/SMsgReader.cxx4
-rw-r--r--common/rfb/SSecurityPlain.cxx3
-rw-r--r--common/rfb/UserPasswdGetter.h10
-rw-r--r--common/rfb/util.cxx176
-rw-r--r--common/rfb/util.h27
24 files changed, 242 insertions, 290 deletions
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx
index 74143a40..ec36b33d 100644
--- a/common/network/TcpSocket.cxx
+++ b/common/network/TcpSocket.cxx
@@ -341,8 +341,9 @@ Socket* TcpListener::createSocket(int fd) {
return new TcpSocket(fd);
}
-void TcpListener::getMyAddresses(std::list<char*>* result) {
+std::list<std::string> TcpListener::getMyAddresses() {
struct addrinfo *ai, *current, hints;
+ std::list<std::string> result;
initSockets();
@@ -356,9 +357,11 @@ void TcpListener::getMyAddresses(std::list<char*>* result) {
// Windows doesn't like NULL for service, so specify something
if ((getaddrinfo(NULL, "1", &hints, &ai)) != 0)
- return;
+ return result;
for (current= ai; current != NULL; current = current->ai_next) {
+ char addr[INET6_ADDRSTRLEN];
+
switch (current->ai_family) {
case AF_INET:
if (!UseIPv4)
@@ -372,15 +375,15 @@ void TcpListener::getMyAddresses(std::list<char*>* result) {
continue;
}
- char *addr = new char[INET6_ADDRSTRLEN];
-
getnameinfo(current->ai_addr, current->ai_addrlen, addr, INET6_ADDRSTRLEN,
NULL, 0, NI_NUMERICHOST);
- result->push_back(addr);
+ result.push_back(addr);
}
freeaddrinfo(ai);
+
+ return result;
}
int TcpListener::getMyPort() {
@@ -707,7 +710,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) {
return pattern;
}
-char* TcpFilter::patternToStr(const TcpFilter::Pattern& p) {
+std::string TcpFilter::patternToStr(const TcpFilter::Pattern& p) {
char addr[INET6_ADDRSTRLEN + 2];
if (p.address.u.sa.sa_family == AF_INET) {
@@ -739,5 +742,9 @@ char* TcpFilter::patternToStr(const TcpFilter::Pattern& p) {
else
snprintf(result, resultlen, "%c%s/%u", action, addr, p.prefixlen);
- return result;
+ std::string out = result;
+
+ delete [] result;
+
+ return out;
}
diff --git a/common/network/TcpSocket.h b/common/network/TcpSocket.h
index d008f194..c62dd78b 100644
--- a/common/network/TcpSocket.h
+++ b/common/network/TcpSocket.h
@@ -39,6 +39,7 @@
#endif
#include <list>
+#include <string>
/* Tunnelling support. */
#define TUNNEL_PORT_OFFSET 5500
@@ -69,7 +70,7 @@ namespace network {
virtual int getMyPort();
- static void getMyAddresses(std::list<char*>* result);
+ static std::list<std::string> getMyAddresses();
protected:
virtual Socket* createSocket(int fd);
@@ -107,7 +108,7 @@ namespace network {
vnc_sockaddr_t mask; // computed from address and prefix
};
static Pattern parsePattern(const char* s);
- static char* patternToStr(const Pattern& p);
+ static std::string patternToStr(const Pattern& p);
protected:
std::list<Pattern> filter;
};
diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx
index 862c2c95..da036821 100644
--- a/common/rfb/CConnection.cxx
+++ b/common/rfb/CConnection.cxx
@@ -548,7 +548,7 @@ void CConnection::serverCutText(const char* str)
strFree(serverClipboard);
serverClipboard = NULL;
- serverClipboard = latin1ToUTF8(str);
+ serverClipboard = strDup(latin1ToUTF8(str).c_str());
handleClipboardAnnounce(true);
}
@@ -612,7 +612,8 @@ void CConnection::handleClipboardProvide(uint32_t flags,
strFree(serverClipboard);
serverClipboard = NULL;
- serverClipboard = convertLF((const char*)data[0], lengths[0]);
+ std::string filtered(convertLF((const char*)data[0], lengths[0]));
+ serverClipboard = strDup(filtered.c_str());
// FIXME: Should probably verify that this data was actually requested
handleClipboardData(serverClipboard);
@@ -681,9 +682,9 @@ void CConnection::announceClipboard(bool available)
void CConnection::sendClipboardData(const char* data)
{
if (server.clipboardFlags() & rfb::clipboardProvide) {
- CharArray filtered(convertCRLF(data));
- size_t sizes[1] = { strlen(filtered.buf) + 1 };
- const uint8_t* data[1] = { (const uint8_t*)filtered.buf };
+ std::string filtered(convertCRLF(data));
+ size_t sizes[1] = { filtered.size() + 1 };
+ const uint8_t* data[1] = { (const uint8_t*)filtered.c_str() };
if (unsolicitedClipboardAttempt) {
unsolicitedClipboardAttempt = false;
@@ -697,9 +698,9 @@ void CConnection::sendClipboardData(const char* data)
writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, data);
} else {
- CharArray latin1(utf8ToLatin1(data));
+ std::string latin1(utf8ToLatin1(data));
- writer()->writeClientCutText(latin1.buf);
+ writer()->writeClientCutText(latin1.c_str());
}
}
diff --git a/common/rfb/CMsgHandler.cxx b/common/rfb/CMsgHandler.cxx
index 2f91d5a5..f547f0a9 100644
--- a/common/rfb/CMsgHandler.cxx
+++ b/common/rfb/CMsgHandler.cxx
@@ -139,11 +139,8 @@ void CMsgHandler::handleClipboardCaps(uint32_t flags, const uint32_t* lengths)
if (lengths[i] == 0)
vlog.debug(" %s (only notify)", type);
else {
- char bytes[1024];
-
- iecPrefix(lengths[i], "B", bytes, sizeof(bytes));
vlog.debug(" %s (automatically send up to %s)",
- type, bytes);
+ type, iecPrefix(lengths[i], "B").c_str());
}
}
}
diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx
index ba0380fc..42647119 100644
--- a/common/rfb/CMsgReader.cxx
+++ b/common/rfb/CMsgReader.cxx
@@ -277,8 +277,8 @@ bool CMsgReader::readServerCutText()
}
CharArray ca(len);
is->readBytes(ca.buf, len);
- CharArray filtered(convertLF(ca.buf, len));
- handler->serverCutText(filtered.buf);
+ std::string filtered(convertLF(ca.buf, len));
+ handler->serverCutText(filtered.c_str());
return true;
}
diff --git a/common/rfb/CSecurityDH.cxx b/common/rfb/CSecurityDH.cxx
index aab25671..9e67885c 100644
--- a/common/rfb/CSecurityDH.cxx
+++ b/common/rfb/CSecurityDH.cxx
@@ -104,11 +104,12 @@ bool CSecurityDH::readKey()
void CSecurityDH::writeCredentials()
{
- CharArray username;
- CharArray password;
+ std::string username;
+ std::string password;
rdr::RandomStream rs;
- (CSecurity::upg)->getUserPasswd(isSecure(), &username.buf, &password.buf);
+ (CSecurity::upg)->getUserPasswd(isSecure(), &username, &password);
+
std::vector<uint8_t> bBytes(keyLength);
if (!rs.hasData(keyLength))
throw ConnFailedException("failed to generate DH private key");
@@ -133,14 +134,12 @@ void CSecurityDH::writeCredentials()
if (!rs.hasData(128))
throw ConnFailedException("failed to generate random padding");
rs.readBytes(buf, 128);
- size_t len = strlen(username.buf);
- if (len >= 64)
+ if (username.size() >= 64)
throw AuthFailureException("username is too long");
- memcpy(buf, username.buf, len + 1);
- len = strlen(password.buf);
- if (len >= 64)
+ memcpy(buf, username.c_str(), username.size() + 1);
+ if (password.size() >= 64)
throw AuthFailureException("password is too long");
- memcpy(buf + 64, password.buf, len + 1);
+ memcpy(buf + 64, password.c_str(), password.size() + 1);
aes128_encrypt(&aesCtx, 128, (uint8_t *)buf, (uint8_t *)buf);
rdr::OutStream* os = cc->getOutStream();
diff --git a/common/rfb/CSecurityMSLogonII.cxx b/common/rfb/CSecurityMSLogonII.cxx
index 45c43c3f..d7e23715 100644
--- a/common/rfb/CSecurityMSLogonII.cxx
+++ b/common/rfb/CSecurityMSLogonII.cxx
@@ -93,11 +93,12 @@ bool CSecurityMSLogonII::readKey()
void CSecurityMSLogonII::writeCredentials()
{
- CharArray username;
- CharArray password;
+ std::string username;
+ std::string password;
rdr::RandomStream rs;
- (CSecurity::upg)->getUserPasswd(isSecure(), &username.buf, &password.buf);
+ (CSecurity::upg)->getUserPasswd(isSecure(), &username, &password);
+
std::vector<uint8_t> bBytes(8);
if (!rs.hasData(8))
throw ConnFailedException("failed to generate DH private key");
@@ -125,14 +126,12 @@ void CSecurityMSLogonII::writeCredentials()
throw ConnFailedException("failed to generate random padding");
rs.readBytes(user, 256);
rs.readBytes(pass, 64);
- size_t len = strlen(username.buf);
- if (len >= 256)
+ if (username.size() >= 256)
throw AuthFailureException("username is too long");
- memcpy(user, username.buf, len + 1);
- len = strlen(password.buf);
- if (len >= 64)
+ memcpy(user, username.c_str(), username.size() + 1);
+ if (password.size() >= 64)
throw AuthFailureException("password is too long");
- memcpy(pass, password.buf, len + 1);
+ memcpy(pass, password.c_str(), password.size() + 1);
// DES-CBC with the original key as IV, and the reversed one as the DES key
struct CBC_CTX(struct des_ctx, DES_BLOCK_SIZE) ctx;
diff --git a/common/rfb/CSecurityPlain.cxx b/common/rfb/CSecurityPlain.cxx
index 464dfcb5..7b75ef86 100644
--- a/common/rfb/CSecurityPlain.cxx
+++ b/common/rfb/CSecurityPlain.cxx
@@ -24,7 +24,6 @@
#include <rfb/CConnection.h>
#include <rfb/CSecurityPlain.h>
#include <rfb/UserPasswdGetter.h>
-#include <rfb/util.h>
#include <rdr/OutStream.h>
@@ -34,16 +33,16 @@ bool CSecurityPlain::processMsg()
{
rdr::OutStream* os = cc->getOutStream();
- CharArray username;
- CharArray password;
+ std::string username;
+ std::string password;
- (CSecurity::upg)->getUserPasswd(cc->isSecure(), &username.buf, &password.buf);
+ (CSecurity::upg)->getUserPasswd(cc->isSecure(), &username, &password);
// Return the response to the server
- os->writeU32(strlen(username.buf));
- os->writeU32(strlen(password.buf));
- os->writeBytes(username.buf,strlen(username.buf));
- os->writeBytes(password.buf,strlen(password.buf));
+ os->writeU32(username.size());
+ os->writeU32(password.size());
+ os->writeBytes(username.data(), username.size());
+ os->writeBytes(password.data(), password.size());
os->flush();
return true;
}
diff --git a/common/rfb/CSecurityRSAAES.cxx b/common/rfb/CSecurityRSAAES.cxx
index b1c273a4..f48e2523 100644
--- a/common/rfb/CSecurityRSAAES.cxx
+++ b/common/rfb/CSecurityRSAAES.cxx
@@ -433,29 +433,26 @@ bool CSecurityRSAAES::readSubtype()
void CSecurityRSAAES::writeCredentials()
{
- CharArray username;
- CharArray password;
+ std::string username;
+ std::string password;
- (CSecurity::upg)->getUserPasswd(
- isSecure(),
- subtype == secTypeRA2UserPass ? &username.buf : NULL, &password.buf
- );
- size_t len;
- if (username.buf) {
- len = strlen(username.buf);
- if (len > 255)
+ if (subtype == secTypeRA2UserPass)
+ (CSecurity::upg)->getUserPasswd(isSecure(), &username, &password);
+ else
+ (CSecurity::upg)->getUserPasswd(isSecure(), NULL, &password);
+
+ if (subtype == secTypeRA2UserPass) {
+ if (username.size() > 255)
throw AuthFailureException("username is too long");
- raos->writeU8(len);
- if (len)
- raos->writeBytes(username.buf, len);
+ raos->writeU8(username.size());
+ raos->writeBytes(username.data(), username.size());
} else {
raos->writeU8(0);
}
- len = strlen(password.buf);
- if (len > 255)
+
+ if (password.size() > 255)
throw AuthFailureException("password is too long");
- raos->writeU8(len);
- if (len)
- raos->writeBytes(password.buf, len);
+ raos->writeU8(password.size());
+ raos->writeBytes(password.data(), password.size());
raos->flush();
}
diff --git a/common/rfb/CSecurityVncAuth.cxx b/common/rfb/CSecurityVncAuth.cxx
index 41eb5484..875e088a 100644
--- a/common/rfb/CSecurityVncAuth.cxx
+++ b/common/rfb/CSecurityVncAuth.cxx
@@ -29,7 +29,6 @@
#include <stdio.h>
#include <rfb/CConnection.h>
-#include <rfb/Password.h>
#include <rfb/CSecurityVncAuth.h>
#include <rfb/util.h>
#include <rfb/Security.h>
@@ -55,14 +54,13 @@ bool CSecurityVncAuth::processMsg()
// Read the challenge & obtain the user's password
uint8_t challenge[vncAuthChallengeSize];
is->readBytes(challenge, vncAuthChallengeSize);
- PlainPasswd passwd;
- (CSecurity::upg)->getUserPasswd(cc->isSecure(), 0, &passwd.buf);
+ std::string passwd;
+ (CSecurity::upg)->getUserPasswd(cc->isSecure(), 0, &passwd);
// Calculate the correct response
uint8_t key[8];
- int pwdLen = strlen(passwd.buf);
- for (int i=0; i<8; i++)
- key[i] = i<pwdLen ? passwd.buf[i] : 0;
+ for (size_t i=0; i<8; i++)
+ key[i] = i<passwd.size() ? passwd[i] : 0;
deskey(key, EN0);
for (int j = 0; j < vncAuthChallengeSize; j += 8)
des(challenge+j, challenge+j);
diff --git a/common/rfb/ComparingUpdateTracker.cxx b/common/rfb/ComparingUpdateTracker.cxx
index 85065d7e..c8d69b78 100644
--- a/common/rfb/ComparingUpdateTracker.cxx
+++ b/common/rfb/ComparingUpdateTracker.cxx
@@ -253,14 +253,12 @@ void ComparingUpdateTracker::compareRect(const Rect& r, Region* newChanged)
void ComparingUpdateTracker::logStats()
{
double ratio;
- char a[1024], b[1024];
-
- siPrefix(totalPixels, "pixels", a, sizeof(a));
- siPrefix(missedPixels, "pixels", b, sizeof(b));
ratio = (double)totalPixels / missedPixels;
- vlog.info("%s in / %s out", a, b);
+ vlog.info("%s in / %s out",
+ siPrefix(totalPixels, "pixels").c_str(),
+ siPrefix(missedPixels, "pixels").c_str());
vlog.info("(1:%g ratio)", ratio);
totalPixels = missedPixels = 0;
diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx
index 1d4c7a45..9cbfa53d 100644
--- a/common/rfb/Configuration.cxx
+++ b/common/rfb/Configuration.cxx
@@ -135,7 +135,7 @@ void Configuration::list(int width, int nameWidth) {
fprintf(stderr, "%s Parameters:\n", name.buf);
while (current) {
- char* def_str = current->getDefaultStr();
+ std::string def_str = current->getDefaultStr();
const char* desc = current->getDescription();
fprintf(stderr," %-*s -", nameWidth, current->getName());
int column = strlen(current->getName());
@@ -157,11 +157,10 @@ void Configuration::list(int width, int nameWidth) {
if (!s) break;
}
- if (def_str) {
- if (column + (int)strlen(def_str) + 11 > width)
+ if (!def_str.empty()) {
+ if (column + (int)def_str.size() + 11 > width)
fprintf(stderr,"\n%*s",nameWidth+4,"");
- fprintf(stderr," (default=%s)\n",def_str);
- strFree(def_str);
+ fprintf(stderr," (default=%s)\n",def_str.c_str());
} else {
fprintf(stderr,"\n");
}
@@ -257,12 +256,11 @@ bool AliasParameter::setParam() {
return param->setParam();
}
-char*
-AliasParameter::getDefaultStr() const {
- return 0;
+std::string AliasParameter::getDefaultStr() const {
+ return "";
}
-char* AliasParameter::getValueStr() const {
+std::string AliasParameter::getValueStr() const {
return param->getValueStr();
}
@@ -313,13 +311,12 @@ void BoolParameter::setParam(bool b) {
vlog.debug("set %s(Bool) to %d", getName(), value);
}
-char*
-BoolParameter::getDefaultStr() const {
- return strDup(def_value ? "1" : "0");
+std::string BoolParameter::getDefaultStr() const {
+ return def_value ? "1" : "0";
}
-char* BoolParameter::getValueStr() const {
- return strDup(value ? "1" : "0");
+std::string BoolParameter::getValueStr() const {
+ return value ? "1" : "0";
}
bool BoolParameter::isBool() const {
@@ -355,15 +352,14 @@ IntParameter::setParam(int v) {
return true;
}
-char*
-IntParameter::getDefaultStr() const {
- char* result = new char[16];
+std::string IntParameter::getDefaultStr() const {
+ char result[16];
sprintf(result, "%d", def_value);
return result;
}
-char* IntParameter::getValueStr() const {
- char* result = new char[16];
+std::string IntParameter::getValueStr() const {
+ char result[16];
sprintf(result, "%d", value);
return result;
}
@@ -400,13 +396,13 @@ bool StringParameter::setParam(const char* v) {
return value != 0;
}
-char* StringParameter::getDefaultStr() const {
- return strDup(def_value);
+std::string StringParameter::getDefaultStr() const {
+ return def_value;
}
-char* StringParameter::getValueStr() const {
+std::string StringParameter::getValueStr() const {
LOCK_CONFIG;
- return strDup(value);
+ return std::string(value);
}
StringParameter::operator const char *() const {
@@ -457,11 +453,11 @@ void BinaryParameter::setParam(const uint8_t* v, size_t len) {
}
}
-char* BinaryParameter::getDefaultStr() const {
+std::string BinaryParameter::getDefaultStr() const {
return binToHex(def_value, def_length);
}
-char* BinaryParameter::getValueStr() const {
+std::string BinaryParameter::getValueStr() const {
LOCK_CONFIG;
return binToHex(value, length);
}
diff --git a/common/rfb/Configuration.h b/common/rfb/Configuration.h
index 318b6b8d..20552364 100644
--- a/common/rfb/Configuration.h
+++ b/common/rfb/Configuration.h
@@ -171,8 +171,8 @@ namespace rfb {
virtual bool setParam(const char* value) = 0;
virtual bool setParam();
- virtual char* getDefaultStr() const = 0;
- virtual char* getValueStr() const = 0;
+ virtual std::string getDefaultStr() const = 0;
+ virtual std::string getValueStr() const = 0;
virtual bool isBool() const;
virtual void setImmutable();
@@ -195,8 +195,8 @@ namespace rfb {
ConfigurationObject co=ConfGlobal);
virtual bool setParam(const char* value);
virtual bool setParam();
- virtual char* getDefaultStr() const;
- virtual char* getValueStr() const;
+ virtual std::string getDefaultStr() const;
+ virtual std::string getValueStr() const;
virtual bool isBool() const;
virtual void setImmutable();
private:
@@ -210,8 +210,8 @@ namespace rfb {
virtual bool setParam(const char* value);
virtual bool setParam();
virtual void setParam(bool b);
- virtual char* getDefaultStr() const;
- virtual char* getValueStr() const;
+ virtual std::string getDefaultStr() const;
+ virtual std::string getValueStr() const;
virtual bool isBool() const;
operator bool() const;
protected:
@@ -227,8 +227,8 @@ namespace rfb {
using VoidParameter::setParam;
virtual bool setParam(const char* value);
virtual bool setParam(int v);
- virtual char* getDefaultStr() const;
- virtual char* getValueStr() const;
+ virtual std::string getDefaultStr() const;
+ virtual std::string getValueStr() const;
operator int() const;
protected:
int value;
@@ -244,13 +244,9 @@ namespace rfb {
ConfigurationObject co=ConfGlobal);
virtual ~StringParameter();
virtual bool setParam(const char* value);
- virtual char* getDefaultStr() const;
- virtual char* getValueStr() const;
+ virtual std::string getDefaultStr() const;
+ virtual std::string getValueStr() const;
operator const char*() const;
-
- // getData() returns a copy of the data - it must be delete[]d by the
- // caller.
- char* getData() const { return getValueStr(); }
protected:
char* value;
char* def_value;
@@ -265,8 +261,8 @@ namespace rfb {
virtual ~BinaryParameter();
virtual bool setParam(const char* value);
virtual void setParam(const uint8_t* v, size_t l);
- virtual char* getDefaultStr() const;
- virtual char* getValueStr() const;
+ virtual std::string getDefaultStr() const;
+ virtual std::string getValueStr() const;
std::vector<uint8_t> getData() const;
diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx
index b9faf689..b6dd81f4 100644
--- a/common/rfb/DecodeManager.cxx
+++ b/common/rfb/DecodeManager.cxx
@@ -211,8 +211,6 @@ void DecodeManager::logStats()
double ratio;
- char a[1024], b[1024];
-
rects = 0;
pixels = bytes = equivalent = 0;
@@ -228,22 +226,21 @@ void DecodeManager::logStats()
ratio = (double)stats[i].equivalent / stats[i].bytes;
- siPrefix(stats[i].rects, "rects", a, sizeof(a));
- siPrefix(stats[i].pixels, "pixels", b, sizeof(b));
- vlog.info(" %s: %s, %s", encodingName(i), a, b);
- iecPrefix(stats[i].bytes, "B", a, sizeof(a));
+ vlog.info(" %s: %s, %s", encodingName(i),
+ siPrefix(stats[i].rects, "rects").c_str(),
+ siPrefix(stats[i].pixels, "pixels").c_str());
vlog.info(" %*s %s (1:%g ratio)",
(int)strlen(encodingName(i)), "",
- a, ratio);
+ iecPrefix(stats[i].bytes, "B").c_str(), ratio);
}
ratio = (double)equivalent / bytes;
- siPrefix(rects, "rects", a, sizeof(a));
- siPrefix(pixels, "pixels", b, sizeof(b));
- vlog.info(" Total: %s, %s", a, b);
- iecPrefix(bytes, "B", a, sizeof(a));
- vlog.info(" %s (1:%g ratio)", a, ratio);
+ vlog.info(" Total: %s, %s",
+ siPrefix(rects, "rects").c_str(),
+ siPrefix(pixels, "pixels").c_str());
+ vlog.info(" %s (1:%g ratio)",
+ iecPrefix(bytes, "B").c_str(), ratio);
}
void DecodeManager::setThreadException(const rdr::Exception& e)
diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx
index a955a2c1..e2571cab 100644
--- a/common/rfb/EncodeManager.cxx
+++ b/common/rfb/EncodeManager.cxx
@@ -177,8 +177,6 @@ void EncodeManager::logStats()
double ratio;
- char a[1024], b[1024];
-
rects = 0;
pixels = bytes = equivalent = 0;
@@ -194,13 +192,12 @@ void EncodeManager::logStats()
ratio = (double)copyStats.equivalent / copyStats.bytes;
- siPrefix(copyStats.rects, "rects", a, sizeof(a));
- siPrefix(copyStats.pixels, "pixels", b, sizeof(b));
- vlog.info(" %s: %s, %s", "Copies", a, b);
- iecPrefix(copyStats.bytes, "B", a, sizeof(a));
+ vlog.info(" %s: %s, %s", "Copies",
+ siPrefix(copyStats.rects, "rects").c_str(),
+ siPrefix(copyStats.pixels, "pixels").c_str());
vlog.info(" %*s %s (1:%g ratio)",
(int)strlen("Copies"), "",
- a, ratio);
+ iecPrefix(copyStats.bytes, "B").c_str(), ratio);
}
for (i = 0;i < stats.size();i++) {
@@ -225,23 +222,22 @@ void EncodeManager::logStats()
ratio = (double)stats[i][j].equivalent / stats[i][j].bytes;
- siPrefix(stats[i][j].rects, "rects", a, sizeof(a));
- siPrefix(stats[i][j].pixels, "pixels", b, sizeof(b));
- vlog.info(" %s: %s, %s", encoderTypeName((EncoderType)j), a, b);
- iecPrefix(stats[i][j].bytes, "B", a, sizeof(a));
+ vlog.info(" %s: %s, %s", encoderTypeName((EncoderType)j),
+ siPrefix(stats[i][j].rects, "rects").c_str(),
+ siPrefix(stats[i][j].pixels, "pixels").c_str());
vlog.info(" %*s %s (1:%g ratio)",
(int)strlen(encoderTypeName((EncoderType)j)), "",
- a, ratio);
+ iecPrefix(stats[i][j].bytes, "B").c_str(), ratio);
}
}
ratio = (double)equivalent / bytes;
- siPrefix(rects, "rects", a, sizeof(a));
- siPrefix(pixels, "pixels", b, sizeof(b));
- vlog.info(" Total: %s, %s", a, b);
- iecPrefix(bytes, "B", a, sizeof(a));
- vlog.info(" %s (1:%g ratio)", a, ratio);
+ vlog.info(" Total: %s, %s",
+ siPrefix(rects, "rects").c_str(),
+ siPrefix(pixels, "pixels").c_str());
+ vlog.info(" %s (1:%g ratio)",
+ iecPrefix(bytes, "B").c_str(), ratio);
}
bool EncodeManager::supported(int encoding)
diff --git a/common/rfb/Hostname.h b/common/rfb/Hostname.h
index 341f69e1..8e57f31d 100644
--- a/common/rfb/Hostname.h
+++ b/common/rfb/Hostname.h
@@ -38,7 +38,9 @@ namespace rfb {
return true;
}
- static void getHostAndPort(const char* hi, char** host, int* port, int basePort=5900) {
+ static void getHostAndPort(const char* hi, std::string* host,
+ int* port, int basePort=5900)
+ {
const char* hostStart;
const char* hostEnd;
const char* portStart;
@@ -86,14 +88,9 @@ namespace rfb {
hostEnd--;
if (hostStart == hostEnd)
- *host = strDup("localhost");
- else {
- size_t len;
- len = hostEnd - hostStart + 1;
- *host = new char[len];
- strncpy(*host, hostStart, len-1);
- (*host)[len-1] = '\0';
- }
+ *host = "localhost";
+ else
+ *host = std::string(hostStart, hostEnd - hostStart);
if (portStart == NULL)
*port = basePort;
diff --git a/common/rfb/LogWriter.cxx b/common/rfb/LogWriter.cxx
index 6df82d8e..a86e9652 100644
--- a/common/rfb/LogWriter.cxx
+++ b/common/rfb/LogWriter.cxx
@@ -123,7 +123,7 @@ bool LogParameter::setParam(const char* v) {
LogWriter::setLogParams("*::0");
StringParameter::setParam(v);
CharArray logParam;
- CharArray params(getData());
+ CharArray params(strDup(getValueStr().c_str()));
while (params.buf) {
strSplit(params.buf, ',', &logParam.buf, &params.buf);
if (strlen(logParam.buf) && !LogWriter::setLogParams(logParam.buf))
diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx
index a30e9187..211fbd98 100644
--- a/common/rfb/SConnection.cxx
+++ b/common/rfb/SConnection.cxx
@@ -384,7 +384,7 @@ void SConnection::clientCutText(const char* str)
strFree(clientClipboard);
clientClipboard = NULL;
- clientClipboard = latin1ToUTF8(str);
+ clientClipboard = strDup(latin1ToUTF8(str).c_str());
handleClipboardAnnounce(true);
}
@@ -433,7 +433,8 @@ void SConnection::handleClipboardProvide(uint32_t flags,
strFree(clientClipboard);
clientClipboard = NULL;
- clientClipboard = convertLF((const char*)data[0], lengths[0]);
+ std::string filtered(convertLF((const char*)data[0], lengths[0]));
+ clientClipboard = strDup(filtered.c_str());
// FIXME: Should probably verify that this data was actually requested
handleClipboardData(clientClipboard);
@@ -594,9 +595,9 @@ void SConnection::sendClipboardData(const char* data)
{
if (client.supportsEncoding(pseudoEncodingExtendedClipboard) &&
(client.clipboardFlags() & rfb::clipboardProvide)) {
- CharArray filtered(convertCRLF(data));
- size_t sizes[1] = { strlen(filtered.buf) + 1 };
- const uint8_t* data[1] = { (const uint8_t*)filtered.buf };
+ std::string filtered(convertCRLF(data));
+ size_t sizes[1] = { filtered.size() + 1 };
+ const uint8_t* data[1] = { (const uint8_t*)filtered.c_str() };
if (unsolicitedClipboardAttempt) {
unsolicitedClipboardAttempt = false;
@@ -610,9 +611,9 @@ void SConnection::sendClipboardData(const char* data)
writer()->writeClipboardProvide(rfb::clipboardUTF8, sizes, data);
} else {
- CharArray latin1(utf8ToLatin1(data));
+ std::string latin1(utf8ToLatin1(data));
- writer()->writeServerCutText(latin1.buf);
+ writer()->writeServerCutText(latin1.c_str());
}
}
diff --git a/common/rfb/SMsgHandler.cxx b/common/rfb/SMsgHandler.cxx
index 3eccd92d..092d9f7e 100644
--- a/common/rfb/SMsgHandler.cxx
+++ b/common/rfb/SMsgHandler.cxx
@@ -106,11 +106,8 @@ void SMsgHandler::handleClipboardCaps(uint32_t flags, const uint32_t* lengths)
if (lengths[i] == 0)
vlog.debug(" %s (only notify)", type);
else {
- char bytes[1024];
-
- iecPrefix(lengths[i], "B", bytes, sizeof(bytes));
vlog.debug(" %s (automatically send up to %s)",
- type, bytes);
+ type, iecPrefix(lengths[i], "B").c_str());
}
}
}
diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx
index 5ff07e23..3fddf302 100644
--- a/common/rfb/SMsgReader.cxx
+++ b/common/rfb/SMsgReader.cxx
@@ -316,8 +316,8 @@ bool SMsgReader::readClientCutText()
CharArray ca(len);
is->readBytes(ca.buf, len);
- CharArray filtered(convertLF(ca.buf, len));
- handler->clientCutText(filtered.buf);
+ std::string filtered(convertLF(ca.buf, len));
+ handler->clientCutText(filtered.c_str());
return true;
}
diff --git a/common/rfb/SSecurityPlain.cxx b/common/rfb/SSecurityPlain.cxx
index ab3a2391..018ca517 100644
--- a/common/rfb/SSecurityPlain.cxx
+++ b/common/rfb/SSecurityPlain.cxx
@@ -45,7 +45,8 @@ StringParameter PasswordValidator::plainUsers
bool PasswordValidator::validUser(const char* username)
{
- CharArray users(plainUsers.getValueStr()), user;
+ CharArray users(strDup(plainUsers.getValueStr().c_str()));
+ CharArray user;
while (users.buf) {
strSplit(users.buf, ',', &user.buf, &users.buf);
diff --git a/common/rfb/UserPasswdGetter.h b/common/rfb/UserPasswdGetter.h
index 27775cc3..db7df396 100644
--- a/common/rfb/UserPasswdGetter.h
+++ b/common/rfb/UserPasswdGetter.h
@@ -17,16 +17,20 @@
*/
#ifndef __RFB_USERPASSWDGETTER_H__
#define __RFB_USERPASSWDGETTER_H__
+
+#include <string>
+
namespace rfb {
class UserPasswdGetter {
public:
// getUserPasswd gets the username and password. This might involve a
// dialog, getpass(), etc. The user buffer pointer can be null, in which
- // case no user name will be retrieved. The caller MUST delete [] the
- // result(s).
- virtual void getUserPasswd(bool secure, char** user, char** password)=0;
+ // case no user name will be retrieved.
+ virtual void getUserPasswd(bool secure, std::string* user,
+ std::string* password)=0;
virtual ~UserPasswdGetter() {}
};
}
+
#endif
diff --git a/common/rfb/util.cxx b/common/rfb/util.cxx
index d1ba9200..30cf0300 100644
--- a/common/rfb/util.cxx
+++ b/common/rfb/util.cxx
@@ -66,10 +66,6 @@ namespace rfb {
delete [] s;
}
- void strFree(wchar_t* s) {
- delete [] s;
- }
-
bool strSplit(const char* src, const char limiter, char** out1, char** out2, bool fromEnd) {
CharArray out1old, out2old;
@@ -139,9 +135,12 @@ namespace rfb {
}
}
- char* binToHex(const uint8_t* in, size_t inlen) {
- char* out = new char[inlen*2+1]();
- binToHex(in, inlen, out, inlen*2);
+ std::string binToHex(const uint8_t* in, size_t inlen) {
+ char* buffer = new char[inlen*2+1]();
+ std::string out;
+ binToHex(in, inlen, buffer, inlen*2);
+ out = buffer;
+ delete [] buffer;
return out;
}
@@ -185,19 +184,16 @@ namespace rfb {
return out;
}
- char* convertLF(const char* src, size_t bytes)
+ std::string convertLF(const char* src, size_t bytes)
{
- char* buffer;
size_t sz;
+ std::string out;
- char* out;
const char* in;
size_t in_len;
- // Always include space for a NULL
- sz = 1;
-
// Compute output size
+ sz = 0;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
@@ -215,44 +211,39 @@ namespace rfb {
in_len--;
}
- // Alloc
- buffer = new char[sz];
- memset(buffer, 0, sz);
+ // Reserve space
+ out.reserve(sz);
// And convert
- out = buffer;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
if (*in != '\r') {
- *out++ = *in++;
+ out += *in++;
in_len--;
continue;
}
if ((in_len < 2) || (*(in+1) != '\n'))
- *out++ = '\n';
+ out += '\n';
in++;
in_len--;
}
- return buffer;
+ return out;
}
- char* convertCRLF(const char* src, size_t bytes)
+ std::string convertCRLF(const char* src, size_t bytes)
{
- char* buffer;
+ std::string out;
size_t sz;
- char* out;
const char* in;
size_t in_len;
- // Always include space for a NULL
- sz = 1;
-
// Compute output size
+ sz = 0;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
@@ -270,35 +261,30 @@ namespace rfb {
in_len--;
}
- // Alloc
- buffer = new char[sz];
- memset(buffer, 0, sz);
+ // Reserve space
+ out.reserve(sz);
// And convert
- out = buffer;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
if (*in == '\n') {
if ((in == src) || (*(in-1) != '\r'))
- *out++ = '\r';
+ out += '\r';
}
- *out = *in;
+ out += *in;
if (*in == '\r') {
- if ((in_len < 2) || (*(in+1) != '\n')) {
- out++;
- *out = '\n';
- }
+ if ((in_len < 2) || (*(in+1) != '\n'))
+ out += '\n';
}
- out++;
in++;
in_len--;
}
- return buffer;
+ return out;
}
size_t ucs4ToUTF8(unsigned src, char dst[5]) {
@@ -438,18 +424,15 @@ namespace rfb {
return 2;
}
- char* latin1ToUTF8(const char* src, size_t bytes) {
- char* buffer;
+ std::string latin1ToUTF8(const char* src, size_t bytes) {
+ std::string out;
size_t sz;
- char* out;
const char* in;
size_t in_len;
- // Always include space for a NULL
- sz = 1;
-
// Compute output size
+ sz = 0;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
@@ -459,35 +442,32 @@ namespace rfb {
in_len--;
}
- // Alloc
- buffer = new char[sz];
- memset(buffer, 0, sz);
+ // Reserve space
+ out.reserve(sz);
// And convert
- out = buffer;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
- out += ucs4ToUTF8(*(const unsigned char*)in, out);
+ char buf[5];
+ ucs4ToUTF8(*(const unsigned char*)in, buf);
+ out += buf;
in++;
in_len--;
}
- return buffer;
+ return out;
}
- char* utf8ToLatin1(const char* src, size_t bytes) {
- char* buffer;
+ std::string utf8ToLatin1(const char* src, size_t bytes) {
+ std::string out;
size_t sz;
- char* out;
const char* in;
size_t in_len;
- // Always include space for a NULL
- sz = 1;
-
// Compute output size
+ sz = 0;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
@@ -500,12 +480,10 @@ namespace rfb {
sz++;
}
- // Alloc
- buffer = new char[sz];
- memset(buffer, 0, sz);
+ // Reserve space
+ out.reserve(sz);
// And convert
- out = buffer;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
@@ -517,27 +495,24 @@ namespace rfb {
in_len -= len;
if (ucs > 0xff)
- *out++ = '?';
+ out += '?';
else
- *out++ = (unsigned char)ucs;
+ out += (unsigned char)ucs;
}
- return buffer;
+ return out;
}
- char* utf16ToUTF8(const wchar_t* src, size_t units)
+ std::string utf16ToUTF8(const wchar_t* src, size_t units)
{
- char* buffer;
+ std::string out;
size_t sz;
- char* out;
const wchar_t* in;
size_t in_len;
- // Always include space for a NULL
- sz = 1;
-
// Compute output size
+ sz = 0;
in = src;
in_len = units;
while ((in_len > 0) && (*in != '\0')) {
@@ -552,41 +527,38 @@ namespace rfb {
sz += ucs4ToUTF8(ucs, buf);
}
- // Alloc
- buffer = new char[sz];
- memset(buffer, 0, sz);
+ // Reserve space
+ out.reserve(sz);
// And convert
- out = buffer;
in = src;
in_len = units;
while ((in_len > 0) && (*in != '\0')) {
size_t len;
unsigned ucs;
+ char buf[5];
len = utf16ToUCS4(in, in_len, &ucs);
in += len;
in_len -= len;
- out += ucs4ToUTF8(ucs, out);
+ ucs4ToUTF8(ucs, buf);
+ out += buf;
}
- return buffer;
+ return out;
}
- wchar_t* utf8ToUTF16(const char* src, size_t bytes)
+ std::wstring utf8ToUTF16(const char* src, size_t bytes)
{
- wchar_t* buffer;
+ std::wstring out;
size_t sz;
- wchar_t* out;
const char* in;
size_t in_len;
- // Always include space for a NULL
- sz = 1;
-
// Compute output size
+ sz = 0;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
@@ -601,26 +573,26 @@ namespace rfb {
sz += ucs4ToUTF16(ucs, buf);
}
- // Alloc
- buffer = new wchar_t[sz];
- memset(buffer, 0, sz * sizeof(wchar_t));
+ // Reserve space
+ out.reserve(sz);
// And convert
- out = buffer;
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
size_t len;
unsigned ucs;
+ wchar_t buf[3];
len = utf8ToUCS4(in, in_len, &ucs);
in += len;
in_len -= len;
- out += ucs4ToUTF16(ucs, out);
+ ucs4ToUTF16(ucs, buf);
+ out += buf;
}
- return buffer;
+ return out;
}
unsigned msBetween(const struct timeval *first,
@@ -657,12 +629,12 @@ namespace rfb {
return false;
}
- static size_t doPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen,
- unsigned divisor, const char **prefixes,
- size_t prefixCount, int precision) {
+ static std::string doPrefix(long long value, const char *unit,
+ unsigned divisor, const char **prefixes,
+ size_t prefixCount, int precision) {
+ char buffer[256];
double newValue;
- size_t prefix, len;
+ size_t prefix;
newValue = value;
prefix = 0;
@@ -673,11 +645,11 @@ namespace rfb {
prefix++;
}
- len = snprintf(buffer, maxlen, "%.*g %s%s", precision, newValue,
- (prefix == 0) ? "" : prefixes[prefix-1], unit);
- buffer[maxlen-1] = '\0';
+ snprintf(buffer, sizeof(buffer), "%.*g %s%s", precision, newValue,
+ (prefix == 0) ? "" : prefixes[prefix-1], unit);
+ buffer[sizeof(buffer)-1] = '\0';
- return len;
+ return buffer;
}
static const char *siPrefixes[] =
@@ -685,16 +657,16 @@ namespace rfb {
static const char *iecPrefixes[] =
{ "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
- size_t siPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen, int precision) {
- return doPrefix(value, unit, buffer, maxlen, 1000, siPrefixes,
+ std::string siPrefix(long long value, const char *unit,
+ int precision) {
+ return doPrefix(value, unit, 1000, siPrefixes,
sizeof(siPrefixes)/sizeof(*siPrefixes),
precision);
}
- size_t iecPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen, int precision) {
- return doPrefix(value, unit, buffer, maxlen, 1024, iecPrefixes,
+ std::string iecPrefix(long long value, const char *unit,
+ int precision) {
+ return doPrefix(value, unit, 1024, iecPrefixes,
sizeof(iecPrefixes)/sizeof(*iecPrefixes),
precision);
}
diff --git a/common/rfb/util.h b/common/rfb/util.h
index e7d716fe..d8d7c653 100644
--- a/common/rfb/util.h
+++ b/common/rfb/util.h
@@ -28,6 +28,7 @@
#include <string.h>
#include <stdint.h>
+#include <string>
#include <vector>
struct timeval;
@@ -59,7 +60,6 @@ namespace rfb {
char* strDup(const char* s);
void strFree(char* s);
- void strFree(wchar_t* s);
// Returns true if split successful. Returns false otherwise.
// ALWAYS *copies* first part of string to out1 buffer.
@@ -79,17 +79,16 @@ namespace rfb {
// Conversion to and from a hex string
void binToHex(const uint8_t* in, size_t inlen, char* out, size_t outlen);
- char* binToHex(const uint8_t* in, size_t inlen);
+ std::string binToHex(const uint8_t* in, size_t inlen);
bool hexToBin(const char* in, size_t inlen, uint8_t* out, size_t outlen);
std::vector<uint8_t> hexToBin(const char* in, size_t inlen);
// Makes sure line endings are in a certain format
- char* convertLF(const char* src, size_t bytes = (size_t)-1);
- char* convertCRLF(const char* src, size_t bytes = (size_t)-1);
+ std::string convertLF(const char* src, size_t bytes = (size_t)-1);
+ std::string convertCRLF(const char* src, size_t bytes = (size_t)-1);
- // Convertions between various Unicode formats. The returned strings are
- // always null terminated and must be freed using strFree().
+ // Convertions between various Unicode formats
size_t ucs4ToUTF8(unsigned src, char dst[5]);
size_t utf8ToUCS4(const char* src, size_t max, unsigned* dst);
@@ -97,11 +96,11 @@ namespace rfb {
size_t ucs4ToUTF16(unsigned src, wchar_t dst[3]);
size_t utf16ToUCS4(const wchar_t* src, size_t max, unsigned* dst);
- char* latin1ToUTF8(const char* src, size_t bytes = (size_t)-1);
- char* utf8ToLatin1(const char* src, size_t bytes = (size_t)-1);
+ std::string latin1ToUTF8(const char* src, size_t bytes = (size_t)-1);
+ std::string utf8ToLatin1(const char* src, size_t bytes = (size_t)-1);
- char* utf16ToUTF8(const wchar_t* src, size_t units = (size_t)-1);
- wchar_t* utf8ToUTF16(const char* src, size_t bytes = (size_t)-1);
+ std::string utf16ToUTF8(const wchar_t* src, size_t units = (size_t)-1);
+ std::wstring utf8ToUTF16(const char* src, size_t bytes = (size_t)-1);
// HELPER functions for timeout handling
@@ -129,10 +128,10 @@ namespace rfb {
bool isBefore(const struct timeval *first,
const struct timeval *second);
- size_t siPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen, int precision=6);
- size_t iecPrefix(long long value, const char *unit,
- char *buffer, size_t maxlen, int precision=6);
+ std::string siPrefix(long long value, const char *unit,
+ int precision=6);
+ std::string iecPrefix(long long value, const char *unit,
+ int precision=6);
}
// Some platforms (e.g. Windows) include max() and min() macros in their