Ejemplo n.º 1
0
kdb::KeySet Plugin::getNeededConfig()
{
	Key neededConfigKey ("system/elektra/modules", KEY_END);
	neededConfigKey.addName(pluginName);
	neededConfigKey.addName("config/needs");

	KeySet d (info.dup());
	KeySet config = d.cut(neededConfigKey);

	KeySet ret;
	Key oldParent = neededConfigKey;
	Key newParent("system", KEY_END);
	for (KeySet::iterator i = config.begin(); i != config.end(); ++i)
	{
		Key k(i->dup());
		ret.append(kdb::tools::helper::rebaseKey(k, oldParent, newParent));
	}
	return ret;
}
Ejemplo n.º 2
0
/**
 * @pre name and mountpoint set
 * Add plugin serialization into keyset ret.
 *
 * Only can be done once!
 * (see firstRef in Plugin)
 * */
void Backend::serialize (kdb::KeySet & ret)
{
	assert (!mp.empty ());
	Key backendRootKey (Backends::mountpointsPath, KEY_END);
	backendRootKey.addBaseName (mp);
	backendRootKey.setString ("This is a configuration for a backend, see subkeys for more information");
	ret.append (backendRootKey);


	if (mp == "/")
	{
		ret.append (*Key (backendRootKey.getName () + "/mountpoint", KEY_VALUE, "/", KEY_COMMENT,
				  "The mountpoint says the location where the backend should be mounted.\n"
				  "This is the root mountpoint.\n",
				  KEY_END));
	}
	else if (mp.at (0) == '/')
	{
		Key k ("system" + mp, KEY_END);
		Key restrictedPath ("system/elektra", KEY_END);
		if (!k) throw MountpointInvalidException ();
		if (restrictedPath.isBelow (k)) throw MountpointInvalidException ();
		ret.append (*Key (backendRootKey.getName () + "/mountpoint", KEY_VALUE, mp.c_str (), KEY_COMMENT,
				  "The mountpoint says the location where the backend should be mounted.\n"
				  "This is a cascading mountpoint.\n"
				  "That means it is both mounted to dir, user and system.",
				  KEY_END));
	}
	else
	{
		Key k (mp, KEY_END);
		Key restrictedPath ("system/elektra", KEY_END);
		if (!k) throw MountpointInvalidException ();
		if (restrictedPath.isBelow (k)) throw MountpointInvalidException ();
		ret.append (*Key (backendRootKey.getName () + "/mountpoint", KEY_VALUE, mp.c_str (), KEY_COMMENT,
				  "The mountpoint says the location where the backend should be mounted.\n"
				  "This is a normal mountpoint.\n",
				  KEY_END));
	}

	const string configBasePath = Backends::getBasePath (mp) + "/config";
	ret.append (Key (configBasePath, KEY_END));

	config.rewind ();
	Key common = config.next ();
	Key oldParent ("system", KEY_END);
	Key newParent (configBasePath, KEY_END);

	for (KeySet::iterator i = config.begin (); i != config.end (); ++i)
	{
		Key k (i->dup ());
		ret.append (kdb::tools::helper::rebaseKey (k, oldParent, newParent));
	}


	errorplugins.serialise (backendRootKey, ret);
	getplugins.serialise (backendRootKey, ret);
	setplugins.serialise (backendRootKey, ret);

	ret.append (*Key (backendRootKey.getName () + "/config/path", KEY_VALUE, configFile.c_str (), KEY_COMMENT,
			  "The path for this backend. Note that plugins can override that with more specific configuration.", KEY_END));
}