Пример #1
0
void GlobalPlugins::serialize (kdb::KeySet & ret)
{
	// transform to suitable data structure
	std::map<std::shared_ptr<Plugin>, Placements> pp;
	for (auto const & placements : plugins)
	{
		for (auto const & plugin : placements.second)
		{
			std::istringstream ss (plugin->lookupInfo ("status"));
			std::string status;
			bool isglobal = false;
			while (ss >> status)
			{
				if (status == "global") isglobal = true;
			}

			if (!isglobal)
			{
				throw NoGlobalPlugin (plugin->name ());
			}

			pp[plugin].addPlacement (placements.first);
		}
	}

	ret.append (Key ("system/elektra/globalplugins", KEY_VALUE, "", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/postcommit", KEY_VALUE, "list", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/postcommit/user", KEY_VALUE, "list", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/postcommit/user/placements", KEY_VALUE, "", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/postcommit/user/placements/set", KEY_VALUE, "presetstorage precommit postcommit",
			 KEY_END));
	ret.append (
		Key ("system/elektra/globalplugins/postcommit/user/placements/get", KEY_VALUE, "pregetstorage postgetstorage", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/postcommit/user/placements/error", KEY_VALUE, "prerollback postrollback", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/postcommit/user/plugins", KEY_VALUE, "", KEY_END));
	Key i ("system/elektra/globalplugins/postcommit/user/plugins/#0", KEY_END);
	for (auto const & plugin : pp)
	{
		i.setString (plugin.first->name ());
		ret.append (i.dup ());
		Key placements (i.dup ());
		placements.addBaseName ("placements");
		ret.append (placements);

		ret.append (g (placements, "get", plugin.second.get));
		ret.append (g (placements, "set", plugin.second.set));
		ret.append (g (placements, "error", plugin.second.error));

		serializeConf (ret, Key (i.getName () + "/config", KEY_VALUE, "", KEY_END), plugin.first->getConfig ());
		ckdb::elektraArrayIncName (*i);
	}
	ret.append (Key ("system/elektra/globalplugins/postrollback", KEY_VALUE, "list", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/precommit", KEY_VALUE, "list", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/pregetstorage", KEY_VALUE, "list", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/postgetstorage", KEY_VALUE, "list", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/presetstorage", KEY_VALUE, "list", KEY_END));
	ret.append (Key ("system/elektra/globalplugins/prerollback", KEY_VALUE, "list", KEY_END));
}
Пример #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));
}