config: "uri" now has source name as fallback

For SyncEvolution<->SyncEvolution synchronization there should be
no need to set the uri property of each source explicitly, because
typically it is the same as the source name.

With this patch, the source name is used as fallback. Because some
code needs to check whether the URI is set, getURI() returns the
setting directly (as before) whereas getURINonEmpty() always returns a
non-empty result with the name as fallback.
This commit is contained in:
Patrick Ohly 2011-04-21 12:20:00 +02:00
parent d2e70d93e5
commit 436c23f827
5 changed files with 23 additions and 11 deletions

View File

@ -4971,7 +4971,7 @@ void Connection::ready()
// configuration might contain
// additional parameters (like date
// range selection for events)
if (boost::starts_with(sourceConfig->getURI(), serverURI)) {
if (boost::starts_with(sourceConfig->getURINonEmpty(), serverURI)) {
SE_LOG_DEBUG(NULL, NULL,
"SAN entry #%d = source %s with mode %s",
(int)sync, source.c_str(), syncMode.c_str());

View File

@ -260,7 +260,7 @@ void LocalTransportAgent::run()
SyncSourceConfig source(sourceName, nodes);
string sync = source.getSync();
if (sync != "disabled") {
string targetName = source.getURI();
string targetName = source.getURINonEmpty();
SyncSourceNodes targetNodes = client.getSyncSourceNodes(targetName);
SyncSourceConfig targetSource(targetName, targetNodes);
string fullTargetName = m_clientContext + "/" + targetName;

View File

@ -2547,7 +2547,8 @@ static StringConfigProperty sourcePropDatabaseFormat("databaseFormat",
static ConfigProperty sourcePropURI("uri",
"this is appended to the server's URL to identify the\n"
"server's database");
"server's database; if unset, the source name is used as\n"
"fallback");
static bool SourcePropURIIsSet(boost::shared_ptr<SyncSourceConfig> source)
{
return source->isSet(sourcePropURI);
@ -2684,6 +2685,13 @@ void SyncSourceConfig::savePassword(ConfigUserInterface &ui,
}
void SyncSourceConfig::setPassword(const string &value, bool temporarily) { m_cachedPassword = ""; sourcePropPassword.setProperty(*getNode(sourcePropPassword), value, temporarily); }
std::string SyncSourceConfig::getURI() const { return sourcePropURI.getProperty(*getNode(sourcePropURI)); }
std::string SyncSourceConfig::getURINonEmpty() const {
string uri = sourcePropURI.getProperty(*getNode(sourcePropURI));
if (uri.empty()) {
uri = m_name;
}
return uri;
}
void SyncSourceConfig::setURI(const string &value, bool temporarily) { sourcePropURI.setProperty(*getNode(sourcePropURI), value, temporarily); }
std::string SyncSourceConfig::getSync() const { return m_sourcePropSync.getProperty(*getNode(m_sourcePropSync)); }
void SyncSourceConfig::setSync(const string &value, bool temporarily) { m_sourcePropSync.setProperty(*getNode(m_sourcePropSync), value, temporarily); }

View File

@ -1951,6 +1951,13 @@ class SyncSourceConfig {
virtual std::string getURI() const;
virtual void setURI(const string &value, bool temporarily = false);
/**
* like getURI(), but instead of returning an empty string when
* not configured, return the source name
*/
virtual std::string getURINonEmpty() const;
/**
* Gets the default syncMode.
*

View File

@ -1720,7 +1720,7 @@ void SyncContext::displaySourceProgress(sysync::TProgressEventEnum type,
SE_LOG_INFO(NULL, NULL, "proxy authorization failed, check proxy username and password");
break;
case 404:
SE_LOG_INFO(&source, NULL, "server database not found, check URI '%s'", source.getURI().c_str());
SE_LOG_INFO(&source, NULL, "server database not found, check URI '%s'", source.getURINonEmpty().c_str());
break;
case 0:
break;
@ -1980,7 +1980,7 @@ void SyncContext::initSources(SourceList &sourceList)
// must set special URI for clients so that
// engine knows about superdatastore and its
// URI
vFilter["uri"] = string("<") + vSource->getName() + ">" + vSource->getURI();
vFilter["uri"] = string("<") + vSource->getName() + ">" + vSource->getURINonEmpty();
}
BOOST_FOREACH (std::string source, mappedSources) {
setConfigFilter (false, source, vFilter);
@ -2982,7 +2982,7 @@ SyncMLStatus SyncContext::sync(SyncReport *report)
SyncReport childReport;
agent->getClientSyncReport(childReport);
BOOST_FOREACH(SyncSource *source, sourceList) {
const SyncSourceReport *childSourceReport = childReport.findSyncSourceReport(source->getURI());
const SyncSourceReport *childSourceReport = childReport.findSyncSourceReport(source->getURINonEmpty());
if (childSourceReport) {
SyncMLStatus parentSourceStatus = source->getStatus();
SyncMLStatus childSourceStatus = childSourceReport->getStatus();
@ -3074,7 +3074,7 @@ bool SyncContext::sendSAN(uint16_t version)
}
syncMode = mode;
hasSource = true;
string uri = sc->getURI();
string uri = sc->getURINonEmpty();
SourceType sourceType = sc->getSourceType();
/*If the type is not set by user explictly, let's use backend default
@ -3330,10 +3330,7 @@ SyncMLStatus SyncContext::doSync()
m_engine.SetInt32Value(target, "forceslow", slow);
m_engine.SetInt32Value(target, "syncmode", direction);
string uri = source->getURI();
if (uri.empty()) {
source->throwError("uri not configured");
}
string uri = source->getURINonEmpty();
m_engine.SetStrValue(target, "remotepath", uri);
} else {
m_engine.SetInt32Value(target, "enabled", 0);