Exemplo n.º 1
0
/**
 * Generate a C-Style key and stream it.
 *
 * This keyset can be used to include as c-code for
 * applikations using elektra.
 *
 * @param key the key object to work with
 * @param stream the file pointer where to send the stream
 * @param options KDB_O_SHOWINDICES, KDB_O_IGNORE_COMMENT, KDB_O_SHOWINFO
 * @retval 1 on success
 * @ingroup stream
 */
int keyGenerate (const Key * key, FILE * stream, option_t options)
{
	size_t n = keyGetNameSize (key);
	if (n > 1)
	{
		char * nam = (char *) elektraMalloc (n);
		if (nam == NULL) return -1;
		keyGetName (key, nam, n);
		fprintf (stream, "\tkeyNew (\"%s\"", nam);
		elektraFree (nam);
	}

	size_t s = keyGetValueSize (key);
	if (s > 1)
	{
		char * str = (char *) elektraMalloc (s);
		if (str == NULL) return -1;
		if (keyIsBinary (key))
		{
			keyGetBinary (key, str, s);
			fprintf (stream, ", KEY_SIZE, \"%zd\"", keyGetValueSize (key));
		}
		else
		{
			keyGetString (key, str, s);
		}
		fprintf (stream, ", KEY_VALUE, \"%s\"", str);
		elektraFree (str);
	}

	const Key * meta;
	Key * dup = keyDup (key);
	keyRewindMeta (dup);
	while ((meta = keyNextMeta (dup)))
	{
		fprintf (stream, ", KEY_META, \"%s\", \"%s\"", keyName (meta), keyString (meta));
	}
	keyDel (dup);

	fprintf (stream, ", KEY_END)");

	if (options == 0) return 1; /* dummy to make icc happy */
	return 1;
}
Exemplo n.º 2
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 ();
}
Exemplo n.º 3
0
 FREObject LNLeapDevice::getConfigType(uint32_t len, const uint8_t* key) {
     std::string keyString( key, key+len );
     
     int type;
     
     switch (controller->config().type(keyString)) {
         case Config::TYPE_UNKNOWN:
         {
             type = 0;
             break;
         }
         case Config::TYPE_BOOLEAN:
         {
             type = 1;
             break;
         }
         case Config::TYPE_INT32:
         {
             type = 2;
             break;
         }
         case Config::TYPE_FLOAT:
         {
             type = 6;
             break;
         }
         case Config::TYPE_STRING:
         {
             type = 8;
             break;
         }
         default:
         {
             type = 0;
             break;
         }
     }
     
     FREObject freReturnValue;
     FRENewObjectFromInt32(type, &freReturnValue);
     
     return freReturnValue;
 }
Exemplo n.º 4
0
/**
 * @brief read the desired iteration count from config
 * @param errorKey may hold a warning if an invalid configuration is provided
 * @param config KeySet holding the plugin configuration
 * @returns the number of iterations for the key derivation function
 */
kdb_unsigned_long_t CRYPTO_PLUGIN_FUNCTION (getIterationCount) (Key * errorKey, KeySet * config)
{
	Key * k = ksLookupByName (config, ELEKTRA_CRYPTO_PARAM_ITERATION_COUNT, 0);
	if (k)
	{
		const kdb_unsigned_long_t iterations = strtoul (keyString (k), NULL, 10);
		if (iterations > 0)
		{
			return iterations;
		}
		else
		{
			ELEKTRA_ADD_WARNING (ELEKTRA_WARNING_CRYPTO_CONFIG, errorKey,
					     "iteration count provided at " ELEKTRA_CRYPTO_PARAM_ITERATION_COUNT
					     " is invalid. Using default value instead.");
		}
	}
	return ELEKTRA_CRYPTO_DEFAULT_ITERATION_COUNT;
}
Exemplo n.º 5
0
/**
 * @internal
 *
 * @brief Check if an update is needed at all
 *
 * @retval -1 an error occurred
 * @retval 0 no update needed
 * @retval number of plugins which need update
 */
static int elektraGetCheckUpdateNeeded (Split * split, Key * parentKey)
{
	int updateNeededOccurred = 0;
	for (size_t i = 0; i < split->size; i++)
	{
		int ret = -1;
		Backend * backend = split->handles[i];
		clear_bit (split->syncbits[i], 1);

		if (backend->getplugins[RESOLVER_PLUGIN] && backend->getplugins[RESOLVER_PLUGIN]->kdbGet)
		{
			ksRewind (split->keysets[i]);
			keySetName (parentKey, keyName (split->parents[i]));
			keySetString (parentKey, "");
			ret = backend->getplugins[RESOLVER_PLUGIN]->kdbGet (backend->getplugins[RESOLVER_PLUGIN], split->keysets[i],
									    parentKey);
			// store resolved filename
			keySetString (split->parents[i], keyString (parentKey));
			// no keys in that backend
			backendUpdateSize (backend, split->parents[i], 0);
		}
		// TODO: set error in else case!

		switch (ret)
		{
		case 1:
			// Seems like we need to sync that
			set_bit (split->syncbits[i], SPLIT_FLAG_SYNC);
			++updateNeededOccurred;
			break;
		case 0:
			// Nothing to do here
			break;
		default:
			ELEKTRA_ASSERT (0, "resolver did not return 1 0 -1, but %d", ret);
		case -1:
			// Ohh, an error occurred, lets stop the
			// process.
			return -1;
		}
	}
	return updateNeededOccurred;
}
Exemplo n.º 6
0
int elektraWresolverOpen (Plugin * handle, Key * errorKey)
{
	KeySet * resolverConfig = elektraPluginGetConfig (handle);
	const char * path = keyString (ksLookupByName (resolverConfig, "/path", 0));

	if (!path)
	{
		ELEKTRA_SET_ERROR (34, errorKey, "Could not find file configuration");
		return -1;
	}

	resolverHandles * p = elektraMalloc (sizeof (resolverHandles));

	// switch is only present to forget no namespace and to get
	// a warning whenever a new namespace is present.
	// (also used below in close)
	// In fact its linear code executed:
	switch (KEY_NS_SPEC)
	{
	case KEY_NS_SPEC:
		resolverInit (&p->spec, path);
		elektraResolveSpec (&p->spec, errorKey);
	case KEY_NS_DIR:
		resolverInit (&p->dir, path);
		elektraResolveDir (&p->dir, errorKey);
	case KEY_NS_USER:
		resolverInit (&p->user, path);
		elektraResolveUser (&p->user, errorKey);
	case KEY_NS_SYSTEM:
		resolverInit (&p->system, path);
		elektraResolveSystem (&p->system, errorKey);
	case KEY_NS_PROC:
	case KEY_NS_EMPTY:
	case KEY_NS_NONE:
	case KEY_NS_META:
	case KEY_NS_CASCADING:
		break;
	}

	elektraPluginSetData (handle, p);

	return 0; /* success */
}
Exemplo n.º 7
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 ();
}
Name
IdentityCertificate::certificateNameToPublicKeyName(const Name& certificateName)
{
  int i = certificateName.size() - 1;
  string idString("ID-CERT");
  for (; i >= 0; i--) {
    if (certificateName.get(i).toEscapedString() == idString)
      break;
  }

  Name tmpName = certificateName.getSubName(0, i);
  string keyString("KEY");
  for (i = 0; i < tmpName.size(); i++) {
    if (tmpName.get(i).toEscapedString() == keyString)
      break;
  }

  return tmpName.getSubName(0, i).append(tmpName.getSubName(i + 1, tmpName.size() - i - 1));
}
Exemplo n.º 9
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);
}
static void test_ifsetthenkey()
{
	Key *parentKey = keyNew("user/tests/conditionals", KEY_VALUE, "", KEY_END);
	KeySet *ks = ksNew(5,
	keyNew("user/tests/conditionals/totest", KEY_VALUE, "", KEY_META, "check/condition", "(totest=='') ? (totest := bla/val1)", 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");
	Key *key = ksLookupByName(ks, "user/tests/conditionals/totest", 0);
	succeed_if(strcmp(keyString(key), "100") == 0, "error setting then value");
	ksDel(ks);
	keyDel(parentKey);
	PLUGIN_CLOSE();

}
Exemplo n.º 11
0
Name
IdentityManager::getKeyNameFromCertificatePrefix(const Name & certificatePrefix)
{
  Name result;

  string keyString("KEY");
  int i = 0;
  for(; i < certificatePrefix.size(); i++) {
    if (certificatePrefix.get(i).toEscapedString() == keyString)
      break;
  }

  if (i >= certificatePrefix.size())
    throw SecurityException("Identity Certificate Prefix does not have a KEY component");

  result.append(certificatePrefix.getSubName(0, i));
  result.append(certificatePrefix.getSubName(i + 1, certificatePrefix.size()-i-1));

  return result;
}
Exemplo n.º 12
0
static OnConflict getConfOption (Key * key)
{
	const char * string = keyString (key);
	if (!strcmp (string, "ERROR"))
	{
		return ERROR;
	}
	else if (!strcmp (string, "WARNING"))
	{
		return WARNING;
	}
	else if (!strcmp (string, "INFO"))
	{
		return INFO;
	}
	else
	{
		return IGNORE;
	}
}
bool
createTXTRecord(scopedTXTRecord& txtRecord, Local<Object>& object) {
    HandleScope scope;
    Local<Array> names = object->GetPropertyNames();
    uint32_t length = names->Length();

    for (uint32_t index = 0; index<length; ++index) {
        Local<Value> key = names->Get(index);

        if (key->IsString()) {
            // Local<Value> buffer = object->Get(key);
            Handle<Value> buffer = object->Get(key);
            String::Utf8Value string_value( buffer->ToString());

            // A DNS-SD key is 7-bit ascii
            String::AsciiValue keyString(key);
            std::string buf(*keyString, keyString.length());

 /*           Local<Object> obj;
            uint8_t valLen = 0;
            const void *value = NULL;

            if (Buffer::HasInstance(buffer)) {
                obj = buffer->ToObject();
                valLen = Buffer::Length(obj);
                value = Buffer::Data(obj);
            }

            if (txtRecord.setValue(buf.c_str(), valLen, value) != kDNSServiceErr_NoError) {
                return false;
            }
*/        
            if (txtRecord.setValue(buf.c_str(), buffer->ToString()->Utf8Length(), *string_value) != kDNSServiceErr_NoError) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}
Exemplo n.º 14
0
void testReadSingleLine (const char * fileName)
{
	Key * parentKey = keyNew ("user/tests/file", KEY_VALUE, srcdir_file (fileName), KEY_END);

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

	KeySet * ks = ksNew (0, KS_END);

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

	const Key * key = ksLookupByName (ks, "user/tests/file", KDB_O_NONE);
	exit_if_fail (key, "key not found");

	succeed_if (!strcmp ("this is a single line testfile\n", keyString (key)), "read single line data doesn't match expected string");

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Exemplo n.º 15
0
static void test_writePref (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/pref-write", KEY_VALUE, elektraFilename (), KEY_END);
	KeySet * conf = ksNew (0, KS_END);

	PLUGIN_OPEN ("mozprefs");

	KeySet * ks = ksNew (
		30, keyNew ("user/tests/pref-write/user/a/user/key", KEY_VALUE, "usertest", KEY_META, "type", "string", KEY_END),
		keyNew ("user/tests/pref-write/lock/a/lock/key", KEY_VALUE, "true", KEY_META, "type", "boolean", KEY_END),
		keyNew ("user/tests/pref-write/pref/a/default/key", KEY_VALUE, "1", KEY_META, "type", "integer", KEY_END),
		keyNew ("user/tests/pref-write/sticky/a/sticky/key", KEY_VALUE, "false", KEY_META, "type", "boolean", 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 (fileName), keyString (parentKey)), "files do not match as expected");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Exemplo n.º 16
0
static void setOrderNumber(Key *parentKey, Key *key)
{
	kdb_long_long_t order = 0;
	const Key *orderKey = keyGetMeta(parentKey, "order");
	if (orderKey != NULL)
	{
		char *ptr = (char *)keyString(orderKey);
		++ptr; //skip #
		while (*ptr == '_')
		{
			++ptr;
		}
		elektraReadArrayNumber(ptr, &order);

	}
	++order;
	char buffer[ELEKTRA_MAX_ARRAY_SIZE];
	elektraWriteArrayNumber(buffer, order);
	keySetMeta(key, "order", buffer);
	keySetMeta(parentKey, "order", buffer);
}
Exemplo n.º 17
0
static void test_getArrayNext (void)
{
	printf ("Test get array next");

	KeySet * array = ksNew (10, keyNew ("user/test/array/#0", KEY_END), keyNew ("user/test/array/#1", KEY_END),

				KS_END);

	Key * nextKey = elektraArrayGetNextKey (array);
	exit_if_fail (array, "The getnext function did not return a proper key");
	succeed_if (!strcmp (keyName (nextKey), "user/test/array/#2"), "The getnext function did not use the correct keyname");
	succeed_if (!strcmp (keyString (nextKey), ""), "The getnext function did not return an empty key");

	keyDel (nextKey);
	ksClear (array);
	nextKey = elektraArrayGetNextKey (array);
	succeed_if (!nextKey, "The getnext function did not return NULL on an empty array");
	keyDel (nextKey);

	ksDel (array);
}
Exemplo n.º 18
0
void elektraMetaArrayAdd (Key * key, const char * metaName, const char * value)
{
	const Key * meta = keyGetMeta (key, metaName);
	Key * arrayKey;
	if (!meta)
	{
		keySetMeta (key, metaName, "#0");
		arrayKey = keyDup (keyGetMeta (key, metaName));
		keySetString (arrayKey, 0);
		keyAddBaseName (arrayKey, "#");
	}
	else
	{
		arrayKey = keyDup (meta);
		keyAddBaseName (arrayKey, keyString (meta));
	}
	elektraArrayIncName (arrayKey);
	keySetMeta (key, keyName (arrayKey), value);
	keySetMeta (key, metaName, keyBaseName (arrayKey));
	keyDel (arrayKey);
}
Exemplo n.º 19
0
static void test_commentIniRead (char * fileName)
{
	Key * parentKey = keyNew ("user/tests/ini-read", KEY_VALUE, srcdir_file (fileName), KEY_END);

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

	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/ini-read/nosectionkey", KDB_O_NONE);
	exit_if_fail (key, "nosectionkey not found");
	const Key * noSectionComment = keyGetMeta (key, "comments/#0");
	exit_if_fail (noSectionComment, "nosectionkey contained no comment");
	succeed_if (!strcmp (";nosection comment1", keyString (noSectionComment)), "nosectionkey contained an invalid comment");
	noSectionComment = keyGetMeta (key, "comments/#1");
	exit_if_fail (noSectionComment, "nosectionkey contained no comment");
	succeed_if (!strcmp (";nosection comment2", keyString (noSectionComment)), "nosectionkey contained an invalid comment");


	key = ksLookupByName (ks, "user/tests/ini-read/section1", KDB_O_NONE);
	exit_if_fail (key, "section1 not found");
	const Key * sectionComment = keyGetMeta (key, "comments/#0");
	exit_if_fail (sectionComment, "sectionkey contained no comment");
	succeed_if (!strcmp (";section comment1", keyString (sectionComment)), "sectionkey contained an invalid comment");
	sectionComment = keyGetMeta (key, "comments/#1");
	exit_if_fail (sectionComment, "sectionkey contained no comment");
	succeed_if (!strcmp (";section comment2", keyString (sectionComment)), "sectionkey contained an invalid comment");


	key = ksLookupByName (ks, "user/tests/ini-read/section1/key1", KDB_O_NONE);
	exit_if_fail (key, "key1 not found");
	const Key * keyComment_ = keyGetMeta (key, "comments/#0");
	exit_if_fail (keyComment_, "key1 contained no comment");
	succeed_if (!strcmp (";key comment1", keyString (keyComment_)), "key1 contained an invalid comment");
	keyComment_ = keyGetMeta (key, "comments/#1");
	exit_if_fail (keyComment_, "key1 contained no comment");
	succeed_if (!strcmp (";key comment2", keyString (keyComment_)), "key1 contained an invalid comment");


	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Exemplo n.º 20
0
static void insertNewKeyIntoExistendOrder(Key *key, KeySet *ks)
{
	if (keyGetMeta(ksLookup(ks, key, KDB_O_NONE), "order"))
		return;
	ksRewind(ks);	
	Key *curKey;
	Key *prevKey = NULL;
	while ((curKey = ksNext(ks)) != NULL)
	{
		if (!strcmp(keyName(curKey), keyName(key)))
		{
			const char *oldOrder = "#1";
			if (keyGetMeta(prevKey, "order"))
			{
				oldOrder = keyString(keyGetMeta(prevKey, "order"));
			}
			setSubOrderNumber(key, oldOrder);
		}	
		prevKey = curKey;
	}
}
Exemplo n.º 21
0
static void test_get (void)
{
	char const * const fileName = "camel/simple.yaml";
	printf ("• Parse file “%s”\n", fileName);

	char const * const prefix = "user/camel/tests/read";
	Key * parentKey = keyNew (prefix, KEY_VALUE, srcdir_file (fileName), KEY_END);
	KeySet * conf = ksNew (0, KS_END);
	PLUGIN_OPEN ("camel");

	KeySet * keySet = ksNew (0, KS_END);

	int status = plugin->kdbGet (plugin, keySet, parentKey);

	succeed_if (status == ELEKTRA_PLUGIN_STATUS_SUCCESS || status == ELEKTRA_PLUGIN_STATUS_NO_UPDATE, "Unable to open or parse file");
	succeed_if (output_error (parentKey), "Received unexpected error while reading the configuration");

	char keyValues[][2][50] = {
		{ "hello", "world" },
	};

	Key * key;
	char text[MAX_LENGTH_TEXT];
	for (size_t pair = 0; pair < sizeof (keyValues) / sizeof (keyValues[0]); pair++)
	{
		char * name = keyValues[pair][0];
		char * value = keyValues[pair][1];
		snprintf (text, MAX_LENGTH_TEXT, "%s/%s", prefix, name);
		key = ksLookupByName (keySet, text, KDB_O_NONE);

		snprintf (text, MAX_LENGTH_TEXT, "Key “%s” not found", name);
		exit_if_fail (key, text);

		succeed_if_same_string (keyString (key), value);
	}

	keyDel (parentKey);
	ksDel (keySet);
	PLUGIN_CLOSE ();
}
Exemplo n.º 22
0
void test_plainIniWrite(char *fileName)
{
	Key *parentKey = keyNew ("user/tests/ini-write", KEY_VALUE,
			elektraFilename(), KEY_END);
	KeySet *conf = ksNew (0);
	PLUGIN_OPEN("ini");

	KeySet *ks = ksNew (30,
			keyNew ("user/tests/ini-write/nosectionkey",
					KEY_VALUE, "nosectionvalue",
					KEY_END),
			keyNew ("user/tests/ini-write/section1", KEY_DIR, KEY_END),
			keyNew ("user/tests/ini-write/section1/key1",
					KEY_VALUE, "value1",
					KEY_END),
			keyNew ("user/tests/ini-write/section1/key2",
					KEY_VALUE, "value2",
					KEY_END),
			keyNew ("user/tests/ini-write/section2", KEY_DIR, KEY_END),
			keyNew ("user/tests/ini-write/section2/key3",
					KEY_VALUE, "value3",
					KEY_END),
			keyNew ("user/tests/ini-write/section2/emptykey", KEY_END),
			KS_END);

	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 ()
	;
}
Exemplo n.º 23
0
/**
 * @brief Output warnings if present
 *
 * To check for warnings use:
 * succeed_if(output_warnings(parentKey), "warning(s) found");
 *
 * @param warningKey the key to retrieve metadata from
 *
 * @see check_for_errors_and_warnings if you want errors to have a test case failed without output
 *
 * @return 1 if no warnings (can be used within succeed_if)
 */
int output_warnings(Key *warningKey)
{
	const Key *metaWarnings = keyGetMeta(warningKey, "warnings");
	if (!metaWarnings) return 1; /* There are no current warnings */

	int nrWarnings = atoi(keyString(metaWarnings));
	char buffer[] = "warnings/#00\0description";

	printf ("There are %d warnings\n", nrWarnings+1);
	for (int i=0; i<=nrWarnings; ++i)
	{
		buffer[10] = i/10%10 + '0';
		buffer[11] = i%10 + '0';
		printf ("buffer is: %s\n", buffer);
		strncat(buffer, "/number" , sizeof(buffer) -1);
		printf ("number: %s\n", keyString(keyGetMeta(warningKey, buffer)));
		buffer[12] = '\0'; strncat(buffer, "/description" , sizeof(buffer) -1);
		printf ("description: %s\n", keyString(keyGetMeta(warningKey, buffer)));
		buffer[12] = '\0'; strncat(buffer, "/ingroup" , sizeof(buffer) -1);
		keyGetMeta(warningKey, buffer);
		printf ("ingroup: %s\n", keyString(keyGetMeta(warningKey, buffer)));
		buffer[12] = '\0'; strncat(buffer, "/module" , sizeof(buffer) -1);
		keyGetMeta(warningKey, buffer);
		printf ("module: %s\n", keyString(keyGetMeta(warningKey, buffer)));
		buffer[12] = '\0'; strncat(buffer, "/file" , sizeof(buffer) -1);
		keyGetMeta(warningKey, buffer);
		printf ("file: %s\n", keyString(keyGetMeta(warningKey, buffer)));
		buffer[12] = '\0'; strncat(buffer, "/line" , sizeof(buffer) -1);
		keyGetMeta(warningKey, buffer);
		printf ("line: %s\n", keyString(keyGetMeta(warningKey, buffer)));
		buffer[12] = '\0'; strncat(buffer, "/reason" , sizeof(buffer) -1);
		keyGetMeta(warningKey, buffer);
		printf ("reason: %s\n", keyString(keyGetMeta(warningKey, buffer)));
	}

	return 0;
}
Exemplo n.º 24
0
/**
 * Helper function for code generation.
 *
 * Finds an array element Key from its relative name and index.
 * Also checks type metadata, if @p type is not NULL.
 *
 * @param elektra The Elektra instance to use.
 * @param name    The relative name of the array.
 * @param index   The index of the array element.
 * @param type    The expected type metadata value.
 * @return the Key referenced by @p name or NULL, if a fatal error occurs and the fatal error handler returns to this function
 */
Key * elektraFindArrayElementKey (Elektra * elektra, const char * name, size_t index, KDBType type)
{
	elektraSetArrayLookupKey (elektra, name, index);
	Key * const resultKey = ksLookup (elektra->config, elektra->lookupKey, 0);
	if (resultKey == NULL)
	{
		elektraFatalError (elektra, elektraErrorKeyNotFound (keyName (elektra->lookupKey)));
		return NULL;
	}

	if (type != NULL)
	{
		const char * actualType = keyString (keyGetMeta (resultKey, "type"));
		if (strcmp (actualType, type) != 0)
		{
			elektraFatalError (elektra, elektraErrorWrongType (keyName (elektra->lookupKey), type, actualType));
			return NULL;
		}
	}

	return resultKey;
}
Exemplo n.º 25
0
void testRoundTrip (const char * fileName)
{
	Key * parentKey = keyNew ("user/tests/file", KEY_VALUE, srcdir_file (fileName), KEY_END);

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

	KeySet * ks = ksNew (0, KS_END);

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

	keySetString (parentKey, elektraFilename ());

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

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

	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Exemplo n.º 26
0
int main()
{
	KeySet *myConfig = ksNew(0, KS_END);
	Key *key = keyNew("system/test/myapp",KEY_END);
	KDB *handle = kdbOpen(key);

	kdbGet(handle, myConfig, key);

	keySetName(key, "user/test/myapp");
	kdbGet(handle, myConfig, key);

	// check for errors in key
	keyDel(key);

	/*
	ksRewind(myConfig);
	while ((key = ksNext(myConfig)))
	{
		printf ("%s\n", keyName(key));
	}
	*/

	key = ksLookupByName(myConfig,"/test/myapp/key", 0);

	// check if key is not 0 and work with it...
	if (key)
	{
		printf("%s\n", keyString(key));
	}

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


	// maybe you want kdbSet() myConfig here

	kdbClose(handle, 0); // no more affairs with the key database.
	return 0;
}
Exemplo n.º 27
0
static void test_complexInsert (char * source, char * compare)
{
	Key * parentKey = keyNew ("user/tests/ini-write", KEY_VALUE, srcdir_file (source), 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);
	KeySet * appendKS = ksNew (10, keyNew ("user/tests/ini-write/section/subsection", KEY_BINARY, KEY_END),
				   keyNew ("user/tests/ini-write/section/subsection/subkey", KEY_VALUE, "subval", KEY_END),
				   keyNew ("user/tests/ini-write/section/zkey3", KEY_VALUE, "3", KEY_END), 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);
	ksAppend (ks, appendKS);
	succeed_if (plugin->kdbSet (plugin, ks, writeParentKey) >= 1, "call to kdbSet was not successful");
	succeed_if (compare_line_files (srcdir_file (compare), keyString (writeParentKey)), "files do not match as expected");
	keyDel (ksLookup (ks, writeParentKey, KDB_O_POP));
	keyDel (writeParentKey);
	ksDel (appendKS);
	ksDel (ks);
	PLUGIN_CLOSE ();
}
Name
IdentityCertificate::certificateNameToPublicKeyName(const Name& certificateName)
{
  string idString("ID-CERT");
  bool foundIdString = false;
  size_t idCertComponentIndex = certificateName.size() - 1;
  for (; idCertComponentIndex + 1 > 0; --idCertComponentIndex) {
    if (certificateName.get(idCertComponentIndex).toUri() == idString)
      {
        foundIdString = true;
        break;
      }
  }

  if (!foundIdString)
    throw Error("Incorrect identity certificate name " + certificateName.toUri());

  Name tmpName = certificateName.getSubName(0, idCertComponentIndex);
  string keyString("KEY");
  bool foundKeyString = false;
  size_t keyComponentIndex = 0;
  for (; keyComponentIndex < tmpName.size(); keyComponentIndex++) {
    if (tmpName.get(keyComponentIndex).toUri() == keyString)
      {
        foundKeyString = true;
        break;
      }
  }

  if (!foundKeyString)
    throw Error("Incorrect identity certificate name " + certificateName.toUri());

  return tmpName
           .getSubName(0, keyComponentIndex)
           .append(tmpName.getSubName(keyComponentIndex + 1,
                                      tmpName.size() - keyComponentIndex - 1));
}
void test_name()
{
	printf ("Resolve Name\n");

	KeySet *modules = ksNew(0, KS_END);
	elektraModulesInit (modules, 0);

	Plugin *plugin = elektraPluginOpen("resolver", modules, set_pluginconf(), 0);
	exit_if_fail (plugin, "could not load resolver plugin");

	KeySet *test_config = set_pluginconf();
	KeySet *config = elektraPluginGetConfig (plugin);
	succeed_if (config != 0, "there should be a config");
	compare_keyset(config, test_config);
	ksDel (test_config);

	succeed_if (plugin->kdbOpen != 0, "no open pointer");
	succeed_if (plugin->kdbClose != 0, "no open pointer");
	succeed_if (plugin->kdbGet != 0, "no open pointer");
	succeed_if (plugin->kdbSet != 0, "no open pointer");
	succeed_if (plugin->kdbError!= 0, "no open pointer");

	succeed_if (!strcmp(plugin->name, "resolver"), "got wrong name");

	resolverHandles *h = elektraPluginGetData(plugin);
	succeed_if (h != 0, "no plugin handle");

	Key *parentKey= keyNew("system", KEY_END);
	plugin->kdbGet(plugin, 0, parentKey);
	succeed_if (!strcmp(keyString(parentKey), KDB_DB_SYSTEM "/elektra.ecf"),
			"resulting filename not correct");

	keyDel (parentKey);
	elektraPluginClose(plugin, 0);
	elektraModulesClose(modules, 0);
	ksDel (modules);
}
Exemplo n.º 30
0
STDMETHODIMP CMapiImp::ReadMail(unsigned long aSession, unsigned long ulUIParam, LPTSTR lpszMessageID,
                              unsigned long flFlags, unsigned long ulReserved, lpnsMapiMessage *lppMessage)
{
  PRInt32 irv;
  nsCAutoString keyString((char *) lpszMessageID);
  PR_LOG(MAPI, PR_LOG_DEBUG, ("CMapiImp::ReadMail asking for key %s\n", (char *) lpszMessageID));
  nsMsgKey msgKey = keyString.ToInteger(&irv);
  if (irv)
  {
    NS_ASSERTION(PR_FALSE, "invalid lpszMessageID");
    return MAPI_E_INVALID_MESSAGE;
  }
  MsgMapiListContext *listContext;
  LONG ret = InitContext(aSession, &listContext);
  if (ret != SUCCESS_SUCCESS)
  {
    NS_ASSERTION(PR_FALSE, "init context failed in ReadMail");
    return ret;
  }
  *lppMessage = listContext->GetMessage (msgKey, flFlags);
  NS_ASSERTION(*lppMessage, "get message failed");

  return (*lppMessage) ? SUCCESS_SUCCESS : E_FAIL;
}