bool BinaryParameter::setParam(const char* v) {
if (immutable) return true;
- uint8_t *newValue = hexToBin(v, strlen(v));
- if (newValue == NULL)
+ std::vector<uint8_t> newValue = hexToBin(v, strlen(v));
+ if (newValue.empty() && strlen(v) > 0)
return false;
- setParam(newValue, strlen(v)/2);
- delete [] newValue;
+ setParam(newValue.data(), newValue.size());
return true;
}
return binToHex(value, length);
}
-void BinaryParameter::getData(uint8_t** data_, size_t* length_) const {
+std::vector<uint8_t> BinaryParameter::getData() const {
LOCK_CONFIG;
- if (length_) *length_ = length;
- if (data_) {
- *data_ = new uint8_t[length];
- memcpy(*data_, value, length);
- }
+ std::vector<uint8_t> out(length);
+ memcpy(out.data(), value, length);
+ return out;
}
#ifndef __RFB_CONFIGURATION_H__
#define __RFB_CONFIGURATION_H__
+#include <vector>
+
#include <rfb/util.h>
namespace os { class Mutex; }
virtual char* getDefaultStr() const;
virtual char* getValueStr() const;
- // getData() will return length zero if there is no data
- // NB: data may be set to zero, OR set to a zero-length buffer
- void getData(uint8_t** data, size_t* length) const;
+ std::vector<uint8_t> getData() const;
protected:
uint8_t* value;
void VncAuthPasswdParameter::getVncAuthPasswd(PlainPasswd *password, PlainPasswd *readOnlyPassword) {
ObfuscatedPasswd obfuscated, obfuscatedReadOnly;
- getData((uint8_t**)&obfuscated.buf, &obfuscated.length);
+ std::vector<uint8_t> data = getData();
+ obfuscated.length = data.size();
+ if (!data.empty()) {
+ obfuscated.buf = new char[data.size()];
+ memcpy(obfuscated.buf, data.data(), data.size());
+ }
if (obfuscated.length == 0) {
if (passwdFile) {
return true;
}
- uint8_t* hexToBin(const char* in, size_t inlen) {
- uint8_t* out = new uint8_t[inlen/2];
- if (!hexToBin(in, inlen, out, inlen/2)) {
- delete [] out;
- return NULL;
- }
+ std::vector<uint8_t> hexToBin(const char* in, size_t inlen) {
+ std::vector<uint8_t> out(inlen/2);
+ if (!hexToBin(in, inlen, out.data(), inlen/2))
+ return std::vector<uint8_t>();
return out;
}
#include <string.h>
#include <stdint.h>
+#include <vector>
+
struct timeval;
namespace rfb {
void binToHex(const uint8_t* in, size_t inlen, char* out, size_t outlen);
char* binToHex(const uint8_t* in, size_t inlen);
bool hexToBin(const char* in, size_t inlen, uint8_t* out, size_t outlen);
- uint8_t* hexToBin(const char* in, size_t inlen);
+ std::vector<uint8_t> hexToBin(const char* in, size_t inlen);
// Makes sure line endings are in a certain format
}
}
-void RegKey::getBinary(const TCHAR* valname, void** data, size_t* length) const {
+std::vector<uint8_t> RegKey::getBinary(const TCHAR* valname) const {
TCharArray hex(getRepresentation(valname));
- *data = hexToBin(CStr(hex.buf), strlen(CStr(hex.buf)));
- *length = strlen(CStr(hex.buf))/2;
- if (*data == NULL)
- throw rdr::Exception("getBinary failed");
+ return hexToBin(CStr(hex.buf), strlen(CStr(hex.buf)));
}
-void RegKey::getBinary(const TCHAR* valname, void** data, size_t* length, void* def, size_t deflen) const {
+std::vector<uint8_t> RegKey::getBinary(const TCHAR* valname, const uint8_t* def, size_t deflen) const {
try {
- getBinary(valname, data, length);
+ return getBinary(valname);
} catch(rdr::Exception&) {
- if (deflen) {
- *data = new char[deflen];
- memcpy(*data, def, deflen);
- } else
- *data = 0;
- *length = deflen;
+ std::vector<uint8_t> out(deflen);
+ memcpy(out.data(), def, deflen);
+ return out;
}
}
TCHAR* getString(const TCHAR* valname) const;
TCHAR* getString(const TCHAR* valname, const TCHAR* def) const;
- void getBinary(const TCHAR* valname, void** data, size_t* length) const;
- void getBinary(const TCHAR* valname, void** data, size_t* length, void* def, size_t deflength) const;
+ std::vector<uint8_t> getBinary(const TCHAR* valname) const;
+ std::vector<uint8_t> getBinary(const TCHAR* valname, const uint8_t* def, size_t deflength) const;
int getInt(const TCHAR* valname) const;
int getInt(const TCHAR* valname, int def) const;
#include <vncconfig/Legacy.h>
#include <rfb/LogWriter.h>
-#include <rfb/Password.h>
#include <rfb_win32/CurrentUser.h>
using namespace rfb;
}
regKey.setInt(_T("QueryTimeout"), key.getInt(_T("QueryTimeout"), 10));
- ObfuscatedPasswd passwd;
- key.getBinary(_T("Password"), (void**)&passwd.buf, &passwd.length, 0, 0);
- regKey.setBinary(_T("Password"), passwd.buf, passwd.length);
+ std::vector<uint8_t> passwd;
+ passwd = key.getBinary(_T("Password"));
+ regKey.setBinary(_T("Password"), passwd.data(), passwd.size());
bool enableInputs = key.getBool(_T("InputsEnabled"), true);
regKey.setBool(_T("AcceptKeyEvents"), enableInputs);