SyncSourceParams: introduced context information

Backends like XMLRPC need information about URL, proxy and SSL
settings, etc. This can be done via source specific properties, like
evolutionsource, but this is not how this is normally done. It would
be nicer if the exising per-peer properties could be used. The goal is
that a normal peer configuration can be created from a template with
the necessary information to enable sources using that information.

This patch makes this possible by adding a context parameter to
SyncSourceParams:
     * @param    context     Additional non-source config settings.
     *                       When running as part of a normal sync, these are the
     *                       settings for the peer. When running in a local sync,
     *                       these settings come from the "source-config" peer
     *                       config inside the config context of the source.
     *                       Testing uses "source-config@client-test". On the
     *                       command line, this is the config chosen by the
     *                       user, which may or may not have peer-specific settings!

Note that this still doesn't solve the problem for XMLRPC to SyncML
peer sync, because in that case ("normal sync") the context will be
the one describing the peer. SyncURL is already used and proxy
settings might not match.

The XMLRPC backends therefore was not changed and continues to use
evolutionsource.
This commit is contained in:
Patrick Ohly 2010-10-08 15:00:08 +02:00
parent 73c2221129
commit 55ada103c4
8 changed files with 41 additions and 21 deletions

View File

@ -440,10 +440,10 @@ private:
/** called internally in this class */
TestingSyncSource *createSource(const string &name, bool isSourceA) {
string database = getDatabaseName(name);
SyncConfig config("client-test-changes");
SyncSourceNodes nodes = config.getSyncSourceNodes(name,
string("_") + m_clientID +
"_" + (isSourceA ? "A" : "B"));
boost::shared_ptr<SyncConfig> context(new SyncConfig("source-config@client-test"));
SyncSourceNodes nodes = context->getSyncSourceNodes(name,
string("_") + m_clientID +
"_" + (isSourceA ? "A" : "B"));
// always set this property: the name might have changes since last test run
nodes.getProperties()->setProperty("evolutionsource", database.c_str());
@ -451,8 +451,8 @@ private:
nodes.getProperties()->setProperty("evolutionpassword", m_evoPassword.c_str());
SyncSourceParams params(name,
nodes);
nodes,
context);
const RegisterSyncSourceTest *test = m_configs[name];
ClientTestConfig testConfig;
getSourceConfig(test, testConfig);

View File

@ -2818,7 +2818,7 @@ void ReadOperations::checkSource(const std::string &sourceName)
bool checked = false;
try {
// this can already throw exceptions when the config is invalid
SyncSourceParams params(sourceName, config->getSyncSourceNodes(sourceName));
SyncSourceParams params(sourceName, config->getSyncSourceNodes(sourceName), config);
auto_ptr<SyncSource> syncSource(SyncSource::createSource(params, false, config.get()));
if (syncSource.get()) {
@ -2839,7 +2839,7 @@ void ReadOperations::getDatabases(const string &sourceName, SourceDatabases_t &d
boost::shared_ptr<SyncConfig> config(new SyncConfig(m_configName));
setFilters(*config);
SyncSourceParams params(sourceName, config->getSyncSourceNodes(sourceName));
SyncSourceParams params(sourceName, config->getSyncSourceNodes(sourceName), config);
const SourceRegistry &registry(SyncSource::getSourceRegistry());
BOOST_FOREACH(const RegisterSyncSource *sourceInfo, registry) {
SyncSource *source = sourceInfo->m_create(params);

View File

@ -451,7 +451,7 @@ bool Cmdline::run() {
boost::shared_ptr<FilterConfigNode> trackingNode(new VolatileConfigNode());
boost::shared_ptr<FilterConfigNode> serverNode(new VolatileConfigNode());
SyncSourceNodes nodes(true, sharedNode, configNode, hiddenNode, trackingNode, serverNode, "");
SyncSourceParams params("list", nodes);
SyncSourceParams params("list", nodes, boost::shared_ptr<const SyncConfig>());
BOOST_FOREACH(const RegisterSyncSource *source, registry) {
BOOST_FOREACH(const Values::value_type &alias, source->m_typeValues) {
@ -727,7 +727,7 @@ bool Cmdline::run() {
}
// check whether the sync source works
SyncSourceParams params("list", to->getSyncSourceNodes(source));
SyncSourceParams params("list", to->getSyncSourceNodes(source), to);
auto_ptr<SyncSource> syncSource(SyncSource::createSource(params, false, to.get()));
if (syncSource.get() == NULL) {
disable = "no backend available";
@ -820,7 +820,7 @@ bool Cmdline::run() {
string sourceName = *m_sources.begin();
SyncSourceNodes sourceNodes = context->getSyncSourceNodesNoTracking(sourceName);
SyncSourceParams params(sourceName, sourceNodes);
SyncSourceParams params(sourceName, sourceNodes, context);
cxxptr<SyncSource> source(SyncSource::createSource(params, true));
sysync::TSyError err;

View File

@ -133,7 +133,7 @@ void LocalTransportAgent::run()
try {
SE_LOG_INFO(NULL, NULL, "client is running");
// TODO: password and abort handling in a derived class
SyncContext client(m_clientContext,
SyncContext client(std::string("source-config@") + m_clientContext,
m_server->getRootPath() + "/." + m_clientContext,
boost::shared_ptr<TransportAgent>(this, NoopAgentDestructor()),
true);

View File

@ -1548,6 +1548,14 @@ class SyncSourceNodes {
boost::shared_ptr<FilterConfigNode> m_props[2];
};
/**
* nop deleter for boost::shared_ptr<SyncConfig>
*/
struct SyncConfigNOP
{
void operator() (SyncConfig *) {}
};
/**
* same as SyncSourceNodes, but with only read access to properties
*/

View File

@ -1908,7 +1908,7 @@ void SyncContext::initSources(SourceList &sourceList)
if (sourceType.m_backend == "virtual") {
//This is a virtual sync source, check and enable the referenced
//sub syncsources here
SyncSourceParams params(name, source);
SyncSourceParams params(name, source, boost::shared_ptr<SyncConfig>(this, SyncConfigNOP()));
boost::shared_ptr<VirtualSyncSource> vSource = boost::shared_ptr<VirtualSyncSource> (new VirtualSyncSource (params));
std::vector<std::string> mappedSources = vSource->getMappedSources();
BOOST_FOREACH (std::string source, mappedSources) {
@ -1953,7 +1953,8 @@ void SyncContext::initSources(SourceList &sourceList)
if (enabled) {
if (sourceType.m_backend != "virtual") {
SyncSourceParams params(name,
source);
source,
boost::shared_ptr<SyncConfig>(this, SyncConfigNOP()));
cxxptr<SyncSource> syncSource(SyncSource::createSource(params));
if (!syncSource) {
throwError(name + ": type unknown" );

View File

@ -350,9 +350,9 @@ SyncSource *SyncSource::createSource(const SyncSourceParams &params, bool error,
SyncSource *SyncSource::createTestingSource(const string &name, const string &type, bool error,
const char *prefix)
{
SyncConfig config("testing@client-test");
SyncSourceNodes nodes = config.getSyncSourceNodes(name);
SyncSourceParams params(name, nodes);
boost::shared_ptr<SyncConfig> context(new SyncConfig("source-config@client-test"));
SyncSourceNodes nodes = context->getSyncSourceNodes(name);
SyncSourceParams params(name, nodes, context);
PersistentSyncSourceConfig sourceconfig(name, nodes);
sourceconfig.setSourceType(type);
if (prefix) {
@ -367,7 +367,7 @@ VirtualSyncSource::VirtualSyncSource(const SyncSourceParams &params, SyncConfig
if (config) {
BOOST_FOREACH(std::string name, getMappedSources()) {
SyncSourceNodes source = config->getSyncSourceNodes(name);
SyncSourceParams params(name, source);
SyncSourceParams params(name, source, boost::shared_ptr<SyncConfig>(config, SyncConfigNOP()));
boost::shared_ptr<SyncSource> syncSource(createSource(params, true, config));
m_sources.push_back(syncSource);
}

View File

@ -45,15 +45,26 @@ struct SyncSourceParams {
/**
* @param name the name needed by SyncSource
* @param nodes a set of config nodes to be used by this source
* @param context Additional non-source config settings.
* When running as part of a normal sync, these are the
* settings for the peer. When running in a local sync,
* these settings come from the "source-config" peer
* config inside the config context of the source.
* Testing uses "source-config@client-test". On the
* command line, this is the config chosen by the
* user, which may or may not have peer-specific settings!
*/
SyncSourceParams(const string &name,
const SyncSourceNodes &nodes = SyncSourceNodes()) :
const SyncSourceNodes &nodes,
const boost::shared_ptr<const SyncConfig> &context) :
m_name(name),
m_nodes(nodes)
m_nodes(nodes),
m_context(context)
{}
string m_name;
SyncSourceNodes m_nodes;
boost::shared_ptr<const SyncConfig> m_context;
};
/**
@ -1139,7 +1150,7 @@ class DummySyncSource : public SyncSource
SyncSource(params) {}
DummySyncSource(const std::string &name) :
SyncSource(SyncSourceParams(name)) {}
SyncSource(SyncSourceParams(name, SyncSourceNodes(), boost::shared_ptr<const SyncConfig>())) {}
virtual Databases getDatabases() { return Databases(); }
virtual void open() {}