Skip to content

Commit

Permalink
remove various deprecated things
Browse files Browse the repository at this point in the history
  • Loading branch information
kodebach committed Oct 2, 2020
1 parent 3a63e42 commit f42102b
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 163 deletions.
3 changes: 0 additions & 3 deletions examples/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ case KEY_NS_USER:
case KEY_NS_SYSTEM:
printf ("system namespace\n");
break;
case KEY_NS_EMPTY:
printf ("empty name\n");
break;
case KEY_NS_NONE:
printf ("no key\n");
break;
Expand Down
6 changes: 3 additions & 3 deletions src/include/kdb.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ typedef int elektraLookupFlags;
enum {
KEY_NS_NONE=0,
KEY_NS_CASCADING=1,
KEY_NS_FIRST=2, // TODO (kodebach): remove from enum
KEY_NS_META=2,
KEY_NS_SPEC=3,
KEY_NS_PROC=4,
KEY_NS_DIR=5,
KEY_NS_USER=6,
KEY_NS_SYSTEM=7,
KEY_NS_DEFAULT=8,
KEY_NS_LAST=8, // TODO (kodebach): remove from enum
KEY_NS_EMPTY=100 // TODO (kodebach): remove
};
typedef int elektraNamespace;

static const elektraNamespace KEY_NS_FIRST = KEY_NS_META;
static const elektraNamespace KEY_NS_LAST = KEY_NS_DEFAULT;

typedef ssize_t elektraCursor;


Expand Down
3 changes: 0 additions & 3 deletions src/include/kdbproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace ckdb
extern "C" {
#endif

// this might become the new keySetName
ssize_t elektraKeySetName (Key * key, const char * newName, elektraKeyFlags options);

KeySet * elektraKeyGetMetaKeySet (const Key * key);

Key * ksPopAtCursor (KeySet * ks, elektraCursor c);
Expand Down
3 changes: 1 addition & 2 deletions src/libs/elektra/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Backend * backendOpenModules (KeySet * modules, KeySet * global, Key * errorKey)
ksNew (5, keyNew ("system:/module", KEY_VALUE, "1", KEY_END), keyNew ("user:/module", KEY_VALUE, "1", KEY_END), KS_END);
Key * cur = ksCurrent (modules);

elektraKeySetName (errorKey, keyName (cur), KEY_CASCADING_NAME | KEY_EMPTY_NAME);
keySetName (errorKey, keyName (cur));

Plugin * plugin = elektraPluginOpen (keyBaseName (cur), modules, defaultConfig, errorKey);
if (!plugin)
Expand Down Expand Up @@ -436,7 +436,6 @@ int backendUpdateSize (Backend * backend, Key * parent, int size)
backend->systemsize = size;
break;
case KEY_NS_PROC:
case KEY_NS_EMPTY:
case KEY_NS_META:
case KEY_NS_CASCADING:
case KEY_NS_NONE:
Expand Down
11 changes: 0 additions & 11 deletions src/libs/elektra/kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,6 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
return -1;
}

if (ns == KEY_NS_EMPTY)
{
ELEKTRA_ADD_INTERFACE_WARNING (parentKey, "Empty namespace passed to kdbGet. Please use the cascading key / instead");
}

int errnosave = errno;
Key * initialParent = keyDup (parentKey);

Expand Down Expand Up @@ -1552,12 +1547,6 @@ int kdbSet (KDB * handle, KeySet * ks, Key * parentKey)
return -1;
}

if (ns == KEY_NS_EMPTY)
{
ELEKTRA_ADD_INTERFACE_WARNING (parentKey, "Invalid key name passed to kdbSet");
ELEKTRA_LOG ("ns == KEY_NS_EMPTY");
}

if (!handle || !ks)
{
clearError (parentKey); // clear previous error to set new one
Expand Down
16 changes: 7 additions & 9 deletions src/libs/elektra/kdbenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,14 @@ enum elektraLockFlags
enum elektraNamespace
{
KEY_NS_NONE=0, ///< no key given as parameter to keyGetNamespace()
KEY_NS_EMPTY=1, ///< key name was empty, e.g. invalid key name
KEY_NS_CASCADING=1, ///< cascading key, starts with /, abstract name for any of the namespaces below
KEY_NS_META=2, ///< metakey, i.e. any key name not under other categories
KEY_NS_CASCADING=3, ///< cascading key, starts with /, abstract name for any of the namespaces below
KEY_NS_FIRST=4, ///< For iteration over namespaces (first element, inclusive)
KEY_NS_SPEC=4, ///< spec contains the specification of the other namespaces
KEY_NS_PROC=5, ///< proc contains process-specific configuration
KEY_NS_DIR=6, ///< dir contains configuration from a specific directory
KEY_NS_USER=7, ///< user key in the home directory of the current user
KEY_NS_SYSTEM=8, ///< system key is shared for a computer system
KEY_NS_LAST=8 ///< For iteration over namespaces (last element, inclusive)
KEY_NS_SPEC=3, ///< spec contains the specification of the other namespaces
KEY_NS_PROC=4, ///< proc contains process-specific configuration
KEY_NS_DIR=5, ///< dir contains configuration from a specific directory
KEY_NS_USER=6, ///< user key in the home directory of the current user
KEY_NS_SYSTEM=7, ///< system key is shared for a computer system
KEY_NS_DEFAULT=8, ///< default key used as a fallback if no other key is found
};

/**
Expand Down
121 changes: 57 additions & 64 deletions src/libs/elektra/keyname.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,62 @@ size_t keyGetUnescapedName (const Key * key, char * returnedName, size_t maxSize
ssize_t keySetName (Key * key, const char * newName)
{
// TODO (kodebach): change to return size_t
return elektraKeySetName (key, newName, 0);
if (!key) return -1;
if (test_bit (key->flags, KEY_FLAG_RO_NAME)) return -1;
if (newName == NULL || strlen (newName) == 0) return -1;

size_t oldKeySize = key->keySize;
size_t oldKeyUSize = key->keyUSize;

if (!elektraKeyNameValidate (newName, NULL, &key->keySize, &key->keyUSize))
{
// error invalid name
return -1;
}

// from now on this function CANNOT fail -> we may modify the key

clear_bit (key->flags, (keyflag_t) KEY_FLAG_MMAP_KEY);

if (test_bit (key->flags, KEY_FLAG_MMAP_KEY))
{
// key was in mmap region, clear flag and set NULL to allow realloc
key->key = NULL;
key->ukey = NULL;
clear_bit (key->flags, (keyflag_t) KEY_FLAG_MMAP_KEY);
}

if (key->keySize > oldKeySize)
{
// buffer growing -> realloc first
elektraRealloc ((void **) &key->key, key->keySize);
}

if (key->keyUSize > oldKeyUSize)
{
// buffer growing -> realloc first
elektraRealloc ((void **) &key->ukey, key->keyUSize);
}

elektraKeyNameCanonicalize (newName, &key->key, key->keySize, 0);
elektraKeyNameUnescape (key->key, &key->ukey);

if (key->keySize < oldKeySize)
{
// buffer shrinking -> realloc after
elektraRealloc ((void **) &key->key, key->keySize);
}

if (key->keyUSize < oldKeyUSize)
{
// buffer shrinking -> realloc after
elektraRealloc ((void **) &key->ukey, key->keyUSize);
}

set_bit (key->flags, KEY_FLAG_SYNC);

if (keyGetNamespace (key) != KEY_NS_META) keySetOwner (key, NULL);
return key->keySize;
}

int elektraKeyNameValidate (const char * name, const char * prefix, size_t * sizePtr, size_t * usizePtr)
Expand Down Expand Up @@ -1057,68 +1112,6 @@ void elektraKeyNameUnescape (const char * canonicalName, char ** unescapedName)
*outPtr = '\0';
}

// TODO (kodebach): remove options
ssize_t elektraKeySetName (Key * key, const char * newName, elektraKeyFlags options)
{
// TODO (kodebach): change to return size_t
if (!key) return -1;
if (test_bit (key->flags, KEY_FLAG_RO_NAME)) return -1;
if (newName == NULL || strlen (newName) == 0) return -1;

size_t oldKeySize = key->keySize;
size_t oldKeyUSize = key->keyUSize;

if (!elektraKeyNameValidate (newName, NULL, &key->keySize, &key->keyUSize))
{
// error invalid name
return -1;
}

// from now on this function CANNOT fail -> we may modify the key

clear_bit (key->flags, (keyflag_t) KEY_FLAG_MMAP_KEY);

if (test_bit (key->flags, KEY_FLAG_MMAP_KEY))
{
// key was in mmap region, clear flag and set NULL to allow realloc
key->key = NULL;
key->ukey = NULL;
clear_bit (key->flags, (keyflag_t) KEY_FLAG_MMAP_KEY);
}

if (key->keySize > oldKeySize)
{
// buffer growing -> realloc first
elektraRealloc ((void **) &key->key, key->keySize);
}

if (key->keyUSize > oldKeyUSize)
{
// buffer growing -> realloc first
elektraRealloc ((void **) &key->ukey, key->keyUSize);
}

elektraKeyNameCanonicalize (newName, &key->key, key->keySize, 0);
elektraKeyNameUnescape (key->key, &key->ukey);

if (key->keySize < oldKeySize)
{
// buffer shrinking -> realloc after
elektraRealloc ((void **) &key->key, key->keySize);
}

if (key->keyUSize < oldKeyUSize)
{
// buffer shrinking -> realloc after
elektraRealloc ((void **) &key->ukey, key->keyUSize);
}

set_bit (key->flags, KEY_FLAG_SYNC);

if (!(options & KEY_META_NAME) && keyGetNamespace (key) != KEY_NS_META) keySetOwner (key, NULL);
return key->keySize;
}

/**
* @brief Returns a pointer to the internal unescaped key name where the @p basename starts.
*
Expand Down Expand Up @@ -1747,7 +1740,7 @@ ssize_t keySetNamespace (Key * key, elektraNamespace ns)
{
// TODO (kodebach): document
if (!key) return -1;
if (ns == KEY_NS_NONE || ns == KEY_NS_EMPTY) return -1;
if (ns == KEY_NS_NONE) return -1;

if (ns == key->ukey[0]) return key->keySize;

Expand Down
5 changes: 2 additions & 3 deletions src/libs/elektra/keyset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,6 @@ KeySet * ksCut (KeySet * ks, const Key * cutpoint)
case KEY_NS_META:
((Key *) cutpoint)->ukey[0] = ns;
break;
case KEY_NS_EMPTY:
case KEY_NS_NONE:
case KEY_NS_CASCADING:
case KEY_NS_DEFAULT:
Expand Down Expand Up @@ -1648,7 +1647,7 @@ static Key * elektraLookupBySpecLinks (KeySet * ks, Key * specKey, char * buffer
elektraCopyCallbackMeta (k, specKey);
}
else
elektraKeySetName (k, keyString (m), KEY_CASCADING_NAME);
keySetName (k, keyString (m));
ret = ksLookup (ks, k, KDB_O_NODEFAULT);
if (ret) break;
++i;
Expand Down Expand Up @@ -2300,7 +2299,7 @@ Key * ksLookupByName (KeySet * ks, const char * name, elektraLookupFlags options
struct _Key key;
key.meta = NULL;
keyInit (&key);
elektraKeySetName (&key, name, KEY_META_NAME | KEY_CASCADING_NAME);
keySetName (&key, name);

found = ksLookup (ks, &key, options);
elektraFree (key.key);
Expand Down
3 changes: 0 additions & 3 deletions src/libs/elektra/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ int mountDefault (KDB * kdb, KeySet * modules, int inFallback, Key * errorKey)
splitAppend (kdb->split, backend, keyNew ("user:/", KEY_VALUE, "default", KEY_END), 2);
}
break;
case KEY_NS_EMPTY:
case KEY_NS_PROC:
case KEY_NS_NONE:
case KEY_NS_META:
Expand Down Expand Up @@ -593,7 +592,6 @@ int mountBackend (KDB * kdb, Backend * backend, Key * errorKey ELEKTRA_UNUSED)
++backend->refcounter;
break;
case KEY_NS_PROC:
case KEY_NS_EMPTY:
case KEY_NS_NONE:
case KEY_NS_META:
case KEY_NS_CASCADING:
Expand Down Expand Up @@ -634,7 +632,6 @@ int mountBackend (KDB * kdb, Backend * backend, Key * errorKey ELEKTRA_UNUSED)
case KEY_NS_SPEC:
// excluded on purpose because mounting spec is a separate step
// (see specmount)
case KEY_NS_EMPTY:
case KEY_NS_PROC:
case KEY_NS_NONE:
case KEY_NS_META:
Expand Down
8 changes: 0 additions & 8 deletions src/libs/elektra/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ static ssize_t splitSearchBackend (Split * split, Backend * backend, Key * paren
break;
case KEY_NS_PROC:
return -1;
case KEY_NS_EMPTY:
return -1;
case KEY_NS_NONE:
return -1;
case KEY_NS_META:
Expand Down Expand Up @@ -256,7 +254,6 @@ static int elektraKeySetNameByNamespace (Key * parentKey, elektraNamespace ns)
case KEY_NS_SYSTEM:
keySetName (parentKey, "system:/");
break;
case KEY_NS_EMPTY:
case KEY_NS_NONE:
case KEY_NS_META:
case KEY_NS_CASCADING:
Expand Down Expand Up @@ -549,9 +546,6 @@ static int elektraSplitPostprocess (Split * split, int i, Key * warningKey, KDB
case KEY_NS_PROC:
elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, 0, "it has a proc key name");
break;
case KEY_NS_EMPTY:
elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, 0, "it has an empty name");
break;
case KEY_NS_META:
elektraDropCurrentKey (split->keysets[i], warningKey, curHandle, 0, "it has a metaname");
break;
Expand Down Expand Up @@ -646,7 +640,6 @@ int splitUpdateSize (Split * split)
split->handles[i]->systemsize = ksGetSize (split->keysets[i]);
break;
case KEY_NS_PROC:
case KEY_NS_EMPTY:
case KEY_NS_NONE:
case KEY_NS_META:
case KEY_NS_CASCADING:
Expand Down Expand Up @@ -782,7 +775,6 @@ int splitSync (Split * split)
}
break;
case KEY_NS_PROC:
case KEY_NS_EMPTY:
case KEY_NS_META:
case KEY_NS_CASCADING:
case KEY_NS_NONE:
Expand Down
3 changes: 0 additions & 3 deletions src/libs/elektra/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ libelektra_0.8 {
ksSetCursor;
ksTail;
ksVNew;

# kdbproposal.h
elektraKeySetName;
};

libelektra_1.0 {
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/resolver/filename.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,6 @@ ElektraResolved * ELEKTRA_PLUGIN_FUNCTION (filename) (elektraNamespace namespace
ELEKTRA_ADD_INTERFACE_WARNING (warningsKey, "Resolver was not able to resolve a filename. Tried to resolve proc");
rc = -1;
break;
case KEY_NS_EMPTY:
ELEKTRA_ADD_INTERFACE_WARNING (warningsKey, "Resolver was not able to resolve a filename. Tried to resolve empty");
rc = -1;
break;
case KEY_NS_NONE:
ELEKTRA_ADD_INTERFACE_WARNING (warningsKey, "Resolver was not able to resolve a filename. Tried to resolve none");
rc = -1;
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/resolver/resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ static resolverHandle * elektraGetResolverHandle (Plugin * handle, Key * parentK
case KEY_NS_SYSTEM:
return &pks->system;
case KEY_NS_PROC:
case KEY_NS_EMPTY:
case KEY_NS_NONE:
case KEY_NS_META:
case KEY_NS_CASCADING:
Expand Down Expand Up @@ -299,7 +298,6 @@ static int needsMapping (Key * testKey, Key * errorKey)
elektraNamespace ns = keyGetNamespace (errorKey);

if (ns == KEY_NS_NONE) return 1; // for unit tests
if (ns == KEY_NS_EMPTY) return 1; // for default backend
if (ns == KEY_NS_CASCADING) return 1; // init all namespaces for cascading

return ns == keyGetNamespace (testKey); // otherwise only init if same ns
Expand Down Expand Up @@ -402,7 +400,6 @@ static int mapFilesForNamespaces (resolverHandles * p, Key * errorKey)
}
// FALLTHROUGH
case KEY_NS_PROC:
case KEY_NS_EMPTY:
case KEY_NS_NONE:
case KEY_NS_META:
case KEY_NS_CASCADING:
Expand Down

0 comments on commit f42102b

Please sign in to comment.