コード例 #1
0
ファイル: split.c プロジェクト: fberlakovich/libelektra
/**
 * @brief Filter out keys not in the correct keyset
 *
 * @param split the split where to do it
 * @param i for which split
 * @param warningKey the key
 * @param handle where to do backend lookups
 *
 * @retval -1 on error (no backend, wrong namespace)
 * @retval 0 otherwise
 */
static int elektraSplitPostprocess (Split * split, int i, Key * warningKey, KDB * handle)
{
	Key * cur = 0;
	Backend * curHandle = 0;
	ksRewind (split->keysets[i]);
	while ((cur = ksNext (split->keysets[i])) != 0)
	{
		curHandle = elektraMountGetBackend (handle, cur);
		if (!curHandle) return -1;

		keyClearSync (cur);

		if (curHandle != split->handles[i])
		{
			elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it is hidden by other mountpoint");
		}
		else
			switch (keyGetNamespace (cur))
			{
			case KEY_NS_SPEC:
				if (!keyIsSpec (split->parents[i]))
					elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it is not spec");
				break;
			case KEY_NS_DIR:
				if (!keyIsDir (split->parents[i]))
					elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it is not dir");
				break;
			case KEY_NS_USER:
				if (!keyIsUser (split->parents[i]))
					elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it is not user");
				break;
			case KEY_NS_SYSTEM:
				if (!keyIsSystem (split->parents[i]))
					elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it is not system");
				break;
			case KEY_NS_PROC:
				elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it has a proc key name");
				break;
			case KEY_NS_EMPTY:
				elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it has an empty name");
				break;
			case KEY_NS_META:
				elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it has a meta name");
				break;
			case KEY_NS_CASCADING:
				elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, "it has a cascading name");
				break;
			case KEY_NS_NONE:
				ELEKTRA_ASSERT (0 && "wrong key namespace, should not be none");
				return -1;
			}
	}
	return 0;
}
コード例 #2
0
ファイル: split.c プロジェクト: fberlakovich/libelektra
/**
 * Determines if the backend is already inserted or not.
 *
 * @warning If no parent Key is given, the default/root backends won't
 * be searched.
 *
 * @param split the split object to work with
 * @param backend the backend to search for
 * @param parent the key to check for domains in default/root backends.
 * @return pos of backend if it already exist
 * @retval -1 if it does not exist
 * @ingroup split
 */
ssize_t elektraSplitSearchBackend (Split * split, Backend * backend, Key * parent)
{
	for (size_t i = 0; i < split->size; ++i)
	{
		if (backend == split->handles[i])
		{
			if (test_bit (split->syncbits[i], SPLIT_FLAG_CASCADING))
			{
				switch (keyGetNamespace (parent))
				{
				case KEY_NS_SPEC:
					if (keyIsSpec (split->parents[i])) return i;
					break;
				case KEY_NS_DIR:
					if (keyIsDir (split->parents[i])) return i;
					break;
				case KEY_NS_USER:
					if (keyIsUser (split->parents[i])) return i;
					break;
				case KEY_NS_SYSTEM:
					if (keyIsSystem (split->parents[i])) return i;
					break;
				case KEY_NS_PROC:
					return -1;
				case KEY_NS_EMPTY:
					return -1;
				case KEY_NS_NONE:
					return -1;
				case KEY_NS_META:
					return -1;
				case KEY_NS_CASCADING:
					return -1;
				}
				continue;
			}
			/* We already have this backend, so leave */
			return i;
		}
	}
	return -1;
}
コード例 #3
0
ファイル: testmod_ini.c プロジェクト: intfrr/libelektra
void test_plainIniRead(char *fileName)
{
	Key *parentKey = keyNew ("user/tests/ini-read", KEY_VALUE,
			srcdir_file(fileName), KEY_END);

	KeySet *conf = ksNew (0);
	PLUGIN_OPEN ("ini");

	KeySet *ks = ksNew (0);

	succeed_if(plugin->kdbGet (plugin, ks, parentKey) >= 1,
			"call to kdbGet was not successful");
	succeed_if(output_error (parentKey), "error in kdbGet");
	succeed_if(output_warnings (parentKey), "warnings in kdbGet");

	Key *key = ksLookupByName (ks, "user/tests/ini-read/nosectionkey", KDB_O_NONE);
	exit_if_fail(key, "nosectionkey not found");
	succeed_if (!strcmp ("nosectionvalue", keyString(key)), "nosectionkey contained invalid data");

	key = ksLookupByName (ks, "user/tests/ini-read/section1", KDB_O_NONE);
	exit_if_fail(key, "section1 not found");
	succeed_if (keyIsDir(key), "section1 is not a directory key");

	key = ksLookupByName (ks, "user/tests/ini-read/section1/key1", KDB_O_NONE);
	exit_if_fail(key, "key1 not found");
	succeed_if (!strcmp ("value1", keyString(key)), "key1 contained invalid data");

	key = ksLookupByName (ks, "user/tests/ini-read/section2/emptykey", KDB_O_NONE);
	exit_if_fail(key, "emptykey not found");
	succeed_if (!strcmp ("", keyString(key)), "emptykey contained invalid data");

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ()
	;
}