示例#1
0
文件: meta.c 项目: 0003088/libelektra
/**
 * @internal
 *
 * elektraSortTopology helper
 * returns the index of dependency depKey
 */
static int getArrayIndex (Key * depKey, _adjMatrix * adjMatrix, size_t size)
{
	for (unsigned int i = 0; i < size; ++i)
	{
		if (!strcmp (keyName (adjMatrix[i].key), keyString (depKey))) return i;
	}
	return -1;
}
示例#2
0
std::string StyleParam::toString() const {

    std::string k(keyName(key));
    k += " : ";

    // TODO: cap, join and color toString()
    if (value.is<none_type>()) {
        return k + "undefined";
    }

    switch (key) {
    case StyleParamKey::extrude: {
        if (!value.is<glm::vec2>()) break;
        auto p = value.get<glm::vec2>();
        return k + "(" + std::to_string(p[0]) + ", " + std::to_string(p[1]) + ")";
    }
    case StyleParamKey::size:
    case StyleParamKey::offset: {
        if (!value.is<glm::vec2>()) break;
        auto p = value.get<glm::vec2>();
        return k + "(" + std::to_string(p.x) + "px, " + std::to_string(p.y) + "px)";
    }
    case StyleParamKey::font_family:
    case StyleParamKey::font_weight:
    case StyleParamKey::font_style:
    case StyleParamKey::text_source:
    case StyleParamKey::transform:
    case StyleParamKey::sprite:
    case StyleParamKey::sprite_default:
        if (!value.is<std::string>()) break;
        return k + value.get<std::string>();
    case StyleParamKey::visible:
        if (!value.is<bool>()) break;
        return k + std::to_string(value.get<bool>());
    case StyleParamKey::width:
    case StyleParamKey::outline_width:
    case StyleParamKey::font_stroke_width:
    case StyleParamKey::font_size:
        if (!value.is<float>()) break;
        return k + std::to_string(value.get<float>());
    case StyleParamKey::order:
    case StyleParamKey::priority:
    case StyleParamKey::color:
    case StyleParamKey::outline_color:
    case StyleParamKey::font_fill:
    case StyleParamKey::font_stroke:
    case StyleParamKey::font_stroke_color:
    case StyleParamKey::cap:
    case StyleParamKey::outline_cap:
    case StyleParamKey::join:
    case StyleParamKey::outline_join:
        if (!value.is<uint32_t>()) break;
        return k + std::to_string(value.get<uint32_t>());
    case StyleParamKey::none:
        break;
    }
    return k + "undefined";
}
示例#3
0
文件: tracer.c 项目: tryge/libelektra
int elektraTracerGet(Plugin *handle, KeySet *returned, Key *parentKey)
{
    ssize_t nr_keys = 0;
    Key *k=0;

    if (!strcmp(keyName(parentKey), "system/elektra/modules/tracer"))
    {
        KeySet *info =
            ksNew(50,
                  keyNew ("system/elektra/modules/tracer",
                          KEY_VALUE, "tracer plugin waits for your orders", KEY_END),
                  keyNew ("system/elektra/modules/tracer/exports", KEY_END),
                  keyNew ("system/elektra/modules/tracer/exports/open",
                          KEY_FUNC, elektraTracerOpen,
                          KEY_END),
                  keyNew ("system/elektra/modules/tracer/exports/close",
                          KEY_FUNC, elektraTracerClose,
                          KEY_END),
                  keyNew ("system/elektra/modules/tracer/exports/get",
                          KEY_FUNC, elektraTracerGet,
                          KEY_END),
                  keyNew ("system/elektra/modules/tracer/exports/set",
                          KEY_FUNC, elektraTracerSet,
                          KEY_END),
                  keyNew ("system/elektra/modules/tracer/exports/error",
                          KEY_FUNC, elektraTracerError,
                          KEY_END),
#include "readme_tracer.c"
                  keyNew ("system/elektra/modules/tracer/infos/version",
                          KEY_VALUE, PLUGINVERSION, KEY_END),
                  KS_END);
        ksAppend(returned, info);
        ksDel (info);
        return 1;
    }

    printf ("tracer: get(%p, %s, %s): ", (void*)handle, keyName(parentKey), keyString(parentKey));
    while ((k = ksNext(returned))!=0) {
        printf ("%s ", keyName(k));
        ++nr_keys;
    }
    printf ("%zd\n", nr_keys);

    return nr_keys;
}
示例#4
0
int elektraTracerClose (Plugin * handle, Key * errorKey)
{
	KeySet * config = elektraPluginGetConfig (handle);

	if (ksLookupByName (config, "/module", 0))
	{
		if (ksLookupByName (config, "/logmodule", 0))
		{
			printf ("tracer: closemodule(%p, %s = %s)\n", (void *) handle, keyName (errorKey), keyString (errorKey));
		}
	}
	else
	{
		printf ("tracer: close(%p, %s = %s)\n", (void *) handle, keyName (errorKey), keyString (errorKey));
	}

	return 0;
}
示例#5
0
static int elektraYajlParseStartArray (void * ctx)
{
	KeySet * ks = (KeySet *)ctx;
	elektraYajlIncrementArrayEntry (ks);

	Key * currentKey = ksCurrent (ks);

	Key * newKey = keyNew (keyName (currentKey), KEY_END);
	// add a pseudo element for empty array
	keyAddName (newKey, "###empty_array");
	ksAppendKey (ks, newKey);

#ifdef ELEKTRA_YAJL_VERBOSE
	printf ("elektraYajlParseStartArray with new key %s\n", keyName (newKey));
#endif

	return 1;
}
示例#6
0
static void announceKeys (KeySet * ks, const char * signalName, DBusBusType busType)
{
	ksRewind (ks);
	Key * k = 0;
	while ((k = ksNext (ks)) != 0)
	{
		elektraDbusSendMessage (busType, keyName (k), signalName);
	}
}
示例#7
0
void removeKeyFromResult (Key * convertKey, Key * target, KeySet * orig)
{
    /* remember which key this key was converted to
     * before removing it from the result
     */
    keySetMeta (convertKey, CONVERT_TARGET, keyName (target));
    Key * key = ksLookup (orig, convertKey, KDB_O_POP);
    keyDel (key);
}
示例#8
0
/**
 * @internal
 *
 * Compare 2 keys.
 *
 * The returned flags bit array has 1s (differ) or 0s (equal) for each key
 * meta info compared, that can be logically ORed using @c #keyswitch_t flags.
 * @link keyswitch_t::KEY_NAME KEY_NAME @endlink,
 * @link keyswitch_t::KEY_VALUE KEY_VALUE @endlink,
 * @link keyswitch_t::KEY_OWNER KEY_OWNER @endlink,
 * @link keyswitch_t::KEY_COMMENT KEY_COMMENT @endlink,
 * @link keyswitch_t::KEY_META KEY_META @endlink (will be set in addition to owner and comment),
 *
 * @par A very simple example would be
 * @code
 Key *key1, *key;
 uint32_t changes;

// omited key1 and key2 initialization and manipulation

changes=keyCompare(key1,key2);

if (changes == 0) printf("key1 and key2 are identicall\n");

if (changes & KEY_VALUE)
printf("key1 and key2 have different values\n");

if (changes & KEY_UID)
printf("key1 and key2 have different UID\n");

 *
 * @endcode
 *
 *
 * @par Example of very powerful specific Key lookup in a KeySet:
 * @code
 Key *base = keyNew ("/sw/MyApp/something", KEY_END);
 KDB *handle = kdbOpen(base);
 KeySet *ks=ksNew(0, KS_END);
 Key *current;
 uint32_t match;
 uint32_t interests;


 kdbGet(handle, ks, base);

// we are interested only in key type and access permissions
interests=(KEY_TYPE | KEY_MODE);

ksRewind(ks);	// put cursor in the beginning
while ((curren=ksNext(ks))) {
match=keyCompare(current,base);

if ((~match & interests) == interests)
printf("Key %s has same type and permissions of base key",keyName(current));

// continue walking in the KeySet....
}

// now we want same name and/or value
interests=(KEY_NAME | KEY_VALUE);

// we don't really need ksRewind(), since previous loop achieved end of KeySet
ksRewind(ks);
while ((current=ksNext(ks))) {
match=keyCompare(current,base);

if ((~match & interests) == interests) {
printf("Key %s has same name, value, and sync status
of base key",keyName(current));
}
// continue walking in the KeySet....
}

ksDel(ks);
kdbClose (handle, base);
keyDel(base);
* @endcode
*
* @return a bit array pointing the differences
* @param key1 first key
* @param key2 second key
* @see #keyswitch_t
* @ingroup keytest
	*/
keyswitch_t keyCompare (const Key * key1, const Key * key2)
{
	if (!key1 && !key2) return 0;
	if (!key1 || !key2) return KEY_NULL;

	keyswitch_t ret = 0;
	ssize_t nsize1 = keyGetNameSize (key1);
	ssize_t nsize2 = keyGetNameSize (key2);
	const char * name1 = keyName (key1);
	const char * name2 = keyName (key2);
	const Key * comment1 = keyGetMeta (key1, "comment");
	const Key * comment2 = keyGetMeta (key2, "comment");
	const char * owner1 = keyOwner (key1);
	const char * owner2 = keyOwner (key2);
	const void * value1 = keyValue (key1);
	const void * value2 = keyValue (key2);
	ssize_t size1 = keyGetValueSize (key1);
	ssize_t size2 = keyGetValueSize (key2);

	// TODO: might be (binary) by chance
	if (strcmp (keyString (comment1), keyString (comment2))) ret |= KEY_COMMENT;

	if (strcmp (owner1, owner2)) ret |= KEY_OWNER;

	if (keyCompareMeta (key1, key2)) ret |= KEY_META;

	if (nsize1 != nsize2)
		ret |= KEY_NAME;
	else if (!name1 || !name2)
		ret |= KEY_NAME;
	else if (strcmp (name1, name2))
		ret |= KEY_NAME;


	if (size1 != size2)
		ret |= KEY_VALUE;
	else if (!value1 || !value2)
		ret |= KEY_VALUE;
	else if (memcmp (value1, value2, size1))
		ret |= KEY_VALUE;

	// TODO: rewind metadata to previous position
	return ret;
}
示例#9
0
static int saveTree (augeas * augeasHandle, KeySet * ks, const char * lensPath, Key * parentKey)
{
	int ret = 0;

	size_t prefixSize = keyGetNameSize (parentKey) - 1;
	size_t arraySize = ksGetSize (ks);
	Key ** keyArray = calloc (ksGetSize (ks), sizeof (Key *));
	ret = elektraKsToMemArray (ks, keyArray);

	if (ret < 0) goto memoryerror;

	qsort (keyArray, arraySize, sizeof (Key *), keyCmpOrderWrapper);

	/* convert the Elektra KeySet to an Augeas tree */
	for (size_t i = 0; i < arraySize; i++)
	{
		Key * key = keyArray[i];
		char * nodeName;
		ret = asprintf (&nodeName, AUGEAS_TREE_ROOT "%s", (keyName (key) + prefixSize));

		if (ret < 0) goto memoryerror;

		aug_set (augeasHandle, nodeName, keyString (key));
		elektraFree (nodeName);
	}

	elektraFree (keyArray);

	/* remove keys not present in the KeySet */
	struct OrphanSearch * data = elektraMalloc (sizeof (struct OrphanSearch));

	if (!data) return -1;

	data->ks = ks;
	data->parentKey = parentKey;

	ret = foreachAugeasNode (augeasHandle, AUGEAS_TREE_ROOT, &removeOrphan, data);

	elektraFree (data);

	/* build the tree */
	ret = aug_text_retrieve (augeasHandle, lensPath, AUGEAS_CONTENT_ROOT, AUGEAS_TREE_ROOT, AUGEAS_OUTPUT_ROOT);

	if (ret < 0)
	{
		/* report the augeas specific error */
		ELEKTRA_SET_ERROR (85, parentKey, getAugeasError (augeasHandle));
	}

	return ret;

memoryerror:
	elektraFree (keyArray);
	ELEKTRA_SET_ERROR (87, parentKey, "Unable to allocate memory while saving the augeas tree");
	return -1;
}
示例#10
0
文件: set.c 项目: intfrr/libelektra
void print_warnings(Key * err)
{
	const Key *meta = 0; keyRewindMeta(err);
	while((meta = keyNextMeta(err)) != 0)
	{
		printf("%s:\t%s\n",
				keyName(meta), 
				keyString(meta)); 
	} 
}
示例#11
0
文件: pib-db.cpp 项目: CSUL/ndn-tools
void
PibDb::keyDeletedFun(sqlite3_context* context, int argc, sqlite3_value** argv)
{
  BOOST_ASSERT(argc == 1);

  PibDb* pibDb = reinterpret_cast<PibDb*>(sqlite3_user_data(context));
  Name keyName(Block(sqlite3_value_blob(argv[0]), sqlite3_value_bytes(argv[0])));

  pibDb->keyDeleted(keyName);
}
示例#12
0
buttons::ButtonType key(const char *name)
{
	int i;

	for (i=0; i < buttons::maxSpecials ; i++) {
		if (!strcmp(keyName(static_cast<buttons::ButtonType>(i)),name))
			return static_cast<buttons::ButtonType>(i);
	}
	throw exceptions::KeyException(name);
}
示例#13
0
/**
 * Check if the key check is below the key key or not.
 *
 * Example:
@verbatim
key user/sw/app
check user/sw/app/key
@endverbatim
 *
 * returns true because check is below key
 *
 * Example:
@verbatim
key user/sw/app
check user/sw/app/folder/key
@endverbatim
 *
 * returns also true because check is indirect below key
 *
 * @param key the key object to work with
 * @param check the key to find the relative position of
 * @return 1 if check is below key
 * @return 0 if it is not below or if it is the same key
 * @see keySetName(), keyGetName(), keyIsDirectBelow()
 * @ingroup keytest
 *
 */
int keyIsBelow(const Key *key, const Key *check)
{
	const char * keyname = 0;
	const char * checkname = 0;
	ssize_t keysize = 0;
	ssize_t checksize = 0;

	if (!key || !check) return -1;

	keyname = keyName(key);
	checkname = keyName(check);
	keysize = keyGetNameSize(key);
	checksize = keyGetNameSize(check);

	if (keysize > checksize + 1) return 0;
	if (strncmp (keyname, checkname, keysize - 1)) return 0;
	if (checkname[keysize - 1] != '/') return 0;
	return 1;
}
示例#14
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;
}
示例#15
0
static void
dump_noteval(note_p note, voice_p voice)
{
    /* Find out the pitch */
    int val = note->value + clef_current->offset;
    int octave;
    int key;
    int accidental;

    if (val < 0) {
        octave = - ((- val + OCTAVE_DIATON - 1) / OCTAVE_DIATON);
        val = (val - octave * OCTAVE_DIATON) % OCTAVE_DIATON;
    } else {
        octave = val / OCTAVE_DIATON;
        val = val % OCTAVE_DIATON;
    }

    accidental = measure_accidental[note->value];
    if (note->tie_end != NO_ID) {
        tie_p tie = &ties[note->tie_end];
        accidental = tie->notes[0]->accidental;
    }

    key = defaultKey(val, voice);
    VPRINTF(" dump note, keyed value = %d, accidental %d, measure accidental %d, key ofdset %d\n",
            val, note->accidental, measure_accidental[note->value],
            defaultKey(val, voice));
    fprintf(lily_out, " %s", keyName(val));
    if (note->accidental != 0) {
        dumpAccidental(note->accidental);
        measure_accidental[note->value] = note->accidental;
    } else if (accidental != 0) {
        /* Require the actual accidental for cross-bar ties */
        note->accidental = accidental;
        dumpAccidental(accidental);
    } else {
        switch (key) {
        case 0: break;
        case 1: fprintf(lily_out, "is"); break;
        case 2: fprintf(lily_out, "isis"); break;
        case -1: fprintf(lily_out, "es"); break;
        case -2: fprintf(lily_out, "eses"); break;
        }
    }

    while (octave > 0) {
        fprintf(lily_out, "'");
        octave--;
    }
    while (octave < 0) {
        fprintf(lily_out, ",");
        octave++;
    }
}
示例#16
0
static void test_arrayDec (void)
{
	printf ("Decrement array indizes\n");

	Key * k = keyNew ("user/array/#0", KEY_END);
	succeed_if (elektraArrayDecName (k) == -1, "Decrementing array index 0 did not fail");
	keyDel (k);

	k = keyNew ("user/array/#___1337", KEY_END);
	succeed_if (elektraArrayDecName (k) == 0, "Unable to decrement array index 1337");
	succeed_if_same_string (keyName (k), "user/array/#___1336");
	succeed_if (elektraArrayDecName (k) == 0, "Unable to decrement array index 1336");
	succeed_if_same_string (keyName (k), "user/array/#___1335");
	keyDel (k);

	k = keyNew ("user/array/#_________4000000000", KEY_END);
	succeed_if (elektraArrayDecName (k) == 0, "Unable to decrement array index 4000000000");
	succeed_if_same_string (keyName (k), "user/array/#_________3999999999");
	keyDel (k);
}
示例#17
0
文件: test.c 项目: jacereda/glcv
static int down(cvkey k) {
        int handled = 0;;
        cvReport("down %s", keyName(k));
        switch (k) {
        case CVK_MOUSELEFT:
                if (cvMouseY() < 10)
                        cvShowKeyboard();
        default:
                handled = 0;
        }
        return handled;
}
示例#18
0
文件: tests.c 项目: intfrr/libelektra
void output_meta(Key *k)
{
	const Key *meta;

	keyRewindMeta (k);
	while ((meta = keyNextMeta (k))!=0)
	{
		printf (", %s: %s", keyName(meta),
			(const char*)keyValue(meta));
	}
	printf ("\n");
}
示例#19
0
文件: ini.c 项目: tryge/libelektra
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;
	}
}
示例#20
0
// keyRel2 helper, turns key into a cascading key ( removes namespace)
Key * keyAsCascading (const Key * key)
{
	if (keyName (key)[0] == '/')
	{
		return keyDup (key);
	}
	else
	{
		elektraNamespace ns = keyGetNamespace (key);
		if (ns == KEY_NS_META || ns == KEY_NS_EMPTY || ns == KEY_NS_NONE)
		{
			// For metakeys or keys without namespace just prefix the keyname with a "/"
			Key * cKey = keyNew ("/", KEY_CASCADING_NAME, KEY_END);
			keyAddName (cKey, keyName (key));
			return cKey;
		}
		else
		{
			// Skip namespace
			const char * name = keyName (key);
			const char * ptr = strchr (name, '/');
			if (!ptr)
			{
				return keyNew ("/", KEY_CASCADING_NAME, KEY_END);
			}
			else
			{
				ssize_t length = keyGetNameSize (key);
				if ((ptr - name) == (length - 1))
				{
					return keyNew ("/", KEY_CASCADING_NAME, KEY_END);
				}
				else
				{
					return keyNew (ptr, KEY_CASCADING_NAME, KEY_END);
				}
			}
		}
	}
}
示例#21
0
static int handleConflictConflict (Key * parentKey, Key * key, Key * conflictMeta, OnConflict onConflict)
{
	ELEKTRA_LOG ("handling conflict %s:%s\n", keyName (key), keyName (conflictMeta));

	int ret = 0;
	const char * problemKeys = elektraMetaArrayToString (key, keyName (conflictMeta), ", ");
	switch (onConflict)
	{
	case ERROR:
		ELEKTRA_SET_ERRORF (142, parentKey, "%s has conflicting metakeys: %s\n", keyName (key), problemKeys);
		ret = -1;
		break;
	case WARNING:
		ELEKTRA_ADD_WARNINGF (143, parentKey, "%s has conflicting metakeys: %s\n", keyName (key), problemKeys);
		break;
	case INFO:
	{
		const char * infoString = "has conflicting metakeys:";
		const size_t len = elektraStrLen (infoString) + elektraStrLen (problemKeys) + elektraStrLen (keyName (key));
		char * buffer = elektraMalloc (len);
		snprintf (buffer, len, "%s %s %s", keyName (key), infoString, problemKeys);
		elektraMetaArrayAdd (key, "logs/spec/info", buffer);
		elektraFree (buffer);
	}
	break;
	case IGNORE:

		break;
	}
	if (problemKeys)
	{
		elektraFree ((void *) problemKeys);
	}
	return ret;
}
示例#22
0
static Key * prefToKey (Key * parentKey, PrefType type, const char * pref)
{
	Key * key = keyNew (keyName (parentKey), KEY_END);
	keyAddBaseName (key, prefix[type]);
	char * localString = elektraStrDup (pref);
	char * cPtr = strstr (localString, ",");
	*cPtr = '\0';
	char * sPtr = localString;
	++sPtr;
	*sPtr++ = '\0';
	char * ePtr = cPtr - 1;
	elektraRstrip (sPtr, &ePtr);
	size_t keyLen = ePtr - sPtr;
	char * prefKey = elektraMalloc (keyLen + 1);
	snprintf (prefKey, keyLen + 1, "%s", sPtr);
	char * tPtr = strtok (prefKey, ".");
	if (tPtr) keyAddBaseName (key, tPtr);
	while ((tPtr = strtok (NULL, ".")) != NULL)
	{
		keyAddBaseName (key, tPtr);
	}
	elektraFree (prefKey);
	sPtr = cPtr + 1;
	sPtr = elektraLskip (sPtr);
	ePtr = strrchr (sPtr, ')');
	*ePtr-- = '\0';
	elektraRstrip (sPtr, &ePtr);
	size_t argLen = ePtr - sPtr + 1;
	char * prefArg = elektraMalloc (argLen + 1);
	snprintf (prefArg, argLen + 1, "%s", sPtr);
	if (!strcmp (prefArg, "true") || !(strcmp (prefArg, "false")))
	{
		keySetMeta (key, "type", "boolean");
		keySetString (key, prefArg);
	}
	else if (prefArg[0] == '"' && prefArg[strlen (prefArg) - 1] == '"')
	{
		// TODO: else if list
		keySetMeta (key, "type", "string");
		*prefArg = '\0';
		*(prefArg + (strlen (prefArg + 1))) = '\0';
		keySetString (key, (prefArg + 1));
	}
	else
	{
		keySetMeta (key, "type", "integer");
		keySetString (key, prefArg);
	}
	elektraFree (prefArg);
	elektraFree (localString);
	return key;
}
void test_keyset()
{
	KeySet		*ks;
	Key     	*cur;
	int		counter;

	printf("Testing KeySet from xml\n");

	ks = ksNew(0, KS_END);
	exit_if_fail( ksFromXMLfile(ks, srcdir_file("xmltool/keyset.xml")) == 0, "ksFromXMLfile(key.xml) failed.");
	counter = 0;
	ksRewind(ks);
	while ( (cur = ksNext(ks)) ) {
		counter ++;

		/* Make tests ... */	
		// printf ("counter: %d - %s\n", counter, keyName(cur));
		switch (counter) {
			// <key type="43" basename="0-27042916" value="0 216905227"><comment>2551516588474823843</comment></key>
		case 1:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/0-27042916") == 0,"name of first key not correct");
			succeed_if (strcmp (keyValue(cur),"0 216905227") == 0,"value of first key not correct");
			succeed_if (strcmp (keyComment(cur),"2551516588474823843") == 0,"comment of first key not correct");
			break;
			// <key type="253" basename="1-2449524622" value="1 1679328197"><comment>3246436893195629244</comment></key>
		case 2:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/1-2449524622") == 0,"name of 2. key not correct");
			succeed_if (strcmp (keyValue(cur),"1 1679328197") == 0,"value of 2. key not correct");
			succeed_if (strcmp (keyComment(cur),"3246436893195629244") == 0,"comment of 2. key not correct");
			break;
			// <key type="string" basename="dir-1-0">
		case 3:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0") == 0,"name of 3. key not correct");
			break;
			// <key type="114" basename="0-294164813" value="0 216245011"><comment>18454108762891828026</comment></key>
		case 4:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0/0-294164813") == 0,"name of 4. key not correct");
			succeed_if (strcmp (keyValue(cur),"0 216245011") == 0,"value of 4. key not correct");
			succeed_if (strcmp (keyComment(cur),"18454108762891828026") == 0,"comment of 4. key not correct");
			break;
			// <key type="135" basename="1-1479930365" value="1 2732423037"><comment>24597295372375238</comment></key>
		case 5:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0/1-1479930365") == 0,"name of 4. key not correct");
			succeed_if (strcmp (keyValue(cur),"1 2732423037") == 0,"value of 4. key not correct");
			succeed_if (strcmp (keyComment(cur),"24597295372375238") == 0,"comment of 4. key not correct");
			break;
			// <key type="string" basename="dir-2-0">
		case 6:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0/dir-2-0") == 0,"name of 3. key not correct");
			break;
			// <key type="144" basename="0-215571059" value="0 264857705"><comment>2188631490667217086</comment></key>
		case 7:	succeed_if (strcmp (keyName(cur),"user/tests/filesys/dir-1-0/dir-2-0/0-215571059") == 0,"name of 4. key not correct");
			succeed_if (strcmp (keyValue(cur),"0 264857705") == 0,"value of 4. key not correct");
			succeed_if (strcmp (keyComment(cur),"2188631490667217086") == 0,"comment of 4. key not correct");
			break;
		}
	}
	
	ksDel(ks);
}
示例#24
0
void OutfitWindow::showCurrentOutfit()
{
    // TRANSLATORS: outfits window label
    mCurrentLabel->setCaption(strprintf(_("Outfit: %d"), mCurrentOutfit + 1));
    if (mCurrentOutfit < static_cast<int>(OUTFITS_COUNT))
        mUnequipCheck->setSelected(mItemsUnequip[mCurrentOutfit]);
    else
        mUnequipCheck->setSelected(false);
    // TRANSLATORS: outfits window label
    mKeyLabel->setCaption(strprintf(_("Key: %s"),
        keyName(mCurrentOutfit).c_str()));
    mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit);
}
示例#25
0
/**
 * @internal
 * Create a new key with a different root or common name.
 *
 * Does not modify `key`. The new key needs to be freed after usage.
 *
 * Preconditions: The key name starts with `source`.
 *
 * Example:
 * ```
 * Key * source = keyNew("user/plugins/foo/placements/get", KEY_END);
 * Key * dest = renameKey ("user/plugins/foo", "user/plugins/bar", source);
 * succeed_if_same_string (keyName(dest), "user/plugins/bar/placements/get");
 * ```
 *
 *
 * @param  source Part of the key name to replace
 * @param  dest   Replaces `source`
 * @param  key    key
 * @return        key with new name
 */
static Key * renameKey (const char * source, const char * dest, Key * key)
{
	const char * name = keyName (key);
	char * baseKeyNames = strndup (name + strlen (source), strlen (name));

	Key * moved = keyDup (key);
	keySetName (moved, dest);
	keyAddName (moved, baseKeyNames);

	elektraFree (baseKeyNames);

	return moved;
}
/**
 * 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;
}
示例#27
0
static void test_backref()
{
	printf ("Test back references\n");

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

	Backend *backend = elektraBackendOpen(set_backref(), modules, 0);
	succeed_if (backend != 0, "there should be a backend");
	succeed_if (backend->getplugins[0] == 0, "there should be no plugin");
	exit_if_fail (backend->getplugins[1] != 0, "there should be a plugin");
	succeed_if (backend->getplugins[2] == 0, "there should be no plugin");

	succeed_if (backend->setplugins[0] == 0, "there should be no plugin");
	exit_if_fail (backend->setplugins[1] != 0, "there should be a plugin");
	succeed_if (backend->setplugins[2] == 0, "there should be no plugin");

	Key *mp;
	succeed_if ((mp = backend->mountpoint) != 0, "no mountpoint found");
	succeed_if_same_string (keyName(mp), "user/tests/backend/backref");
	succeed_if_same_string (keyString(mp), "backref");

	Plugin *plugin1 = backend->getplugins[1];
	Plugin *plugin2 = backend->setplugins[1];
	Plugin *plugin3 = backend->errorplugins[1];

	succeed_if (plugin1 != 0, "there should be a plugin");
	succeed_if (plugin2 != 0, "there should be a plugin");
	succeed_if (plugin3 != 0, "there should be a plugin");

	succeed_if (plugin1 == plugin2, "it should be the same plugin");
	succeed_if (plugin2 == plugin3, "it should be the same plugin");
	succeed_if (plugin1 == plugin3, "it should be the same plugin");

	succeed_if (plugin1->refcounter == 3, "ref counter should be 3");

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

	succeed_if (plugin1->kdbGet != 0, "no get pointer");
	succeed_if (plugin1->kdbSet != 0, "no set pointer");
	succeed_if (plugin2->kdbGet != 0, "no get pointer");
	succeed_if (plugin2->kdbSet != 0, "no set pointer");

	elektraBackendClose (backend, 0);
	elektraModulesClose (modules, 0);
	ksDel (modules);
}
示例#28
0
static void validateArray (KeySet * ks, Key * arrayKey, Key * specKey)
{
	Key * tmpArrayParent = keyDup (arrayKey);
	keySetBaseName (tmpArrayParent, 0);
	Key * arrayParent = ksLookup (ks, tmpArrayParent, KDB_O_NONE);
	keyDel (tmpArrayParent);
	if (arrayParent == NULL) return;
	KeySet * ksCopy = ksDup (ks);
	KeySet * subKeys = ksCut (ksCopy, arrayParent);
	Key * cur;
	long validCount = 0;
	while ((cur = ksNext (subKeys)) != NULL)
	{
		if (!keyIsDirectBelow (arrayParent, cur)) continue;
		if (keyBaseName (cur)[0] == '#')
		{
			if (elektraArrayValidateName (cur) == 1)
			{
				++validCount;
				keySetMeta (cur, "spec/internal/valid", "");
			}
			else
			{
				KeySet * invalidCutKS = ksCut (subKeys, cur);
				Key * toMark;
				while ((toMark = ksNext (invalidCutKS)) != NULL)
				{
					if (strcmp (keyName (cur), keyName (toMark))) keySetMeta (toMark, "conflict/invalid", "");
					elektraMetaArrayAdd (arrayParent, "conflict/invalid/hasmember", keyName (toMark));
				}
				ksDel (invalidCutKS);
			}
		}
	}
	ksDel (subKeys);
	ksDel (ksCopy);
	validateArrayRange (arrayParent, validCount, specKey);
}
示例#29
0
/**
 * Check if the key check is direct below the key key or not.
 *
@verbatim
Example:
key user/sw/app
check user/sw/app/key

returns true because check is below key

Example:
key user/sw/app
check user/sw/app/folder/key

does not return true, because there is only a indirect relation
@endverbatim
 *
 * @param key the key object to work with
 * @param check the key to find the relative position of
 * @return 1 if check is below key
 * @return 0 if it is not below or if it is the same key
 * @return -1 on null pointer
 * @see keyIsBelow(), keySetName(), keyGetName()
 * @ingroup keytest
 *
 */
int keyIsDirectBelow(const Key *key, const Key *check)
{
	const char * checkname = 0;
	ssize_t keysize = 0;

	if (!key || !check) return -1;

	checkname = keyName(check);
	keysize = keyGetNameSize(key);

	if (!keyIsBelow(key, check)) return 0;
	if (strchr(checkname + keysize, '/')) return 0;
	return 1;
}
示例#30
0
文件: kdb.c 项目: KurtMi/libelektra
/**
 * @internal
 * @brief Does the rollback
 *
 * @param split all information for iteration
 * @param parentKey to add warnings (also passed to plugins for the same reason)
 */
static void elektraSetRollback (Split * split, Key * parentKey)
{
	for (size_t p = 0; p < NR_OF_PLUGINS; ++p)
	{
		for (size_t i = 0; i < split->size; i++)
		{
			int ret = 0;
			Backend * backend = split->handles[i];

			ksRewind (split->keysets[i]);
			if (backend->errorplugins[p])
			{
				keySetName (parentKey, keyName (split->parents[i]));
				ret = backend->errorplugins[p]->kdbError (backend->errorplugins[p], split->keysets[i], parentKey);
			}

			if (ret == -1)
			{
				ELEKTRA_ADD_WARNING (81, parentKey, keyName (backend->mountpoint));
			}
		}
	}
}