2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package 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.
|
|
|
|
*/
|
|
|
|
|
2002-05-31 14:34:16 +00:00
|
|
|
#include "CConfig.h"
|
2003-02-22 15:03:31 +00:00
|
|
|
#include "KeyTypes.h"
|
2002-06-10 22:06:45 +00:00
|
|
|
#include "XSocket.h"
|
2002-06-01 19:26:11 +00:00
|
|
|
#include "stdistream.h"
|
|
|
|
#include "stdostream.h"
|
2003-02-22 16:20:23 +00:00
|
|
|
#include <stdlib.h>
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
//
|
2002-05-31 14:43:23 +00:00
|
|
|
// CConfig
|
2001-10-06 14:13:28 +00:00
|
|
|
//
|
|
|
|
|
2002-05-31 14:43:23 +00:00
|
|
|
CConfig::CConfig()
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-05-31 14:43:23 +00:00
|
|
|
CConfig::~CConfig()
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::addScreen(const CString& name)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2002-06-08 23:24:40 +00:00
|
|
|
// alias name must not exist
|
|
|
|
if (m_nameToCanonicalName.find(name) != m_nameToCanonicalName.end()) {
|
|
|
|
return false;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
// add cell
|
2001-10-06 14:13:28 +00:00
|
|
|
m_map.insert(std::make_pair(name, CCell()));
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
// add name
|
|
|
|
m_nameToCanonicalName.insert(std::make_pair(name, name));
|
|
|
|
|
|
|
|
return true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
bool
|
|
|
|
CConfig::renameScreen(const CString& oldName,
|
|
|
|
const CString& newName)
|
|
|
|
{
|
|
|
|
// get canonical name and find cell
|
|
|
|
CString oldCanonical = getCanonicalName(oldName);
|
|
|
|
CCellMap::iterator index = m_map.find(oldCanonical);
|
|
|
|
if (index == m_map.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accept if names are equal but replace with new name to maintain
|
|
|
|
// case. otherwise, the new name must not exist.
|
|
|
|
if (!CStringUtil::CaselessCmp::equal(oldName, newName) &&
|
|
|
|
m_nameToCanonicalName.find(newName) != m_nameToCanonicalName.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update cell
|
|
|
|
CCell tmpCell = index->second;
|
|
|
|
m_map.erase(index);
|
|
|
|
m_map.insert(std::make_pair(newName, tmpCell));
|
|
|
|
|
|
|
|
// update name
|
|
|
|
m_nameToCanonicalName.erase(oldCanonical);
|
|
|
|
m_nameToCanonicalName.insert(std::make_pair(newName, newName));
|
|
|
|
|
|
|
|
// update connections
|
|
|
|
for (index = m_map.begin(); index != m_map.end(); ++index) {
|
2003-02-23 19:29:08 +00:00
|
|
|
for (UInt32 i = 0; i < kNumDirections; ++i) {
|
2002-08-11 11:49:36 +00:00
|
|
|
if (CStringUtil::CaselessCmp::equal(getCanonicalName(
|
|
|
|
index->second.m_neighbor[i]), oldCanonical)) {
|
|
|
|
index->second.m_neighbor[i] = newName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update alias targets
|
|
|
|
if (CStringUtil::CaselessCmp::equal(oldName, oldCanonical)) {
|
|
|
|
for (CNameMap::iterator index = m_nameToCanonicalName.begin();
|
|
|
|
index != m_nameToCanonicalName.end(); ++index) {
|
|
|
|
if (CStringUtil::CaselessCmp::equal(
|
|
|
|
index->second, oldCanonical)) {
|
|
|
|
index->second = newName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::removeScreen(const CString& name)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2002-06-08 23:24:40 +00:00
|
|
|
// get canonical name and find cell
|
|
|
|
CString canonical = getCanonicalName(name);
|
|
|
|
CCellMap::iterator index = m_map.find(canonical);
|
2001-10-06 14:13:28 +00:00
|
|
|
if (index == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove from map
|
|
|
|
m_map.erase(index);
|
|
|
|
|
|
|
|
// disconnect
|
|
|
|
for (index = m_map.begin(); index != m_map.end(); ++index) {
|
|
|
|
CCell& cell = index->second;
|
2003-02-23 19:29:08 +00:00
|
|
|
for (UInt32 i = 0; i < kNumDirections; ++i) {
|
2002-06-08 23:24:40 +00:00
|
|
|
if (getCanonicalName(cell.m_neighbor[i]) == canonical) {
|
2001-10-06 14:13:28 +00:00
|
|
|
cell.m_neighbor[i].erase();
|
|
|
|
}
|
2002-08-11 11:49:36 +00:00
|
|
|
}
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
// remove aliases (and canonical name)
|
|
|
|
for (CNameMap::iterator index = m_nameToCanonicalName.begin();
|
|
|
|
index != m_nameToCanonicalName.end(); ) {
|
|
|
|
if (index->second == canonical) {
|
|
|
|
m_nameToCanonicalName.erase(index++);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CConfig::removeAllScreens()
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
m_map.clear();
|
2002-06-08 23:24:40 +00:00
|
|
|
m_nameToCanonicalName.clear();
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::addAlias(const CString& canonical, const CString& alias)
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
// alias name must not exist
|
|
|
|
if (m_nameToCanonicalName.find(alias) != m_nameToCanonicalName.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// canonical name must be known
|
2002-08-11 11:49:36 +00:00
|
|
|
if (m_map.find(canonical) == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert alias
|
|
|
|
m_nameToCanonicalName.insert(std::make_pair(alias, canonical));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::removeAlias(const CString& alias)
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
// must not be a canonical name
|
|
|
|
if (m_map.find(alias) != m_map.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find alias
|
|
|
|
CNameMap::iterator index = m_nameToCanonicalName.find(alias);
|
|
|
|
if (index == m_nameToCanonicalName.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove alias
|
|
|
|
m_nameToCanonicalName.erase(index);
|
|
|
|
|
|
|
|
return true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
CConfig::removeAllAliases()
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
// remove all names
|
|
|
|
m_nameToCanonicalName.clear();
|
|
|
|
|
|
|
|
// put the canonical names back in
|
|
|
|
for (CCellMap::iterator index = m_map.begin();
|
|
|
|
index != m_map.end(); ++index) {
|
|
|
|
m_nameToCanonicalName.insert(
|
|
|
|
std::make_pair(index->first, index->first));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::connect(const CString& srcName,
|
|
|
|
EDirection srcSide, const CString& dstName)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2003-02-23 19:29:08 +00:00
|
|
|
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// find source cell
|
2002-06-08 23:24:40 +00:00
|
|
|
CCellMap::iterator index = m_map.find(getCanonicalName(srcName));
|
2001-10-06 14:13:28 +00:00
|
|
|
if (index == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return false;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-08 23:24:40 +00:00
|
|
|
// connect side (overriding any previous connection). we
|
|
|
|
// canonicalize in getNeighbor() instead of here because the
|
|
|
|
// destination name doesn't have to exist yet.
|
2001-10-06 14:13:28 +00:00
|
|
|
index->second.m_neighbor[srcSide - kFirstDirection] = dstName;
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
return true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::disconnect(const CString& srcName, EDirection srcSide)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2003-02-23 19:29:08 +00:00
|
|
|
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// find source cell
|
|
|
|
CCellMap::iterator index = m_map.find(srcName);
|
|
|
|
if (index == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return false;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// disconnect side
|
|
|
|
index->second.m_neighbor[srcSide - kFirstDirection].erase();
|
2002-06-08 23:24:40 +00:00
|
|
|
|
|
|
|
return true;
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::setSynergyAddress(const CNetworkAddress& addr)
|
2002-06-09 16:53:25 +00:00
|
|
|
{
|
|
|
|
m_synergyAddress = addr;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::setHTTPAddress(const CNetworkAddress& addr)
|
2002-06-09 16:53:25 +00:00
|
|
|
{
|
|
|
|
m_httpAddress = addr;
|
|
|
|
}
|
|
|
|
|
2002-12-23 13:55:21 +00:00
|
|
|
bool
|
2003-01-25 13:34:51 +00:00
|
|
|
CConfig::addOption(const CString& name, OptionID option, OptionValue value)
|
2002-12-23 13:55:21 +00:00
|
|
|
{
|
2003-02-22 16:41:03 +00:00
|
|
|
// find options
|
|
|
|
CScreenOptions* options = NULL;
|
|
|
|
if (name.empty()) {
|
|
|
|
options = &m_globalOptions;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CCellMap::iterator index = m_map.find(name);
|
|
|
|
if (index != m_map.end()) {
|
|
|
|
options = &index->second.m_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (options == NULL) {
|
2002-12-23 13:55:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add option
|
2003-02-22 16:41:03 +00:00
|
|
|
options->insert(std::make_pair(option, value));
|
2002-12-23 13:55:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2003-01-25 13:34:51 +00:00
|
|
|
CConfig::removeOption(const CString& name, OptionID option)
|
2002-12-23 13:55:21 +00:00
|
|
|
{
|
2003-02-22 16:41:03 +00:00
|
|
|
// find options
|
|
|
|
CScreenOptions* options = NULL;
|
|
|
|
if (name.empty()) {
|
|
|
|
options = &m_globalOptions;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CCellMap::iterator index = m_map.find(name);
|
|
|
|
if (index != m_map.end()) {
|
|
|
|
options = &index->second.m_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (options == NULL) {
|
2002-12-23 13:55:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove option
|
2003-02-22 16:41:03 +00:00
|
|
|
options->erase(option);
|
2002-12-23 13:55:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-01-25 13:34:51 +00:00
|
|
|
bool
|
|
|
|
CConfig::removeOptions(const CString& name)
|
|
|
|
{
|
2003-02-22 16:41:03 +00:00
|
|
|
// find options
|
|
|
|
CScreenOptions* options = NULL;
|
|
|
|
if (name.empty()) {
|
|
|
|
options = &m_globalOptions;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CCellMap::iterator index = m_map.find(name);
|
|
|
|
if (index != m_map.end()) {
|
|
|
|
options = &index->second.m_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (options == NULL) {
|
2003-01-25 13:34:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-22 16:41:03 +00:00
|
|
|
// remove options
|
|
|
|
options->clear();
|
2003-01-25 13:34:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::isValidScreenName(const CString& name) const
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
// name is valid if matches validname
|
2003-04-16 20:05:00 +00:00
|
|
|
// name ::= [_A-Za-z0-9] | [_A-Za-z0-9][-_A-Za-z0-9]*[_A-Za-z0-9]
|
2002-05-31 17:32:26 +00:00
|
|
|
// domain ::= . name
|
|
|
|
// validname ::= name domain*
|
|
|
|
|
|
|
|
// check each dot separated part
|
|
|
|
CString::size_type b = 0;
|
|
|
|
for (;;) {
|
|
|
|
// find end of part
|
|
|
|
CString::size_type e = name.find('.', b);
|
|
|
|
if (e == CString::npos) {
|
|
|
|
e = name.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// part may not be empty
|
|
|
|
if (e - b < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check first and last characters
|
2003-04-16 20:05:00 +00:00
|
|
|
if (!(isalnum(name[b]) || name[b] == '_') ||
|
|
|
|
!(isalnum(name[e - 1]) || name[e - 1] == '_')) {
|
2002-05-31 17:32:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check interior characters
|
|
|
|
for (CString::size_type i = b; i < e; ++i) {
|
2003-04-16 20:05:00 +00:00
|
|
|
if (!isalnum(name[i]) && name[i] != '_' && name[i] != '-') {
|
2002-05-31 17:32:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// next part
|
|
|
|
if (e == name.size()) {
|
|
|
|
// no more parts
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
b = e + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CConfig::const_iterator
|
|
|
|
CConfig::begin() const
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
return const_iterator(m_map.begin());
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CConfig::const_iterator
|
|
|
|
CConfig::end() const
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
return const_iterator(m_map.end());
|
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
CConfig::all_const_iterator
|
|
|
|
CConfig::beginAll() const
|
|
|
|
{
|
|
|
|
return m_nameToCanonicalName.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
CConfig::all_const_iterator
|
|
|
|
CConfig::endAll() const
|
|
|
|
{
|
|
|
|
return m_nameToCanonicalName.end();
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::isScreen(const CString& name) const
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
2002-06-08 23:24:40 +00:00
|
|
|
return (m_nameToCanonicalName.count(name) > 0);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::isCanonicalName(const CString& name) const
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
return CStringUtil::CaselessCmp::equal(getCanonicalName(name), name);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::getCanonicalName(const CString& name) const
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
CNameMap::const_iterator index = m_nameToCanonicalName.find(name);
|
|
|
|
if (index == m_nameToCanonicalName.end()) {
|
|
|
|
return CString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return index->second;
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::getNeighbor(const CString& srcName, EDirection srcSide) const
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
2003-02-23 19:29:08 +00:00
|
|
|
assert(srcSide >= kFirstDirection && srcSide <= kLastDirection);
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
// find source cell
|
2002-06-08 23:24:40 +00:00
|
|
|
CCellMap::const_iterator index = m_map.find(getCanonicalName(srcName));
|
2001-10-06 14:13:28 +00:00
|
|
|
if (index == m_map.end()) {
|
2002-06-08 23:24:40 +00:00
|
|
|
return CString();
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return connection
|
2002-06-08 23:24:40 +00:00
|
|
|
return getCanonicalName(index->second.m_neighbor[
|
|
|
|
srcSide - kFirstDirection]);
|
2001-10-06 14:13:28 +00:00
|
|
|
}
|
2001-10-14 14:37:41 +00:00
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
const CNetworkAddress&
|
|
|
|
CConfig::getSynergyAddress() const
|
2002-06-09 16:53:25 +00:00
|
|
|
{
|
|
|
|
return m_synergyAddress;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
const CNetworkAddress&
|
|
|
|
CConfig::getHTTPAddress() const
|
2002-06-09 16:53:25 +00:00
|
|
|
{
|
|
|
|
return m_httpAddress;
|
|
|
|
}
|
|
|
|
|
2002-12-23 13:55:21 +00:00
|
|
|
const CConfig::CScreenOptions*
|
|
|
|
CConfig::getOptions(const CString& name) const
|
|
|
|
{
|
2003-02-22 16:41:03 +00:00
|
|
|
// find options
|
|
|
|
const CScreenOptions* options = NULL;
|
|
|
|
if (name.empty()) {
|
|
|
|
options = &m_globalOptions;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CCellMap::const_iterator index = m_map.find(name);
|
|
|
|
if (index != m_map.end()) {
|
|
|
|
options = &index->second.m_options;
|
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// return options
|
2003-02-22 16:41:03 +00:00
|
|
|
return options;
|
2002-12-23 13:55:21 +00:00
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
bool
|
|
|
|
CConfig::operator==(const CConfig& x) const
|
|
|
|
{
|
|
|
|
/* FIXME -- no compare available for CNetworkAddress
|
|
|
|
if (m_synergyAddress != x.m_synergyAddress) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_httpAddress != x.m_httpAddress) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (m_map.size() != x.m_map.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_nameToCanonicalName.size() != x.m_nameToCanonicalName.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-22 16:41:03 +00:00
|
|
|
// compare global options
|
|
|
|
if (m_globalOptions != x.m_globalOptions) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-08-11 11:49:36 +00:00
|
|
|
for (CCellMap::const_iterator index1 = m_map.begin(),
|
|
|
|
index2 = x.m_map.begin();
|
|
|
|
index1 != m_map.end(); ++index1, ++index2) {
|
2003-01-25 13:34:51 +00:00
|
|
|
// compare names
|
|
|
|
if (!CStringUtil::CaselessCmp::equal(index1->first, index2->first)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare options
|
|
|
|
if (index1->second.m_options != index2->second.m_options) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare neighbors
|
2003-02-23 19:29:08 +00:00
|
|
|
for (UInt32 i = 0; i < kNumDirections; ++i) {
|
2002-08-11 11:49:36 +00:00
|
|
|
if (!CStringUtil::CaselessCmp::equal(index1->second.m_neighbor[i],
|
|
|
|
index2->second.m_neighbor[i])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CNameMap::const_iterator index1 = m_nameToCanonicalName.begin(),
|
|
|
|
index2 = x.m_nameToCanonicalName.begin();
|
|
|
|
index1 != m_nameToCanonicalName.end();
|
|
|
|
++index1, ++index2) {
|
|
|
|
if (!CStringUtil::CaselessCmp::equal(index1->first, index2->first) ||
|
|
|
|
!CStringUtil::CaselessCmp::equal(index1->second, index2->second)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CConfig::operator!=(const CConfig& x) const
|
|
|
|
{
|
|
|
|
return !operator==(x);
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
const char*
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::dirName(EDirection dir)
|
2001-10-14 14:37:41 +00:00
|
|
|
{
|
|
|
|
static const char* s_name[] = { "left", "right", "top", "bottom" };
|
2003-02-23 19:29:08 +00:00
|
|
|
|
|
|
|
assert(dir >= kFirstDirection && dir <= kLastDirection);
|
|
|
|
|
2001-10-14 14:37:41 +00:00
|
|
|
return s_name[dir - kFirstDirection];
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
bool
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::readLine(std::istream& s, CString& line)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
s >> std::ws;
|
2002-06-01 19:26:11 +00:00
|
|
|
while (std::getline(s, line)) {
|
2002-05-31 17:32:26 +00:00
|
|
|
// strip comments and then trailing whitespace
|
2002-06-10 09:49:21 +00:00
|
|
|
CString::size_type i = line.find('#');
|
2002-05-31 17:32:26 +00:00
|
|
|
if (i != CString::npos) {
|
|
|
|
line.erase(i);
|
|
|
|
}
|
2002-10-15 22:17:41 +00:00
|
|
|
i = line.find_last_not_of(" \r\t");
|
2002-05-31 17:32:26 +00:00
|
|
|
if (i != CString::npos) {
|
|
|
|
line.erase(i + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return non empty line
|
|
|
|
if (!line.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
s >> std::ws;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-02-22 16:20:23 +00:00
|
|
|
OptionValue
|
2002-12-23 13:55:21 +00:00
|
|
|
CConfig::parseBoolean(const CString& arg)
|
|
|
|
{
|
2003-02-22 16:20:23 +00:00
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "true")) {
|
|
|
|
return static_cast<OptionValue>(true);
|
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "false")) {
|
|
|
|
return static_cast<OptionValue>(false);
|
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
throw XConfigRead("invalid argument");
|
|
|
|
}
|
|
|
|
|
2003-02-22 16:20:23 +00:00
|
|
|
OptionValue
|
|
|
|
CConfig::parseInt(const CString& arg)
|
|
|
|
{
|
|
|
|
const char* s = arg.c_str();
|
|
|
|
char* end;
|
|
|
|
long tmp = strtol(s, &end, 10);
|
|
|
|
if (*end != '\0') {
|
|
|
|
// invalid characters
|
|
|
|
throw XConfigRead("invalid argument");
|
|
|
|
}
|
|
|
|
OptionValue value = static_cast<OptionValue>(tmp);
|
|
|
|
if (value != tmp) {
|
|
|
|
// out of range
|
|
|
|
throw XConfigRead("argument out of range");
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2003-02-22 15:03:31 +00:00
|
|
|
OptionValue
|
|
|
|
CConfig::parseModifierKey(const CString& arg)
|
|
|
|
{
|
2003-02-22 16:20:23 +00:00
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "shift")) {
|
2003-02-22 15:03:31 +00:00
|
|
|
return static_cast<OptionValue>(kKeyModifierIDShift);
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "ctrl")) {
|
2003-02-22 15:03:31 +00:00
|
|
|
return static_cast<OptionValue>(kKeyModifierIDControl);
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "alt")) {
|
2003-02-22 15:03:31 +00:00
|
|
|
return static_cast<OptionValue>(kKeyModifierIDAlt);
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "meta")) {
|
2003-02-22 15:03:31 +00:00
|
|
|
return static_cast<OptionValue>(kKeyModifierIDMeta);
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "super")) {
|
2003-02-22 15:03:31 +00:00
|
|
|
return static_cast<OptionValue>(kKeyModifierIDSuper);
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
|
|
|
if (CStringUtil::CaselessCmp::equal(arg, "none")) {
|
2003-02-22 15:03:31 +00:00
|
|
|
return static_cast<OptionValue>(kKeyModifierIDNull);
|
2003-02-22 16:20:23 +00:00
|
|
|
}
|
2003-02-22 15:03:31 +00:00
|
|
|
throw XConfigRead("invalid argument");
|
|
|
|
}
|
|
|
|
|
2002-12-23 13:55:21 +00:00
|
|
|
const char*
|
|
|
|
CConfig::getOptionName(OptionID id)
|
|
|
|
{
|
|
|
|
if (id == kOptionHalfDuplexCapsLock) {
|
|
|
|
return "halfDuplexCapsLock";
|
|
|
|
}
|
|
|
|
if (id == kOptionHalfDuplexNumLock) {
|
|
|
|
return "halfDuplexNumLock";
|
|
|
|
}
|
2003-02-22 15:03:31 +00:00
|
|
|
if (id == kOptionModifierMapForShift) {
|
|
|
|
return "shift";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForControl) {
|
|
|
|
return "ctrl";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForAlt) {
|
|
|
|
return "alt";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForMeta) {
|
|
|
|
return "meta";
|
|
|
|
}
|
|
|
|
if (id == kOptionModifierMapForSuper) {
|
|
|
|
return "super";
|
|
|
|
}
|
2003-02-22 16:20:23 +00:00
|
|
|
if (id == kOptionHeartbeat) {
|
|
|
|
return "heartbeat";
|
|
|
|
}
|
2003-02-22 21:53:25 +00:00
|
|
|
if (id == kOptionScreenSwitchDelay) {
|
|
|
|
return "switchDelay";
|
|
|
|
}
|
2003-02-23 19:29:08 +00:00
|
|
|
if (id == kOptionScreenSwitchTwoTap) {
|
|
|
|
return "switchDoubleTap";
|
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-02-22 16:20:23 +00:00
|
|
|
CString
|
2002-12-23 13:55:21 +00:00
|
|
|
CConfig::getOptionValue(OptionID id, OptionValue value)
|
|
|
|
{
|
|
|
|
if (id == kOptionHalfDuplexCapsLock ||
|
|
|
|
id == kOptionHalfDuplexNumLock) {
|
|
|
|
return (value != 0) ? "true" : "false";
|
|
|
|
}
|
2003-02-22 15:03:31 +00:00
|
|
|
if (id == kOptionModifierMapForShift ||
|
|
|
|
id == kOptionModifierMapForControl ||
|
|
|
|
id == kOptionModifierMapForAlt ||
|
|
|
|
id == kOptionModifierMapForMeta ||
|
|
|
|
id == kOptionModifierMapForSuper) {
|
|
|
|
switch (value) {
|
|
|
|
case kKeyModifierIDShift:
|
|
|
|
return "shift";
|
|
|
|
|
|
|
|
case kKeyModifierIDControl:
|
|
|
|
return "ctrl";
|
|
|
|
|
|
|
|
case kKeyModifierIDAlt:
|
|
|
|
return "alt";
|
|
|
|
|
|
|
|
case kKeyModifierIDMeta:
|
|
|
|
return "meta";
|
|
|
|
|
|
|
|
case kKeyModifierIDSuper:
|
|
|
|
return "super";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
}
|
2003-02-22 21:53:25 +00:00
|
|
|
if (id == kOptionHeartbeat ||
|
2003-02-23 19:29:08 +00:00
|
|
|
id == kOptionScreenSwitchDelay ||
|
|
|
|
id == kOptionScreenSwitchTwoTap) {
|
2003-02-22 16:20:23 +00:00
|
|
|
return CStringUtil::print("%d", value);
|
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::readSection(std::istream& s)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
static const char s_section[] = "section:";
|
2003-02-22 16:20:23 +00:00
|
|
|
static const char s_options[] = "options";
|
2002-05-31 17:32:26 +00:00
|
|
|
static const char s_screens[] = "screens";
|
|
|
|
static const char s_links[] = "links";
|
2002-06-08 23:24:40 +00:00
|
|
|
static const char s_aliases[] = "aliases";
|
2002-05-31 17:32:26 +00:00
|
|
|
|
|
|
|
CString line;
|
|
|
|
if (!readLine(s, line)) {
|
|
|
|
// no more sections
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// should be a section header
|
|
|
|
if (line.find(s_section) != 0) {
|
|
|
|
throw XConfigRead("found data outside section");
|
|
|
|
}
|
|
|
|
|
|
|
|
// get section name
|
|
|
|
CString::size_type i = line.find_first_not_of(" \t", sizeof(s_section) - 1);
|
|
|
|
if (i == CString::npos) {
|
|
|
|
throw XConfigRead("section name is missing");
|
|
|
|
}
|
|
|
|
CString name = line.substr(i);
|
|
|
|
i = name.find_first_of(" \t");
|
|
|
|
if (i != CString::npos) {
|
|
|
|
throw XConfigRead("unexpected data after section name");
|
|
|
|
}
|
|
|
|
|
|
|
|
// read section
|
2003-02-22 16:20:23 +00:00
|
|
|
if (name == s_options) {
|
|
|
|
readSectionOptions(s);
|
2002-06-09 16:53:25 +00:00
|
|
|
}
|
|
|
|
else if (name == s_screens) {
|
2002-05-31 17:32:26 +00:00
|
|
|
readSectionScreens(s);
|
|
|
|
}
|
|
|
|
else if (name == s_links) {
|
|
|
|
readSectionLinks(s);
|
|
|
|
}
|
2002-06-08 23:24:40 +00:00
|
|
|
else if (name == s_aliases) {
|
|
|
|
readSectionAliases(s);
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
else {
|
|
|
|
throw XConfigRead("unknown section name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2003-02-22 16:20:23 +00:00
|
|
|
CConfig::readSectionOptions(std::istream& s)
|
2002-06-09 16:53:25 +00:00
|
|
|
{
|
|
|
|
CString line;
|
|
|
|
CString name;
|
|
|
|
while (readLine(s, line)) {
|
|
|
|
// check for end of section
|
|
|
|
if (line == "end") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse argument: `<name>=<value>'
|
|
|
|
CString::size_type i = line.find_first_of(" \t=");
|
|
|
|
if (i == 0) {
|
|
|
|
throw XConfigRead("missing argument name");
|
|
|
|
}
|
|
|
|
if (i == CString::npos) {
|
|
|
|
throw XConfigRead("missing = in argument");
|
|
|
|
}
|
|
|
|
CString name = line.substr(0, i);
|
|
|
|
i = line.find_first_not_of(" \t", i);
|
|
|
|
if (i == CString::npos || line[i] != '=') {
|
|
|
|
throw XConfigRead("missing = in argument");
|
|
|
|
}
|
|
|
|
i = line.find_first_not_of(" \t", i + 1);
|
|
|
|
CString value;
|
|
|
|
if (i != CString::npos) {
|
|
|
|
value = line.substr(i);
|
|
|
|
}
|
|
|
|
if (value.empty()) {
|
|
|
|
throw XConfigRead("missing value after =");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == "address") {
|
|
|
|
try {
|
|
|
|
m_synergyAddress = CNetworkAddress(value, kDefaultPort);
|
|
|
|
}
|
|
|
|
catch (XSocketAddress&) {
|
|
|
|
throw XConfigRead("invalid address argument");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (name == "http") {
|
|
|
|
try {
|
|
|
|
m_httpAddress = CNetworkAddress(value, kDefaultPort + 1);
|
|
|
|
}
|
|
|
|
catch (XSocketAddress&) {
|
|
|
|
throw XConfigRead("invalid http argument");
|
|
|
|
}
|
|
|
|
}
|
2003-02-22 16:20:23 +00:00
|
|
|
else if (name == "heartbeat") {
|
|
|
|
addOption("", kOptionHeartbeat, parseInt(value));
|
|
|
|
}
|
2003-02-22 21:53:25 +00:00
|
|
|
else if (name == "switchDelay") {
|
|
|
|
addOption("", kOptionScreenSwitchDelay, parseInt(value));
|
|
|
|
}
|
2003-02-23 19:29:08 +00:00
|
|
|
else if (name == "switchDoubleTap") {
|
|
|
|
addOption("", kOptionScreenSwitchTwoTap, parseInt(value));
|
|
|
|
}
|
2002-06-09 16:53:25 +00:00
|
|
|
else {
|
|
|
|
throw XConfigRead("unknown argument");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw XConfigRead("unexpected end of screens section");
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::readSectionScreens(std::istream& s)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
CString line;
|
2002-12-23 13:55:21 +00:00
|
|
|
CString screen;
|
2002-05-31 17:32:26 +00:00
|
|
|
while (readLine(s, line)) {
|
|
|
|
// check for end of section
|
|
|
|
if (line == "end") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if it's the next screen
|
|
|
|
if (line[line.size() - 1] == ':') {
|
|
|
|
// strip :
|
2002-12-23 13:55:21 +00:00
|
|
|
screen = line.substr(0, line.size() - 1);
|
2002-05-31 17:32:26 +00:00
|
|
|
|
|
|
|
// verify validity of screen name
|
2002-12-23 13:55:21 +00:00
|
|
|
if (!isValidScreenName(screen)) {
|
2002-05-31 17:32:26 +00:00
|
|
|
throw XConfigRead("invalid screen name");
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the screen to the configuration
|
2002-12-23 13:55:21 +00:00
|
|
|
if (!addScreen(screen)) {
|
2002-06-08 23:24:40 +00:00
|
|
|
throw XConfigRead("duplicate screen name");
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
else if (screen.empty()) {
|
2002-05-31 17:32:26 +00:00
|
|
|
throw XConfigRead("argument before first screen");
|
|
|
|
}
|
|
|
|
else {
|
2002-12-23 13:55:21 +00:00
|
|
|
// parse argument: `<name>=<value>'
|
|
|
|
CString::size_type i = line.find_first_of(" \t=");
|
|
|
|
if (i == 0) {
|
|
|
|
throw XConfigRead("missing argument name");
|
|
|
|
}
|
|
|
|
if (i == CString::npos) {
|
|
|
|
throw XConfigRead("missing = in argument");
|
|
|
|
}
|
|
|
|
CString name = line.substr(0, i);
|
|
|
|
i = line.find_first_not_of(" \t", i);
|
|
|
|
if (i == CString::npos || line[i] != '=') {
|
|
|
|
throw XConfigRead("missing = in argument");
|
|
|
|
}
|
|
|
|
i = line.find_first_not_of(" \t", i + 1);
|
|
|
|
CString value;
|
|
|
|
if (i != CString::npos) {
|
|
|
|
value = line.substr(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle argument
|
|
|
|
if (name == "halfDuplexCapsLock") {
|
|
|
|
addOption(screen, kOptionHalfDuplexCapsLock,
|
|
|
|
parseBoolean(value));
|
|
|
|
}
|
|
|
|
else if (name == "halfDuplexNumLock") {
|
|
|
|
addOption(screen, kOptionHalfDuplexNumLock,
|
|
|
|
parseBoolean(value));
|
|
|
|
}
|
2003-02-22 15:03:31 +00:00
|
|
|
else if (name == "shift") {
|
|
|
|
addOption(screen, kOptionModifierMapForShift,
|
|
|
|
parseModifierKey(value));
|
|
|
|
}
|
|
|
|
else if (name == "ctrl") {
|
|
|
|
addOption(screen, kOptionModifierMapForControl,
|
|
|
|
parseModifierKey(value));
|
|
|
|
}
|
|
|
|
else if (name == "alt") {
|
|
|
|
addOption(screen, kOptionModifierMapForAlt,
|
|
|
|
parseModifierKey(value));
|
|
|
|
}
|
|
|
|
else if (name == "meta") {
|
|
|
|
addOption(screen, kOptionModifierMapForMeta,
|
|
|
|
parseModifierKey(value));
|
|
|
|
}
|
|
|
|
else if (name == "super") {
|
|
|
|
addOption(screen, kOptionModifierMapForSuper,
|
|
|
|
parseModifierKey(value));
|
|
|
|
}
|
2002-12-23 13:55:21 +00:00
|
|
|
else {
|
|
|
|
// unknown argument
|
|
|
|
throw XConfigRead("unknown argument");
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
throw XConfigRead("unexpected end of screens section");
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::readSectionLinks(std::istream& s)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
CString line;
|
|
|
|
CString screen;
|
|
|
|
while (readLine(s, line)) {
|
|
|
|
// check for end of section
|
|
|
|
if (line == "end") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if it's the next screen
|
|
|
|
if (line[line.size() - 1] == ':') {
|
|
|
|
// strip :
|
|
|
|
screen = line.substr(0, line.size() - 1);
|
|
|
|
|
2002-06-08 23:24:40 +00:00
|
|
|
// verify we know about the screen
|
2002-05-31 17:32:26 +00:00
|
|
|
if (!isScreen(screen)) {
|
|
|
|
throw XConfigRead("unknown screen name");
|
|
|
|
}
|
2002-06-08 23:24:40 +00:00
|
|
|
if (!isCanonicalName(screen)) {
|
|
|
|
throw XConfigRead("cannot use screen name alias here");
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
else if (screen.empty()) {
|
|
|
|
throw XConfigRead("argument before first screen");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// parse argument: `<name>=<value>'
|
|
|
|
CString::size_type i = line.find_first_of(" \t=");
|
|
|
|
if (i == 0) {
|
|
|
|
throw XConfigRead("missing argument name");
|
|
|
|
}
|
|
|
|
if (i == CString::npos) {
|
|
|
|
throw XConfigRead("missing = in argument");
|
|
|
|
}
|
|
|
|
CString name = line.substr(0, i);
|
|
|
|
i = line.find_first_not_of(" \t", i);
|
|
|
|
if (i == CString::npos || line[i] != '=') {
|
|
|
|
throw XConfigRead("missing = in argument");
|
|
|
|
}
|
|
|
|
i = line.find_first_not_of(" \t", i + 1);
|
|
|
|
CString value;
|
|
|
|
if (i != CString::npos) {
|
|
|
|
value = line.substr(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle argument
|
|
|
|
if (name == "left") {
|
|
|
|
if (!isScreen(value)) {
|
|
|
|
throw XConfigRead("unknown screen");
|
|
|
|
}
|
|
|
|
connect(screen, kLeft, value);
|
|
|
|
}
|
|
|
|
else if (name == "right") {
|
|
|
|
if (!isScreen(value)) {
|
|
|
|
throw XConfigRead("unknown screen");
|
|
|
|
}
|
|
|
|
connect(screen, kRight, value);
|
|
|
|
}
|
|
|
|
else if (name == "up") {
|
|
|
|
if (!isScreen(value)) {
|
|
|
|
throw XConfigRead("unknown screen");
|
|
|
|
}
|
|
|
|
connect(screen, kTop, value);
|
|
|
|
}
|
|
|
|
else if (name == "down") {
|
|
|
|
if (!isScreen(value)) {
|
|
|
|
throw XConfigRead("unknown screen");
|
|
|
|
}
|
|
|
|
connect(screen, kBottom, value);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// unknown argument
|
|
|
|
throw XConfigRead("unknown argument");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw XConfigRead("unexpected end of links section");
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
CConfig::readSectionAliases(std::istream& s)
|
2002-06-08 23:24:40 +00:00
|
|
|
{
|
|
|
|
CString line;
|
|
|
|
CString screen;
|
|
|
|
while (readLine(s, line)) {
|
|
|
|
// check for end of section
|
|
|
|
if (line == "end") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if it's the next screen
|
|
|
|
if (line[line.size() - 1] == ':') {
|
|
|
|
// strip :
|
|
|
|
screen = line.substr(0, line.size() - 1);
|
|
|
|
|
|
|
|
// verify we know about the screen
|
|
|
|
if (!isScreen(screen)) {
|
|
|
|
throw XConfigRead("unknown screen name");
|
|
|
|
}
|
|
|
|
if (!isCanonicalName(screen)) {
|
|
|
|
throw XConfigRead("cannot use screen name alias here");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (screen.empty()) {
|
|
|
|
throw XConfigRead("argument before first screen");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// verify validity of screen name
|
|
|
|
if (!isValidScreenName(line)) {
|
|
|
|
throw XConfigRead("invalid screen alias");
|
|
|
|
}
|
|
|
|
|
|
|
|
// add alias
|
|
|
|
if (!addAlias(screen, line)) {
|
|
|
|
throw XConfigRead("alias is duplicate screen name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw XConfigRead("unexpected end of aliases section");
|
|
|
|
}
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// CConfig I/O
|
|
|
|
//
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
std::istream&
|
2002-06-17 13:31:21 +00:00
|
|
|
operator>>(std::istream& s, CConfig& config)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
// FIXME -- should track line and column to improve error reporting
|
|
|
|
|
|
|
|
CConfig tmp;
|
|
|
|
while (s) {
|
|
|
|
tmp.readSection(s);
|
|
|
|
}
|
|
|
|
config = tmp;
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
std::ostream&
|
2002-06-17 13:31:21 +00:00
|
|
|
operator<<(std::ostream& s, const CConfig& config)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
2003-02-22 16:20:23 +00:00
|
|
|
// options section
|
|
|
|
s << "section: options" << std::endl;
|
|
|
|
const CConfig::CScreenOptions* options = config.getOptions("");
|
|
|
|
if (options != NULL && options->size() > 0) {
|
|
|
|
for (CConfig::CScreenOptions::const_iterator
|
|
|
|
option = options->begin();
|
|
|
|
option != options->end(); ++option) {
|
|
|
|
const char* name = CConfig::getOptionName(option->first);
|
|
|
|
CString value = CConfig::getOptionValue(option->first,
|
|
|
|
option->second);
|
|
|
|
if (name != NULL && !value.empty()) {
|
|
|
|
s << "\t" << name << " = " << value << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-09 16:53:25 +00:00
|
|
|
if (config.m_synergyAddress.isValid()) {
|
2003-02-22 16:20:23 +00:00
|
|
|
s << "\taddress = " <<
|
|
|
|
config.m_synergyAddress.getHostname().c_str() << std::endl;
|
2002-06-09 16:53:25 +00:00
|
|
|
}
|
|
|
|
if (config.m_httpAddress.isValid()) {
|
2003-02-22 16:20:23 +00:00
|
|
|
s << "\thttp = " <<
|
|
|
|
config.m_httpAddress.getHostname().c_str() << std::endl;
|
2002-06-09 16:53:25 +00:00
|
|
|
}
|
|
|
|
s << "end" << std::endl;
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
// screens section
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "section: screens" << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
for (CConfig::const_iterator screen = config.begin();
|
|
|
|
screen != config.end(); ++screen) {
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "\t" << screen->c_str() << ":" << std::endl;
|
2002-12-23 13:55:21 +00:00
|
|
|
const CConfig::CScreenOptions* options = config.getOptions(*screen);
|
|
|
|
if (options != NULL && options->size() > 0) {
|
|
|
|
for (CConfig::CScreenOptions::const_iterator
|
|
|
|
option = options->begin();
|
|
|
|
option != options->end(); ++option) {
|
2003-02-22 16:20:23 +00:00
|
|
|
const char* name = CConfig::getOptionName(option->first);
|
|
|
|
CString value = CConfig::getOptionValue(option->first,
|
2002-12-23 13:55:21 +00:00
|
|
|
option->second);
|
2003-02-22 16:20:23 +00:00
|
|
|
if (name != NULL && !value.empty()) {
|
2002-12-23 13:55:21 +00:00
|
|
|
s << "\t\t" << name << " = " << value << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "end" << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
|
|
|
|
// links section
|
|
|
|
CString neighbor;
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "section: links" << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
for (CConfig::const_iterator screen = config.begin();
|
|
|
|
screen != config.end(); ++screen) {
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "\t" << screen->c_str() << ":" << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2002-07-15 15:01:36 +00:00
|
|
|
neighbor = config.getNeighbor(*screen, kLeft);
|
2002-05-31 17:32:26 +00:00
|
|
|
if (!neighbor.empty()) {
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "\t\tleft=" << neighbor.c_str() << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 15:01:36 +00:00
|
|
|
neighbor = config.getNeighbor(*screen, kRight);
|
2002-05-31 17:32:26 +00:00
|
|
|
if (!neighbor.empty()) {
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "\t\tright=" << neighbor.c_str() << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 15:01:36 +00:00
|
|
|
neighbor = config.getNeighbor(*screen, kTop);
|
2002-05-31 17:32:26 +00:00
|
|
|
if (!neighbor.empty()) {
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "\t\tup=" << neighbor.c_str() << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 15:01:36 +00:00
|
|
|
neighbor = config.getNeighbor(*screen, kBottom);
|
2002-05-31 17:32:26 +00:00
|
|
|
if (!neighbor.empty()) {
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "\t\tdown=" << neighbor.c_str() << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|
|
|
|
}
|
2002-06-01 19:26:11 +00:00
|
|
|
s << "end" << std::endl;
|
2002-05-31 17:32:26 +00:00
|
|
|
|
2002-06-08 23:24:40 +00:00
|
|
|
// aliases section (if there are any)
|
|
|
|
if (config.m_map.size() != config.m_nameToCanonicalName.size()) {
|
|
|
|
// map canonical to alias
|
2002-08-11 11:49:36 +00:00
|
|
|
typedef std::multimap<CString, CString,
|
|
|
|
CStringUtil::CaselessCmp> CMNameMap;
|
|
|
|
CMNameMap aliases;
|
2002-06-08 23:24:40 +00:00
|
|
|
for (CConfig::CNameMap::const_iterator
|
|
|
|
index = config.m_nameToCanonicalName.begin();
|
|
|
|
index != config.m_nameToCanonicalName.end();
|
|
|
|
++index) {
|
|
|
|
if (index->first != index->second) {
|
|
|
|
aliases.insert(std::make_pair(index->second, index->first));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// dump it
|
|
|
|
CString screen;
|
|
|
|
s << "section: aliases" << std::endl;
|
2002-08-11 11:49:36 +00:00
|
|
|
for (CMNameMap::const_iterator index = aliases.begin();
|
2002-06-08 23:24:40 +00:00
|
|
|
index != aliases.end(); ++index) {
|
|
|
|
if (index->first != screen) {
|
|
|
|
screen = index->first;
|
2002-08-11 11:49:36 +00:00
|
|
|
s << "\t" << screen.c_str() << ":" << std::endl;
|
2002-06-08 23:24:40 +00:00
|
|
|
}
|
|
|
|
s << "\t\t" << index->second.c_str() << std::endl;
|
|
|
|
}
|
|
|
|
s << "end" << std::endl;
|
|
|
|
}
|
|
|
|
|
2002-05-31 17:32:26 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// CConfig I/O exceptions
|
|
|
|
//
|
|
|
|
|
2002-06-17 13:31:21 +00:00
|
|
|
XConfigRead::XConfigRead(const CString& error) :
|
2002-06-10 22:06:45 +00:00
|
|
|
m_error(error)
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
XConfigRead::~XConfigRead()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
|
|
|
XConfigRead::getWhat() const throw()
|
2002-05-31 17:32:26 +00:00
|
|
|
{
|
2002-10-15 22:08:10 +00:00
|
|
|
return format("XConfigRead", "read error: %{1}", m_error.c_str());
|
2002-05-31 17:32:26 +00:00
|
|
|
}
|