src/libs/elektra/keyset.c
/**
 * @internal
 * @brief Helper for elektraLookupBySpec
 *
 * Lookup using namespaces
 *
 * @param ks the keyset to search in
 * @param specKey contains metadata as specified in buffer+#<number>
 * @param buffer the buffer used for incrementing numbers
 */
@internal
@brief Helper for elektraLookupBySpec

Lookup using namespaces

@param ks the keyset to search in
@param specKey contains metadata as specified in buffer+#
@param buffer the buffer used for incrementing numbers
@internal @brief Helper for elektraLookupBySpec Lookup using namespaces @param ks the keyset to search in @param specKey contains metadata as specified in buffer + # @param buffer the buffer used for incrementing numbers
static Key * elektraLookupBySpecNamespaces (KeySet * ks, Key * specKey, char * buffer)
{
	Key * ret = 0;
	const int prefixSize = ELEKTRA_MAX_PREFIX_SIZE - 1;
	kdb_long_long_t i = 0;
	const Key * m = 0;
	m = keyGetMeta (specKey, buffer);
	if (!m) return elektraLookupByCascading (ks, specKey, KDB_O_NOSPEC | KDB_O_NODEFAULT);
	char * name = specKey->key;
	size_t size = specKey->keySize;
	size_t usize = specKey->keyUSize;
	size_t nameLength = strlen (name);
	size_t maxSize = nameLength + ELEKTRA_MAX_NAMESPACE_SIZE;
	char newname[maxSize * 2]; 
	do
	{
		size_t namespaceSize = keyGetValueSize (m);
		char * startOfName = newname + ELEKTRA_MAX_NAMESPACE_SIZE - namespaceSize;
		strncpy (startOfName, keyString (m), namespaceSize);
		strcpy (newname + ELEKTRA_MAX_NAMESPACE_SIZE - 1, name); 
		specKey->key = startOfName;
		specKey->keySize = nameLength + namespaceSize;
		elektraFinalizeName (specKey);
		ret = ksLookup (ks, specKey, 0);
		if (ret) break;
		++i; 
		elektraWriteArrayNumber (&buffer[prefixSize], i);
		m = keyGetMeta (specKey, buffer);
	} while (m);
	specKey->key = name;
	specKey->keySize = size;
	specKey->keyUSize = usize;
	return ret;
}
static Key * elektraLookupBySpecNamespaces ( KeySet * ks , Key * specKey , char * buffer ) { Key * ret = 0 ; const int prefixSize = ELEKTRA_MAX_PREFIX_SIZE - 1 ; kdb_long_long_t i = 0 ; const Key * m = 0 ; m = keyGetMeta ( specKey , buffer ) ; if ( ! m ) return elektraLookupByCascading ( ks , specKey , KDB_O_NOSPEC | KDB_O_NODEFAULT ) ; char * name = specKey -> key ; size_t size = specKey -> keySize ; size_t usize = specKey -> keyUSize ; size_t nameLength = strlen ( name ) ; size_t maxSize = nameLength + ELEKTRA_MAX_NAMESPACE_SIZE ; char newname [ maxSize * 2 ] ; do { size_t namespaceSize = keyGetValueSize ( m ) ; char * startOfName = newname + ELEKTRA_MAX_NAMESPACE_SIZE - namespaceSize ; strncpy ( startOfName , keyString ( m ) , namespaceSize ) ; strcpy ( newname + ELEKTRA_MAX_NAMESPACE_SIZE - 1 , name ) ; specKey -> key = startOfName ; specKey -> keySize = nameLength + namespaceSize ; elektraFinalizeName ( specKey ) ; ret = ksLookup ( ks , specKey , 0 ) ; if ( ret ) break ; ++ i ; elektraWriteArrayNumber ( & buffer [ prefixSize ] , i ) ; m = keyGetMeta ( specKey , buffer ) ; } while ( m ) ; specKey -> key = name ; specKey -> keySize = size ; specKey -> keyUSize = usize ; return ret ; }
@internal
 @brief Helper for elektraLookupBySpec
@internal @brief Helper for elektraLookupBySpec
// no namespaces specified, so do a default cascading lookup // (obviously w/o spec) // store old name of specKey // buffer for all new names (namespace + cascading key name) // lookup with given namespace // name starts with / // start with 1 (#0 was already in buffer) // restore old cascading name