void CMsgWriter::writeSetEncodings(const std::list<uint32_t> encodings)
{
- std::list<uint32_t>::const_iterator iter;
startMsg(msgTypeSetEncodings);
os->pad(1);
os->writeU16(encodings.size());
- for (iter = encodings.begin(); iter != encodings.end(); ++iter)
- os->writeU32(*iter);
+ for (uint32_t encoding : encodings)
+ os->writeU32(encoding);
endMsg();
}
delete producerCond;
delete queueMutex;
- for (size_t i = 0; i < sizeof(decoders)/sizeof(decoders[0]); i++)
- delete decoders[i];
+ for (Decoder* decoder : decoders)
+ delete decoder;
}
bool DecodeManager::decodeRect(const Rect& r, int encoding,
DecodeManager::QueueEntry* DecodeManager::DecodeThread::findEntry()
{
- std::list<DecodeManager::QueueEntry*>::iterator iter;
Region lockedRegion;
if (manager->workQueue.empty())
if (!manager->workQueue.front()->active)
return manager->workQueue.front();
- for (iter = manager->workQueue.begin();
- iter != manager->workQueue.end();
- ++iter) {
- DecodeManager::QueueEntry* entry;
-
- std::list<DecodeManager::QueueEntry*>::iterator iter2;
-
- entry = *iter;
-
+ for (DecodeManager::QueueEntry* entry : manager->workQueue) {
// Another thread working on this?
if (entry->active)
goto next;
// If this is an ordered decoder then make sure this is the first
// rectangle in the queue for that decoder
if (entry->decoder->flags & DecoderOrdered) {
- for (iter2 = manager->workQueue.begin(); iter2 != iter; ++iter2) {
- if (entry->encoding == (*iter2)->encoding)
+ for (DecodeManager::QueueEntry* entry2 : manager->workQueue) {
+ if (entry2 == entry)
+ break;
+ if (entry->encoding == entry2->encoding)
goto next;
}
}
// For a partially ordered decoder we must ask the decoder for each
// pair of rectangles.
if (entry->decoder->flags & DecoderPartiallyOrdered) {
- for (iter2 = manager->workQueue.begin(); iter2 != iter; ++iter2) {
- if (entry->encoding != (*iter2)->encoding)
+ for (DecodeManager::QueueEntry* entry2 : manager->workQueue) {
+ if (entry2 == entry)
+ break;
+ if (entry->encoding != entry2->encoding)
continue;
if (entry->decoder->doRectsConflict(entry->rect,
entry->bufferStream->data(),
entry->bufferStream->length(),
- (*iter2)->rect,
- (*iter2)->bufferStream->data(),
- (*iter2)->bufferStream->length(),
+ entry2->rect,
+ entry2->bufferStream->data(),
+ entry2->bufferStream->length(),
*entry->server))
goto next;
}
EncodeManager::~EncodeManager()
{
- std::vector<Encoder*>::iterator iter;
-
logStats();
- for (iter = encoders.begin();iter != encoders.end();iter++)
- delete *iter;
+ for (Encoder* encoder : encoders)
+ delete encoder;
}
void EncodeManager::logStats()
void H264Decoder::resetContexts()
{
os::AutoMutex lock(&mutex);
- for (std::deque<H264DecoderContext*>::iterator it = contexts.begin(); it != contexts.end(); it++)
- delete *it;
+ for (H264DecoderContext* context : contexts)
+ delete context;
contexts.clear();
}
H264DecoderContext* H264Decoder::findContext(const Rect& r)
{
os::AutoMutex m(&mutex);
- for (std::deque<H264DecoderContext*>::iterator it = contexts.begin(); it != contexts.end(); it++)
- if ((*it)->isEqualRect(r))
- return *it;
+ for (H264DecoderContext* context : contexts)
+ if (context->isEqualRect(r))
+ return context;
return nullptr;
}
{
if (!extendedDesktopSizeMsgs.empty()) {
if (client->supportsEncoding(pseudoEncodingExtendedDesktopSize)) {
- std::list<ExtendedDesktopSizeMsg>::const_iterator ri;
- for (ri = extendedDesktopSizeMsgs.begin();ri != extendedDesktopSizeMsgs.end();++ri) {
+ for (ExtendedDesktopSizeMsg msg : extendedDesktopSizeMsgs) {
// FIXME: We can probably skip multiple reasonServer entries
- writeExtendedDesktopSizeRect(ri->reason, ri->result,
+ writeExtendedDesktopSizeRect(msg.reason, msg.result,
client->width(), client->height(),
client->screenLayout());
}
const std::list<uint8_t> Security::GetEnabledSecTypes(void)
{
list<uint8_t> result;
- list<uint32_t>::iterator i;
/* Partial workaround for Vino's stupid behaviour. It doesn't allow
* the basic authentication types as part of the VeNCrypt handshake,
* making it impossible for a client to do opportunistic encryption.
* At least make it possible to connect when encryption is explicitly
* disabled. */
- for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++) {
- if (*i >= 0x100) {
+ for (uint32_t type : enabledSecTypes) {
+ if (type >= 0x100) {
result.push_back(secTypeVeNCrypt);
break;
}
}
- for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++)
- if (*i < 0x100)
- result.push_back(*i);
+ for (uint32_t type : enabledSecTypes)
+ if (type < 0x100)
+ result.push_back(type);
return result;
}
const std::list<uint32_t> Security::GetEnabledExtSecTypes(void)
{
list<uint32_t> result;
- list<uint32_t>::iterator i;
- for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++)
- if (*i != secTypeVeNCrypt) /* Do not include VeNCrypt type to avoid loops */
- result.push_back(*i);
+ for (uint32_t type : enabledSecTypes)
+ if (type != secTypeVeNCrypt) /* Do not include VeNCrypt type to avoid loops */
+ result.push_back(type);
return result;
}
char *Security::ToString(void)
{
- list<uint32_t>::iterator i;
static char out[128]; /* Should be enough */
bool firstpass = true;
const char *name;
memset(out, 0, sizeof(out));
- for (i = enabledSecTypes.begin(); i != enabledSecTypes.end(); i++) {
- name = secTypeName(*i);
+ for (uint32_t type : enabledSecTypes) {
+ name = secTypeName(type);
if (name[0] == '[') /* Unknown security type */
continue;
FileTcpFilter fileTcpFilter(hostsFile);
if (strlen(hostsFile) != 0)
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++)
- (*i)->setFilter(&fileTcpFilter);
+ for (SocketListener* listener : listeners)
+ listener->setFilter(&fileTcpFilter);
}
if (listeners.empty()) {
FD_ZERO(&wfds);
FD_SET(ConnectionNumber(dpy), &rfds);
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++)
- FD_SET((*i)->getFd(), &rfds);
+ for (SocketListener* listener : listeners)
+ FD_SET(listener->getFd(), &rfds);
server.getSockets(&sockets);
int clients_connected = 0;
}
// Accept new VNC connections
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++) {
- if (FD_ISSET((*i)->getFd(), &rfds)) {
- Socket* sock = (*i)->accept();
+ for (SocketListener* listener : listeners) {
+ if (FD_ISSET(listener->getFd(), &rfds)) {
+ Socket* sock = listener->accept();
if (sock) {
server.addSocket(sock);
} else {
TXWindow::handleXEvents(dpy);
// Run listener destructors; remove UNIX sockets etc
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++) {
- delete *i;
- }
+ for (SocketListener* listener : listeners)
+ delete listener;
vlog.info("Terminated");
return 0;
server = new VNCServerST(name, this);
setFramebuffer(width, height, fbptr, stride_);
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++) {
- vncSetNotifyFd((*i)->getFd(), screenIndex, true, false);
- }
+ for (SocketListener* listener : listeners)
+ vncSetNotifyFd(listener->getFd(), screenIndex, true, false);
}
XserverDesktop::~XserverDesktop()
bool MonitorIndicesParameter::setParam(const char* value)
{
- int index;
std::set<int> indices;
if (!parseIndices(value, &indices, true)) {
return false;
}
- for (std::set<int>::iterator it = indices.begin(); it != indices.end(); it++) {
- index = *it + 1;
-
+ for (int index : indices) {
+ index += 1;
if (index <= 0 || index > Fl::screen_count())
vlog.error(_("Monitor index %d does not exist"), index);
}
int bytesWritten = 0;
char const * separator = "";
- for (std::set<int>::iterator index = configIndices.begin();
- index != configIndices.end();
- index++)
+ for (int configIndex : configIndices)
{
bytesWritten += snprintf(
buf+bytesWritten,
BUF_MAX_LEN-bytesWritten,
"%s%u",
separator,
- (*index)+1
+ configIndex+1
);
separator = ",";
Security security(SecurityClient::secTypes);
list<uint8_t> secTypes;
- list<uint8_t>::iterator iter;
list<uint32_t> secTypesExt;
- list<uint32_t>::iterator iterExt;
encNoneCheckbox->value(false);
#ifdef HAVE_GNUTLS
authPlainCheckbox->value(false);
secTypes = security.GetEnabledSecTypes();
- for (iter = secTypes.begin(); iter != secTypes.end(); ++iter) {
- switch (*iter) {
+ for (uint8_t type : secTypes) {
+ switch (type) {
case secTypeNone:
encNoneCheckbox->value(true);
authNoneCheckbox->value(true);
}
secTypesExt = security.GetEnabledExtSecTypes();
- for (iterExt = secTypesExt.begin(); iterExt != secTypesExt.end(); ++iterExt) {
- switch (*iterExt) {
+ for (uint32_t type : secTypesExt) {
+ switch (type) {
case secTypePlain:
encNoneCheckbox->value(true);
authPlainCheckbox->value(true);
};
// Encoding Table
-static struct {
+static const struct EscapeMap {
const char first;
const char second;
} replaceMap[] = { { '\n', 'n' },
// Check for sequences which will need encoding
normalCharacter = true;
- for (size_t j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) {
+ for (EscapeMap esc : replaceMap) {
- if (val[i] == replaceMap[j].first) {
+ if (val[i] == esc.first) {
dest[pos] = '\\';
pos++;
if (pos >= destSize)
return false;
- dest[pos] = replaceMap[j].second;
+ dest[pos] = esc.second;
normalCharacter = false;
break;
}
bool escapedCharacter;
escapedCharacter = false;
- for (size_t j = 0; j < sizeof(replaceMap)/sizeof(replaceMap[0]); j++) {
- if (val[i+1] == replaceMap[j].second) {
- dest[pos] = replaceMap[j].first;
+ for (EscapeMap esc : replaceMap) {
+ if (val[i+1] == esc.second) {
+ dest[pos] = esc.first;
escapedCharacter = true;
i++;
break;
}
fprintf(f, "ServerName=%s\n", encodingBuffer);
- for (size_t i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) {
- if (dynamic_cast<StringParameter*>(parameterArray[i]) != nullptr) {
- if (!encodeValue(*(StringParameter*)parameterArray[i],
+ for (VoidParameter* param : parameterArray) {
+ if (dynamic_cast<StringParameter*>(param) != nullptr) {
+ if (!encodeValue(*(StringParameter*)param,
encodingBuffer, buffersize)) {
fclose(f);
throw Exception(_("Failed to save \"%s\": %s"),
- parameterArray[i]->getName(),
+ param->getName(),
_("Could not encode parameter"));
}
- fprintf(f, "%s=%s\n", ((StringParameter*)parameterArray[i])->getName(), encodingBuffer);
- } else if (dynamic_cast<IntParameter*>(parameterArray[i]) != nullptr) {
- fprintf(f, "%s=%d\n", ((IntParameter*)parameterArray[i])->getName(), (int)*(IntParameter*)parameterArray[i]);
- } else if (dynamic_cast<BoolParameter*>(parameterArray[i]) != nullptr) {
- fprintf(f, "%s=%d\n", ((BoolParameter*)parameterArray[i])->getName(), (int)*(BoolParameter*)parameterArray[i]);
+ fprintf(f, "%s=%s\n", ((StringParameter*)param)->getName(), encodingBuffer);
+ } else if (dynamic_cast<IntParameter*>(param) != nullptr) {
+ fprintf(f, "%s=%d\n", ((IntParameter*)param)->getName(), (int)*(IntParameter*)param);
+ } else if (dynamic_cast<BoolParameter*>(param) != nullptr) {
+ fprintf(f, "%s=%d\n", ((BoolParameter*)param)->getName(), (int)*(BoolParameter*)param);
} else {
fclose(f);
throw Exception(_("Failed to save \"%s\": %s"),
- parameterArray[i]->getName(),
+ param->getName(),
_("Unknown parameter type"));
}
}
count = 0;
// FIXME: Follow icon theme specification
- for (size_t i = 0;i < sizeof(icon_sizes)/sizeof(icon_sizes[0]);i++) {
+ for (int icon_size : icon_sizes) {
char icon_path[PATH_MAX];
bool exists;
sprintf(icon_path, "%s/icons/hicolor/%dx%d/apps/tigervnc.png",
- CMAKE_INSTALL_FULL_DATADIR, icon_sizes[i], icon_sizes[i]);
+ CMAKE_INSTALL_FULL_DATADIR, icon_size, icon_size);
struct stat st;
if (stat(icon_path, &st) != 0)
while (sock == nullptr) {
fd_set rfds;
FD_ZERO(&rfds);
- for (std::list<SocketListener*>::iterator i = listeners.begin();
- i != listeners.end();
- i++)
- FD_SET((*i)->getFd(), &rfds);
+ for (SocketListener* listener : listeners)
+ FD_SET(listener->getFd(), &rfds);
int n = select(FD_SETSIZE, &rfds, nullptr, nullptr, nullptr);
if (n < 0) {
}
}
- for (std::list<SocketListener*>::iterator i = listeners.begin ();
- i != listeners.end();
- i++)
- if (FD_ISSET((*i)->getFd(), &rfds)) {
- sock = (*i)->accept();
+ for (SocketListener* listener : listeners)
+ if (FD_ISSET(listener->getFd(), &rfds)) {
+ sock = listener->accept();
if (sock)
/* Got a connection */
break;
SecurityPage::initDialog()
{
list<uint8_t> secTypes;
- list<uint8_t>::iterator i;
if (isItemChecked(IDC_ENC_X509))
enableX509Dialogs();
secTypes = security->GetEnabledSecTypes();
/* Process non-VeNCrypt sectypes */
- for (i = secTypes.begin(); i != secTypes.end(); i++) {
- switch (*i) {
+ for (uint8_t type : secTypes) {
+ switch (type) {
case secTypeNone:
enableAuthMethod(IDC_ENC_NONE, IDC_AUTH_NONE);
break;
}
list<uint32_t> secTypesExt;
- list<uint32_t>::iterator iext;
secTypesExt = security->GetEnabledExtSecTypes();
/* Process VeNCrypt subtypes */
- for (iext = secTypesExt.begin(); iext != secTypesExt.end(); iext++) {
- switch (*iext) {
+ for (uint32_t type : secTypesExt) {
+ switch (type) {
case secTypePlain:
enableAuthMethod(IDC_ENC_NONE, IDC_AUTH_PLAIN);
break;