示例#1
0
void test_metaSkipMerge()
{
	Key *parentKey = keyNew ("user/tests/keytometa", KEY_END);
	KeySet *conf = ksNew (0);
	PLUGIN_OPEN("keytometa");

	KeySet* ks = createSkipMergeTestKeys();
	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/normalkey1", 0);
	succeed_if (key, "normalkey1 was removed");

	const Key *metaKey1 = keyGetMeta(key, "testmeta");
	succeed_if (metaKey1, "normalkey1 contained no metakey");
	const char *expected1 = "meta line1\nmeta line3";
	succeed_if (!strcmp (keyString(metaKey1), expected1), "metakey of normalkey1 contained incorrect data");

	key = ksLookupByName(ks, "user/normalkey2", 0);
	succeed_if (key, "normalkey2 was removed");

	const Key *metaKey2 = keyGetMeta(key, "testmeta");
	succeed_if (metaKey2, "normalkey2 contained no metakey");
	const char *expected2 = "meta line2\nmeta line4";
	succeed_if (!strcmp (keyString(metaKey2), expected2), "metakey of normalkey2 contained incorrect data");

	keyDel (parentKey);
	ksDel(ks);
	PLUGIN_CLOSE ();
}
示例#2
0
static void test_ksPopAtCursor ()
{
	KeySet * ks = ksNew (5, keyNew ("user/valid/key1", KEY_END), keyNew ("user/valid/key2", KEY_END),
			     keyNew ("system/valid/key1", KEY_END), keyNew ("system/valid/key2", KEY_END), KS_END);
	KeySet * ks_c = ksNew (5, keyNew ("user/valid/key1", KEY_END), keyNew ("user/valid/key2", KEY_END),
			       keyNew ("system/valid/key1", KEY_END), KS_END);
	ksRewind (ks);
	ksNext (ks);
	ksNext (ks);
	cursor_t c = ksGetCursor (ks);
	keyDel (ksPopAtCursor (ks, c));
	succeed_if (ksCurrent (ks) == 0, "cursor position wrong");

	compare_keyset (ks, ks_c);
	ksDel (ks);
	ksDel (ks_c);
}
示例#3
0
static void testwriteinvalidheader (const char * file)
{

	Key * parentKey = keyNew ("user/tests/csvstorage", KEY_VALUE, srcdir_file (file), KEY_END);
	KeySet * conf = ksNew (20, keyNew ("system/delimiter", KEY_VALUE, ";", KEY_END),
			       keyNew ("system/header", KEY_VALUE, "colname", KEY_END), KS_END);

	KeySet * ks = ksNew (0, KS_END);
	PLUGIN_OPEN ("csvstorage");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) > 0, "call to kdbGet was not successful");
	succeed_if (!output_warnings (parentKey), "no warnings in kdbGet");
	keySetString (parentKey, elektraFilename ());
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "error: wrote invalid data");
	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
示例#4
0
KeySet * set_pluginconf ()
{
	return ksNew (10, keyNew ("system/anything", KEY_VALUE, "backend", KEY_END), keyNew ("system/more", KEY_END),
		      keyNew ("system/more/config", KEY_END), keyNew ("system/more/config/below", KEY_END), keyNew ("system/path", KEY_END),
		      keyNew ("user/anything", KEY_VALUE, "plugin", KEY_END), keyNew ("user/more", KEY_END),
		      keyNew ("user/more/config", KEY_END), keyNew ("user/more/config/below", KEY_END), keyNew ("user/path", KEY_END),
		      KS_END);
}
示例#5
0
// clang-format off
KeySet *getEmptyKeys(void)
{
	return ksNew(1,
			keyNew("user/tests/yajl",
			       KEY_END),
			KS_END
			);
}
示例#6
0
static void test_preserveEmptyLines (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-write", KEY_VALUE, srcdir_file (fileName), KEY_END);
	Key * writeParentKey = keyNew ("user/tests/ini-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	KeySet * ks = ksNew (30, KS_END);
	PLUGIN_OPEN ("ini");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 0, "call to kdbGet was not successful");
	keyDel (ksLookup (ks, parentKey, KDB_O_POP));
	keyDel (parentKey);
	succeed_if (plugin->kdbSet (plugin, ks, writeParentKey) >= 1, "call to kdbSet was not successful");
	succeed_if (compare_line_files (srcdir_file (fileName), keyString (writeParentKey)), "files do not match as expected");
	keyDel (ksLookup (ks, writeParentKey, KDB_O_POP));
	keyDel (writeParentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
KeySet *simple_config(void)
{
	return ksNew(5,
		keyNew("system/elektra/mountpoints", KEY_END),
		keyNew("system/elektra/mountpoints/simple", KEY_END),
		keyNew("system/elektra/mountpoints/simple/mountpoint", KEY_VALUE, "user/tests/simple", KEY_END),
		KS_END);
}
示例#8
0
KeySet* createKeys()
{
	KeySet *ks = ksNew (30, keyNew ("user/tests/glob/test1", KEY_END),
			keyNew ("user/tests/glob/test2/subtest1", KEY_END),
			keyNew ("user/tests/glob/test3", KEY_END),
			KS_END);
	return ks;
}
示例#9
0
文件: backend.c 项目: beku/libelektra
/**
 * Opens a default backend using the plugin named KDB_DEFAULT_RESOLVER
 * and KDB_DEFAULT_STORAGE.
 *
 * @param modules the modules to work with
 * @param errorKey the key to issue warnings and errors to
 * @return the fresh allocated default backend or 0 if it failed
 */
Backend* elektraBackendOpenDefault(KeySet *modules, Key *errorKey)
{
	Backend *backend = elektraBackendAllocate();

	KeySet *resolverConfig = ksNew(5,
		keyNew("system/path", KEY_VALUE, KDB_DB_FILE, KEY_END),
		KS_END);

	Plugin *resolver = elektraPluginOpen(KDB_DEFAULT_RESOLVER,
			modules, resolverConfig, errorKey);
	if (!resolver)
	{
		elektraFree(backend);
		/* error already set in elektraPluginOpen */
		return 0;
	}

	backend->getplugins[RESOLVER_PLUGIN] = resolver;
	backend->setplugins[RESOLVER_PLUGIN] = resolver;
	backend->setplugins[COMMIT_PLUGIN] = resolver;
	backend->errorplugins[STORAGE_PLUGIN] = resolver;
	resolver->refcounter = 4;

	KeySet *storageConfig = ksNew(5,
		KS_END);

	Plugin *storage = elektraPluginOpen(KDB_DEFAULT_STORAGE,
			modules, storageConfig, errorKey);
	if (!storage)
	{
		elektraPluginClose(resolver, errorKey);
		elektraFree(backend);
		/* error already set in elektraPluginOpen */
		return 0;
	}

	backend->getplugins[STORAGE_PLUGIN] = storage;
	backend->setplugins[STORAGE_PLUGIN] = storage;
	storage->refcounter = 2;

	Key *mp = keyNew ("", KEY_VALUE, "default", KEY_END);
	backend->mountpoint = mp;
	keyIncRef(backend->mountpoint);

	return backend;
}
static void test_mmap_meta_get_after_reopen (const char * tmpFile)
{
	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");
	KeySet * ks = ksNew (0, KS_END);

	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");

	KeySet * expected = metaTestKeySet ();
	compare_keyset (expected, ks);

	ksDel (expected);
	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
示例#11
0
void test_hostLensModify(char *sourceFile, char *compFile)
{
	Key *parentKey = keyNew ("user/tests/augeas-hosts", KEY_VALUE,
			srcdir_file (sourceFile), KEY_END);
	KeySet *conf = ksNew (20,
			keyNew ("system/lens", KEY_VALUE, "Hosts.lns", KEY_END), KS_END);
	PLUGIN_OPEN("augeas");

	KeySet *ks = ksNew(0, KS_END);

	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/augeas-hosts/1/ipaddr", 0);
	exit_if_fail(key, "ip address of localhost not found");
	keySetString (key, "127.0.0.2");

	key = ksLookupByName (ks, "user/tests/augeas-hosts/3/ipaddr", 0);
	exit_if_fail(key, "ip address of host2 not found");
	keySetString (key, "fd00::4711:4712:2::2");

	key = ksLookupByName (ks, "user/tests/augeas-hosts/#comment", 0);
	exit_if_fail(key, "line comment not found");
	keySetString (key, "line comment modified");

	keySetString (parentKey, elektraFilename());

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

	succeed_if(
			compare_line_files (srcdir_file (compFile), keyString (parentKey)),
			"files do not match as expected");

	PLUGIN_CLOSE ();

	elektraUnlink(keyString (parentKey));

	ksDel (ks);
	keyDel (parentKey);
}
示例#12
0
static KeySet *createSimpleTestKeys()
{
	return ksNew (20,
			keyNew("user/tests/rename/will/be/stripped/key1", KEY_VALUE, "value1", KEY_END),
			keyNew("user/tests/rename/will/be/stripped/key2", KEY_VALUE, "value2", KEY_END),
			keyNew("user/tests/rename/will/be/stripped", KEY_VALUE, "value3", KEY_END),
			keyNew("user/tests/rename/will/not/be/stripped/key4", KEY_VALUE, "value4", KEY_END),
			KS_END);
}
示例#13
0
static void test_toLower ()
{
	Key * parentKey = keyNew ("user/tests/rename", KEY_END);
	KeySet * conf = ksNew (20, keyNew ("system/tolower", KEY_VALUE, "0", KEY_END), KS_END);
	KeySet * ks = ksNew (20, keyNew ("user/tests/rename/AM/I/LOWERCASE", KEY_VALUE, "val1", KEY_END),
			     keyNew ("user/tests/rename/I/HOPE/IM/LOWERCASE/TOO", KEY_VALUE, "val2", KEY_END), KS_END);
	ksAppendKey (ks, parentKey);
	PLUGIN_OPEN ("rename");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
	Key * key = ksLookupByName (ks, "user/tests/rename/am/i/lowercase", KDB_O_NONE);
	succeed_if (key, "key1 was not correctly rename");
	key = ksLookupByName (ks, "user/tests/rename/i/hope/im/lowercase/too", KDB_O_NONE);
	succeed_if (key, "key2 was not correctly rename");

	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
static void test_ifthenkey()
{
	Key *parentKey = keyNew("user/tests/conditionals", KEY_VALUE, "", KEY_END);
	KeySet *ks = ksNew(5,
	keyNew("user/tests/conditionals/totest", KEY_VALUE, "153", KEY_META, "check/condition", "(totest>bla/val3) ? (bla/val1 == '100') :  (bla/val2 <= '1')", KEY_END),
	keyNew("user/tests/conditionals/bla/val1", KEY_VALUE, "100", KEY_END),
	keyNew("user/tests/conditionals/bla/val2", KEY_VALUE, "50", KEY_END),
	keyNew("user/tests/conditionals/bla/val3", KEY_VALUE, "3", KEY_END),
		KS_END);
	KeySet *conf = ksNew(0, KS_END);
	PLUGIN_OPEN("conditionals");
	ksRewind(ks);
	succeed_if(plugin->kdbGet(plugin, ks, parentKey) == 1, "error");
	ksDel(ks);
	keyDel(parentKey);
	PLUGIN_CLOSE();

}
示例#15
0
void testWriteMultiLine (const char * compareTo)
{
	Key * parentKey = keyNew ("user/tests/file", KEY_VALUE, elektraFilename (), KEY_END);

	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("file");

	KeySet * ks = ksNew (3, keyNew ("user/tests/file", KEY_VALUE, "\nthis\n\n\tis a\n   multi line test-\nfile\n\n", KEY_END), KS_END);

	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "call to kdbSet was not successful");

	succeed_if (compare_line_files (srcdir_file (compareTo), keyString (parentKey)), "files do not match as expected");

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
/**
 * @brief create new KeySet and add an incomplete configuration to it.
 *
 * The required key "/elektra/modules/crypto/key-derivation/iv" is missing.
 */
static void getIncompleteConfiguration(KeySet **ks)
{
	Key *configKey = keyNew("proc/elektra/modules/crypto/key-derivation/key", KEY_END);
	keySetBinary(configKey, key, sizeof(key));

	(*ks) = ksNew(1,
		configKey,
		KS_END);
}
示例#17
0
文件: line.c 项目: 0003088/libelektra
static inline KeySet * elektraLineContract ()
{
    return ksNew (30, keyNew ("system/elektra/modules/line", KEY_VALUE, "line plugin waits for your orders", KEY_END),
                  keyNew ("system/elektra/modules/line/exports", KEY_END),
                  keyNew ("system/elektra/modules/line/exports/get", KEY_FUNC, elektraLineGet, KEY_END),
                  keyNew ("system/elektra/modules/line/exports/set", KEY_FUNC, elektraLineSet, KEY_END),
#include "readme_line.c"
                  keyNew ("system/elektra/modules/line/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
}
示例#18
0
static void test_multiUp (void)
{
	Key * parentKey = keyNew ("user/tests/mathcheck", KEY_VALUE, "", KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	KeySet * ks = ksNew (5, keyNew ("user/tests/mathcheck/up/sum", KEY_VALUE, "0", KEY_META, "check/math",
					":= + ../val1 + ../../val2 ../val3", KEY_END),
			     keyNew ("user/tests/mathcheck/up/val1", KEY_VALUE, "1", KEY_END),
			     keyNew ("user/tests/mathcheck/val2", KEY_VALUE, "2", KEY_END),
			     keyNew ("user/tests/mathcheck/up/val3", KEY_VALUE, "10", KEY_END), KS_END);

	PLUGIN_OPEN ("mathcheck");
	ksRewind (ks);
	plugin->kdbSet (plugin, ks, parentKey);
	succeed_if (!strcmp (keyString (ksLookupByName (ks, "user/tests/mathcheck/up/sum", 0)), "13"), "error");
	keyDel (parentKey);
	PLUGIN_CLOSE ();
	ksDel (ks);
}
示例#19
0
static void test_lookupDoubleIndirectDefault ()
{
	printf ("Test lookup by double indirect spec with default\n");

	Key * s;
	Key * p;
	Key * u;
	Key * y;
	Key * se;
	Key * pe;
	KeySet * ks =
		ksNew (20, se = keyNew ("spec/first", KEY_END), pe = keyNew ("proc/first", KEY_END), s = keyNew ("spec/abc", KEY_END),
		       p = keyNew ("proc/abc", KEY_END), u = keyNew ("user/abc", KEY_END), y = keyNew ("system/abc", KEY_END), KS_END);
	succeed_if (ksGetSize (ks) == 6, "wrong size");
	keySetMeta (se, "default", "default is ok");
	keySetMeta (s, "default", "default is NOT ok");

	Key * k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == pe, "did not find proc key");

	keySetMeta (se, "namespace/#0", "system");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if_same_string (keyString (k), "default is ok");

	keySetMeta (se, "override/#0", "/abc");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == p, "did not find proc/abc");

	keySetMeta (s, "namespace/#0", "system");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == y, "did not find system key");

	keySetMeta (s, "namespace/#0", "system");
	keySetMeta (s, "namespace/#1", "user");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == y, "did not find system key");

	keySetMeta (s, "namespace/#0", "proc");
	keySetMeta (s, "namespace/#1", "user");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == p, "did not find proc key");

	keySetMeta (s, "namespace/#0", "dir");
	keySetMeta (s, "namespace/#1", 0);
	k = ksLookupByName (ks, "/first", 0);
	succeed_if_same_string (keyString (k), "default is ok");

	keySetMeta (s, "override/#0", "proc/first");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if (k == pe, "did not find override key (double indirect)");

	keySetMeta (s, "override/#0", "dir/first");
	k = ksLookupByName (ks, "/first", 0);
	succeed_if_same_string (keyString (k), "default is ok");

	ksDel (ks);
}
static void test_mmap_bad_file_permissions (const char * tmpFile)
{
	// try writing to a file with bad permissions
	if (getuid () == 0 || geteuid () == 0)
	{
		printf ("Skipping file permission test for root.\n");
		return;
	}

	Key * parentKey = keyNew (TEST_ROOT_KEY, KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("mmapstorage");
	KeySet * ks = ksNew (0, KS_END);

	FILE * fp;
	if ((fp = fopen (tmpFile, "r+")) == 0)
	{
		yield_error ("error opening file");
	}

	struct stat sbuf;
	if (stat (tmpFile, &sbuf) == -1)
	{
		yield_error ("stat() error");
	}
	fclose (fp);

	if (chmod (tmpFile, 0) != 0)
	{
		yield_error ("chmod() failed");
	}

	// open() call should fail because file permissions were wrong
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == ELEKTRA_PLUGIN_STATUS_ERROR, "kdbGet did not detect bad file permissions");

	if (chmod (tmpFile, sbuf.st_mode) != 0)
	{
		yield_error ("chmod() failed");
	}

	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
示例#21
0
static void test_readFormat (const char * format, const char * fileContent, int numKeys, const char ** keys, const char ** values)
{
	const char * tmpFile = elektraFilename ();
	FILE * fh = fopen (tmpFile, "w");
	if (fh)
	{
		fputs (fileContent, fh);
		fclose (fh);
	}

	Key * parentKey = keyNew ("user/tests/simpleini", KEY_VALUE, tmpFile, KEY_END);
	KeySet * conf = 0;
	if (format)
	{
		conf = ksNew (1, keyNew ("system/format", KEY_VALUE, format, KEY_END), KS_END);
	}
	else
	{
		conf = ksNew (0, KS_END);
	}

	PLUGIN_OPEN ("simpleini");

	KeySet * ks = ksNew (numKeys, KS_END);
	Key * key = 0;

	succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "kdbGet was not successful");

	Key * lookup = 0;
	for (int i = 0; i < numKeys; i++)
	{
		lookup = keyNew ("user/tests/simpleini", KEY_END);
		keyAddBaseName (lookup, keys[i]);
		printf ("testing key '%s'\n", keyBaseName (lookup));
		succeed_if ((key = ksLookup (ks, lookup, 0)) != NULL, "key not found");
		succeed_if (strcmp (values[i], keyString (key)) == 0, "value of key did not match");
		keyDel (lookup);
	}

	keyDel (key);
	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
示例#22
0
int main ()
{
	// clang-format off
//! [set]
KeySet * myConfig = ksNew (0, KS_END);
Key * parentKey = keyNew ("system/sw/MyApp", KEY_END);
KDB * handle = kdbOpen (parentKey);

kdbGet (handle, myConfig, parentKey); // kdbGet needs to be called first!
KeySet * base = ksDup (myConfig);     // save a copy of original keyset

// change the keys within myConfig

KeySet * ours = ksDup (myConfig); // save a copy of our keyset
KeySet * theirs;		  // needed for 3-way merging
int ret = kdbSet (handle, myConfig, parentKey);
while (ret == -1) // as long as we have an error
{
	// We got an error. Warn user.
	Key * problemKey = ksCurrent (myConfig);
	// parentKey has the errorInformation
	// problemKey is the faulty key (may be null)
	int userInput = showElektraErrorDialog (parentKey, problemKey);
	switch (userInput)
	{
	case INPUT_USE_OURS:
		kdbGet (handle, myConfig, parentKey); // refresh key database
		ksDel (myConfig);
		myConfig = ours;
		break;
	case INPUT_DO_MERGE:
		theirs = ksDup (ours);
		kdbGet (handle, theirs, parentKey); // refresh key database
		KeySet * res = doElektraMerge (ours, theirs, base);
		ksDel (theirs);
		myConfig = res;
		break;
	case INPUT_USE_THEIRS:
		// should always work, we just write what we got
		// but to be sure always give the user another way
		// to exit the loop
		kdbGet (handle, myConfig, parentKey); // refresh key database
		break;
		// other cases ...
	}
	ret = kdbSet (handle, myConfig, parentKey);
}

ksDel (ours);
ksDel (base);
ksDel (myConfig); // delete the in-memory configuration

kdbClose (handle, parentKey); // no more affairs with the key database.
keyDel (parentKey);
//! [set]
}
示例#23
0
static void test_file_crypto_operations (void)
{
	Plugin * plugin = NULL;
	Key * parentKey = keyNew ("system", KEY_END);
	KeySet * modules = ksNew (0, KS_END);
	KeySet * config = newPluginConfiguration ();

	elektraModulesInit (modules, 0);
	plugin = elektraPluginOpen (PLUGIN_NAME, modules, config, 0);
	succeed_if (plugin, "failed to open plugin handle");
	if (plugin)
	{
		KeySet * data = ksNew (0, KS_END);
		const char * tmpFile = elektraFilename ();
		if (tmpFile)
		{
			// prepare test file to be encrypted
			writeTestFile (tmpFile);
			keySetString (parentKey, tmpFile);

			// try to encrypt the file
			succeed_if (plugin->kdbSet (plugin, data, parentKey) == 1, "kdb set failed");
			succeed_if (isTestFileCorrect (tmpFile) == -1, "file content did not change during encryption");

			// try to decrypt the file again (simulating the pregetstorage call)
			succeed_if (plugin->kdbGet (plugin, data, parentKey) == 1, "kdb get (pregetstorage) failed");
			succeed_if (isTestFileCorrect (keyString (parentKey)) == 1, "file content could not be restored during decryption");

			// a second call to kdb get (the postgetstorage call) should re-encrypt the file again
			succeed_if (plugin->kdbGet (plugin, data, parentKey) == 1, "kdb get (postgetstorage) failed");
			succeed_if (isTestFileCorrect (tmpFile) == -1, "postgetstorage did not encrypt the file again");

			remove (tmpFile);
		}

		ksDel (data);
		elektraPluginClose (plugin, 0);
	}

	elektraModulesClose (modules, 0);
	ksDel (modules);
	keyDel (parentKey);
}
示例#24
0
void word_test (void)
{
	Key * parentKey = keyNew ("user/tests/validation", KEY_VALUE, "", KEY_END);
	Key * k1 = keyNew ("user/tests/validation/valid1", KEY_VALUE, "word", KEY_META, "check/validation", "word", KEY_META,
			   "check/validation/match", "word", KEY_END);
	Key * k2 = keyNew ("user/tests/validation/valid2", KEY_VALUE, "word1 word2 word3", KEY_META, "check/validation", "word2", KEY_META,
			   "check/validation/match", "word", KEY_END);
	Key * k3 = keyNew ("user/tests/validation/invalid1", KEY_VALUE, "aworda", KEY_META, "check/validation", "word", KEY_META,
			   "check/validation/match", "word", KEY_END);
	Key * k4 = keyNew ("user/tests/validation/invalid2", KEY_VALUE, "word1 word2 word3", KEY_META, "check/validation", "word", KEY_META,
			   "check/validation/match", "word", KEY_END);

	KeySet * conf = ksNew (0, KS_END);
	KeySet * ks;
	PLUGIN_OPEN ("validation");

	ks = ksNew (2, KS_END);
	ksAppendKey (ks, k1);
	ksRewind (ks);
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (1), "kdbSet failed");
	ksDel (ks);

	ks = ksNew (2, KS_END);
	ksAppendKey (ks, k2);
	ksRewind (ks);
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (1), "kdbSet failed");
	ksDel (ks);

	ks = ksNew (2, KS_END);
	ksAppendKey (ks, k3);
	ksRewind (ks);
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "kdbSet failed");
	ksDel (ks);

	ks = ksNew (2, KS_END);
	ksAppendKey (ks, k4);
	ksRewind (ks);
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == (-1), "kdbSet failed");
	ksDel (ks);

	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
示例#25
0
static void test_write2 ()
{
	Key * parentKey = keyNew ("user/tests/rename", KEY_END);
	KeySet * conf =
		ksNew (20, keyNew ("system/tolower", KEY_VALUE, "1", KEY_END), keyNew ("system/get/case", KEY_VALUE, "tolower", KEY_END),
		       keyNew ("system/set/case", KEY_VALUE, "toupper", KEY_END), KS_END);
	KeySet * ks = ksNew (20, keyNew ("user/tests/rename/UPPERCASE/UPPERCASE/UPPERCASE/LOWERCASE", KEY_VALUE, "test", KEY_END), KS_END);
	ksAppendKey (ks, parentKey);
	PLUGIN_OPEN ("rename");
	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbGet was not successful");
	Key * key = ksLookupByName (ks, "user/tests/rename/uppercase/uppercase/uppercase/lowercase", KDB_O_NONE);
	succeed_if (key, "key1 was not correctly rename");
	succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "call to kdbSet was not successful");
	key = ksLookupByName (ks, "user/tests/rename/UPPERCASE/UPPERCASE/UPPERCASE/LOWERCASE", KDB_O_NONE);
	succeed_if (key, "key1s name was not correctly saved");
	keyDel (parentKey);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
示例#26
0
static void test_emptySectionBug (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	KeySet * ks = ksNew (30, keyNew ("user/tests/ini-write/MyApp/mykey", KEY_VALUE, "new_value", KEY_END),
			     keyNew ("user/tests/ini-write/binarytest", KEY_BINARY, KEY_END),
			     keyNew ("user/tests/ini-write/debienna/test", KEY_VALUE, "value", KEY_END), KS_END);

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

	succeed_if (compare_line_files (srcdir_file (fileName), keyString (parentKey)), "files do not match as expected");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
示例#27
0
/**
 * Return all the array keys below the given arrayparent
 * The arrayparent itself is not returned.
 * For example, if user/config/# is an array,
 * user/config is the array parent.
 * Only the direct array keys will be returned. This means
 * that for example user/config/#1/key will not be included,
 * but only user/config/#1.
 *
 * A new keyset will be allocated for the resulting keys.
 * This means that the caller must ksDel the resulting keyset.
 *
 * @param arrayParent the parent of the array to be returned
 * @param keys the keyset containing the array keys.
 *
 * @return a keyset containing the arraykeys (if any)
 * @retval NULL on NULL pointers
 */
KeySet *elektraArrayGet(const Key *arrayParent, KeySet *keys)
{
	if (!arrayParent) return 0;

	if (!keys) return 0;

	KeySet *arrayKeys = ksNew(ksGetSize(keys), KS_END);
	elektraKsFilter(arrayKeys, keys, &arrayFilter, (void *)arrayParent);
	return arrayKeys;
}
示例#28
0
/**
 * Updates registrations with current data from storage.
 * Part of elektra plugin contract.
 *
 * @param  handle    plugin handle
 * @param  returned  key set containing current data from storage
 * @param  parentKey key for errors
 *
 * @retval 1 on success
 * @retval -1 on failure
 */
int elektraInternalnotificationGet (Plugin * handle, KeySet * returned, Key * parentKey)
{
	if (!elektraStrCmp (keyName (parentKey), "system/elektra/modules/internalnotification"))
	{
		KeySet * contract = ksNew (
			30,
			keyNew ("system/elektra/modules/internalnotification", KEY_VALUE,
				"internalnotification plugin waits for your orders", KEY_END),
			keyNew ("system/elektra/modules/internalnotification/exports", KEY_END),
			keyNew ("system/elektra/modules/internalnotification/exports/get", KEY_FUNC, elektraInternalnotificationGet,
				KEY_END),
			keyNew ("system/elektra/modules/internalnotification/exports/set", KEY_FUNC, elektraInternalnotificationSet,
				KEY_END),
			keyNew ("system/elektra/modules/internalnotification/exports/open", KEY_FUNC, elektraInternalnotificationOpen,
				KEY_END),
			keyNew ("system/elektra/modules/internalnotification/exports/close", KEY_FUNC, elektraInternalnotificationClose,
				KEY_END),

			keyNew ("system/elektra/modules/internalnotification/exports/notificationCallback", KEY_FUNC,
				elektraInternalnotificationDoUpdate, KEY_END),

			// Export register* functions
			INTERNALNOTIFICATION_EXPORT_FUNCTION (Int), INTERNALNOTIFICATION_EXPORT_FUNCTION (UnsignedInt),
			INTERNALNOTIFICATION_EXPORT_FUNCTION (Long), INTERNALNOTIFICATION_EXPORT_FUNCTION (UnsignedLong),
			INTERNALNOTIFICATION_EXPORT_FUNCTION (LongLong), INTERNALNOTIFICATION_EXPORT_FUNCTION (UnsignedLongLong),
			INTERNALNOTIFICATION_EXPORT_FUNCTION (Float), INTERNALNOTIFICATION_EXPORT_FUNCTION (Double),

			// Export register* functions for kdb_*_t types
			INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbBoolean), INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbChar),
			INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbOctet), INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbShort),
			INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbUnsignedShort), INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbLong),
			INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbUnsignedLong), INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbLongLong),
			INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbUnsignedLongLong), INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbFloat),
			INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbDouble), INTERNALNOTIFICATION_EXPORT_FUNCTION (KdbLongDouble),

			keyNew ("system/elektra/modules/internalnotification/exports/registerCallback", KEY_FUNC,
				elektraInternalnotificationRegisterCallback, KEY_END),
			keyNew ("system/elektra/modules/internalnotification/exports/registerCallbackSameOrBelow", KEY_FUNC,
				elektraInternalnotificationRegisterCallbackSameOrBelow, KEY_END),
			keyNew ("system/elektra/modules/internalnotification/exports/setConversionErrorCallback", KEY_FUNC,
				elektraInternalnotificationSetConversionErrorCallback, KEY_END),

#include ELEKTRA_README

			keyNew ("system/elektra/modules/internalnotification/infos/version", KEY_VALUE, PLUGINVERSION, KEY_END), KS_END);
		ksAppend (returned, contract);
		ksDel (contract);

		return 1;
	}

	elektraInternalnotificationUpdateRegisteredKeys (handle, returned);

	return 1;
}
static void test_timeoutSubscribe (void)
{
	printf ("test subscribe message timeout\n");

	Key * parentKey = keyNew ("system/tests/foo", KEY_END);
	Key * toAdd = keyNew ("system/tests/foo/bar", KEY_END);
	KeySet * ks = ksNew (0, KS_END);

	KeySet * conf = ksNew (3, keyNew ("/endpoint", KEY_VALUE, TEST_ENDPOINT, KEY_END),
			       keyNew ("/connectTimeout", KEY_VALUE, TESTCONFIG_CONNECT_TIMEOUT, KEY_END),
			       keyNew ("/subscribeTimeout", KEY_VALUE, TESTCONFIG_SUBSCRIBE_TIMEOUT, KEY_END), KS_END);
	PLUGIN_OPEN ("zeromqsend");

	// initial get to save current state
	plugin->kdbGet (plugin, ks, parentKey);

	// add key to keyset
	ksAppendKey (ks, toAdd);

	receiveTimeout = 0;
	receivedKeyName = NULL;
	receivedChangeType = NULL;

	// do not subscribe to Commit messages, this makes the plugin timeout due to no subscribers
	pthread_t * thread = startNotificationReaderThread (NULL);

	plugin->kdbSet (plugin, ks, parentKey);
	// without timeout we won't return here

	pthread_join (*thread, NULL);

	succeed_if (receiveTimeout, "receiving did not time out");
	succeed_if (receivedKeyName == NULL, "received key name should be unchanged");
	succeed_if (receivedChangeType == NULL, "received change type should be unchanged");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
	elektraFree (receivedKeyName);
	elektraFree (receivedChangeType);
	elektraFree (thread);
}
示例#30
0
static KeySet * newPluginConfigurationWithTextmodeEnabled (void)
{
	// clang-format off
	return ksNew (3,
		keyNew (ELEKTRA_RECIPIENT_KEY, KEY_VALUE, TEST_KEY_ID, KEY_END),
		keyNew (ELEKTRA_CRYPTO_PARAM_GPG_UNIT_TEST, KEY_VALUE, "1", KEY_END),
		keyNew (ELEKTRA_SIGNATURE_KEY, KEY_VALUE, TEST_KEY_ID, KEY_END),
		keyNew (ELEKTRA_FCRYPT_CONFIG_TEXTMODE, KEY_VALUE, "1", KEY_END),
		KS_END);
	// clang-format on
}