static void test_cascadingLookup (void) { printf ("test cascading lookup\n"); Key * k0; Key * k1; Key * k2; Key * k3; KeySet * ks = ksNew (10, k0 = keyNew ("system/benchmark/override/#0", 0), k1 = keyNew ("system/benchmark/override/#1", 0), k2 = keyNew ("user/benchmark/override/#2", 0), k3 = keyNew ("user/benchmark/override/#3", 0), KS_END); Key * search = keyNew ("/benchmark/override/#0", KEY_CASCADING_NAME, KEY_END); Key * found = ksLookup (ks, search, 0); succeed_if (found == k0, "found wrong key"); elektraKeySetName (search, "/benchmark/override/#1", KEY_CASCADING_NAME); found = ksLookup (ks, search, 0); succeed_if (found == k1, "found wrong key"); keyDel (search); search = keyNew ("/benchmark/override/#2", KEY_CASCADING_NAME, KEY_END); found = ksLookup (ks, search, 0); succeed_if (found == k2, "found wrong key"); elektraKeySetName (search, "/benchmark/override/#3", KEY_CASCADING_NAME); found = ksLookup (ks, search, 0); succeed_if (found == k3, "found wrong key"); keyDel (search); ksDel (ks); }
static void test_lookupNoOverride () { printf ("Test lookup with override not found\n"); // clang-format off Key *specKey = keyNew("/test/lift/limit", KEY_CASCADING_NAME, KEY_META, "default", "1", KEY_META, "override/#0", "/test/person_lift/limit", KEY_META, "override/#1", "/test/material_lift/limit", KEY_META, "override/#2", "/test/heavy_material_lift/limit", KEY_END); // clang-format on Key * dup = keyDup (specKey); Key * k1 = 0; Key * k2 = 0; KeySet * ks = ksNew (20, k1 = keyNew ("user/test/lift/limit", KEY_VALUE, "22", KEY_END), k2 = keyNew ("/test/person_lift/limit", KEY_CASCADING_NAME, KEY_VALUE, "10", KEY_END), KS_END); succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == k1, "found wrong key"); succeed_if (ksLookup (ks, dup, KDB_O_SPEC) == k1, "found wrong key"); elektraKeySetName (dup, "/test/lift/limit", KEY_CASCADING_NAME); succeed_if (ksLookup (ks, dup, KDB_O_SPEC) == k1, "found wrong key"); succeed_if (ksLookup (ks, dup, KDB_O_SPEC | KDB_O_CREATE) == k1, "found wrong key"); keyDel (specKey); ksDel (ks); keyDel (dup); }
/** * @brief sets mountpoint * * @param backend where the mountpoint should be set * @param elektraConfig the config where the mountpoint can be found * @param [out] errorKey the name also has the mountpoint set * * @pre ksCurrent() is root key * @post ksCurrent() is root key * * @retval -1 if no mountpoint is found or memory allocation problem * @retval 0 on success */ int elektraBackendSetMountpoint(Backend *backend, KeySet *elektraConfig, Key *errorKey) { Key * root = ksCurrent(elektraConfig); Key * searchMountpoint = keyDup(root); keyAddBaseName(searchMountpoint, "mountpoint"); Key * foundMountpoint = ksLookup(elektraConfig, searchMountpoint, 0); keyDel (searchMountpoint); ksLookup(elektraConfig, root, 0); // reset ksCurrent() if (!foundMountpoint) { ELEKTRA_ADD_WARNINGF(14, errorKey, "Could not find mountpoint within root %s", keyName(root)); return -1; } backend->mountpoint = keyNew("", KEY_VALUE, keyBaseName(root), KEY_END); elektraKeySetName(backend->mountpoint, keyString(foundMountpoint), KEY_CASCADING_NAME | KEY_EMPTY_NAME); keySetName(errorKey, keyName(backend->mountpoint)); if (!backend->mountpoint) { ELEKTRA_ADD_WARNINGF(14, errorKey, "Could not create mountpoint with name %s and value %s", keyString(foundMountpoint), keyBaseName(root)); return -1; } keyIncRef(backend->mountpoint); return 0; }
/**@return a backend which gives plugin configuration of the module * which is currently point to. * * @param modules the modules to work with * @param errorKey the key to issue warnings and errors to */ Backend* elektraBackendOpenModules(KeySet *modules, Key *errorKey) { Backend *backend = elektraBackendAllocate(); cursor_t save = ksGetCursor (modules); KeySet *defaultConfig = 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); Plugin *plugin = elektraPluginOpen(keyBaseName(cur), modules, defaultConfig, errorKey); if (!plugin) { /* Error already set in plugin */ elektraFree(backend); return 0; } Key *mp = keyNew ("system/elektra/modules", KEY_VALUE, "modules", KEY_END); keyAddBaseName (mp, keyBaseName(cur)); backend->getplugins[0] = plugin; plugin->refcounter = 1; backend->mountpoint = mp; keyIncRef(backend->mountpoint); ksSetCursor (modules, save); return backend; }
static void test_elektraEmptyKeys() { printf ("test empty keys\n"); Key *key = keyNew("", KEY_END); KeySet *ks = ksNew(0, KS_END); elektraKeySetName(key, "", KEY_META_NAME | KEY_CASCADING_NAME); succeed_if_same_string(keyName(key), ""); succeed_if(key->key != 0, "null pointer?"); ksAppendKey(ks, key); succeed_if(ksLookup(ks, key, 0) == key, "could not find empty key"); ksDel(ks); }
/** Returns the value of a meta-information given by name. * * You are not allowed to modify the resulting key. * * @code int f(Key *k) { if (!strcmp(keyValue(keyGetMeta(k, "type")), "boolean")) { // the type of the key is boolean } } * @endcode * * @note You must not delete or change the returned key, * use keySetMeta() if you want to delete or change it. * * @param key the key object to work with * @param metaName the name of the meta information you want the value from * @retval 0 if the key or metaName is 0 * @retval 0 if no such metaName is found * @return value of meta-information if meta-information is found * @see keySetMeta() * @ingroup keymeta **/ const Key * keyGetMeta (const Key * key, const char * metaName) { Key * ret; Key * search; if (!key) return 0; if (!metaName) return 0; if (!key->meta) return 0; search = keyNew (0); elektraKeySetName (search, metaName, KEY_META_NAME | KEY_EMPTY_NAME); ret = ksLookup (key->meta, search, 0); keyDel (search); return ret; }
static void test_lookupCascading () { printf ("Test lookup cascading\n"); Key * specKey = keyNew ("/abc", KEY_CASCADING_NAME, KEY_META, "override/#0", "/something", KEY_END); Key * k = 0; KeySet * ks = ksNew (20, k = keyNew ("user/else", KEY_END), KS_END); succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == 0, "found wrong key"); keySetMeta (specKey, "fallback/#0", "/else"); succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == k, "did not find fallback key"); keySetMeta (specKey, "fallback/#0", ""); succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == 0, "found wrong key"); keySetMeta (specKey, "override/#0", "/else"); succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == k, "did not find override key"); keySetMeta (specKey, "override/#0", ""); succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == 0, "found wrong key"); elektraKeySetName (specKey, "/else", KEY_CASCADING_NAME); succeed_if (ksLookup (ks, specKey, KDB_O_SPEC) == k, "did not find key itself"); keyDel (specKey); ksDel (ks); }
/**Builds a backend out of the configuration supplied * from: * @verbatim system/elektra/mountpoints/<name> @endverbatim * * The root key must be like the above example. You do * not need to rewind the keyset. But every key must be * below the root key. * * The internal consistency will be checked in this * function. If necessary parts are missing, like * no plugins, they cant be loaded or similar 0 * will be returned. * * ksCut() is perfectly suitable for cutting out the * configuration like needed. * * @note The given KeySet will be deleted within the function, * don't use it afterwards. * * @param elektraConfig the configuration to work with. * It is used to build up this backend. * @param modules used to load new modules or get references * to existing one * @return a pointer to a freshly allocated backend * this could be the requested backend or a so called * "missing backend". * @retval 0 if out of memory * @ingroup backend */ Backend* elektraBackendOpen(KeySet *elektraConfig, KeySet *modules, Key *errorKey) { Key * cur; Key * root; KeySet *referencePlugins = 0; KeySet *systemConfig = 0; int failure = 0; referencePlugins = ksNew(0, KS_END); ksRewind(elektraConfig); root = ksNext (elektraConfig); Backend *backend = elektraBackendAllocate(); while ((cur = ksNext(elektraConfig)) != 0) { if (keyRel (root, cur) == 1) { // direct below root key KeySet *cut = ksCut (elektraConfig, cur); if (!strcmp(keyBaseName(cur), "config")) { systemConfig = elektraRenameKeys(cut, "system"); ksDel (cut); } else if (!strcmp(keyBaseName(cur), "getplugins")) { if (elektraProcessPlugins(backend->getplugins, modules, referencePlugins, cut, systemConfig, errorKey) == -1) { if (!failure) ELEKTRA_ADD_WARNING(13, errorKey, "elektraProcessPlugins for get failed"); failure = 1; } } else if (!strcmp(keyBaseName(cur), "mountpoint")) { backend->mountpoint = keyNew("", KEY_VALUE, keyBaseName(root), KEY_END); elektraKeySetName(backend->mountpoint, keyString(cur), KEY_CASCADING_NAME | KEY_EMPTY_NAME); if (!backend->mountpoint) { if (!failure) ELEKTRA_ADD_WARNINGF(14, errorKey, "Could not create mountpoint with name %s and value %s", keyString(cur), keyBaseName(root)); failure = 1; } keyIncRef(backend->mountpoint); ksDel (cut); } else if (!strcmp(keyBaseName(cur), "setplugins")) { if (elektraProcessPlugins(backend->setplugins, modules, referencePlugins, cut, systemConfig, errorKey) == -1) { if (!failure) ELEKTRA_ADD_WARNING(15, errorKey, "elektraProcessPlugins for set failed"); failure = 1; } } else if (!strcmp(keyBaseName(cur), "errorplugins")) { if (elektraProcessPlugins(backend->errorplugins, modules, referencePlugins, cut, systemConfig, errorKey) == -1) { if (!failure) ELEKTRA_ADD_WARNING(15, errorKey, "elektraProcessPlugins for error failed"); failure = 1; } } else { // no one cares about that config if (!failure) ELEKTRA_ADD_WARNING(16, errorKey, keyBaseName(cur)); ksDel (cut); } } } if (failure) { Backend *tmpBackend = elektraBackendOpenMissing(backend->mountpoint); elektraBackendClose(backend, errorKey); backend = tmpBackend; } ksDel (systemConfig); ksDel (elektraConfig); ksDel (referencePlugins); return backend; }
static void test_modules() { printf ("Test mounting with modules\n"); KDB *kdb = kdb_new(); Key *errorKey = keyNew(0); KeySet *modules = modules_config(); succeed_if (elektraMountOpen(kdb, root_config(), modules, errorKey) == 0, "could not buildup mount"); succeed_if (elektraMountDefault(kdb, modules, errorKey) == 0, "could not mount default backend"); succeed_if (elektraMountModules(kdb, modules, errorKey) == 0, "could not mount modules"); succeed_if(output_warnings (errorKey), "warnings found"); succeed_if(output_error (errorKey), "error found"); succeed_if (kdb->split->size == 8, "size of split not correct"); Key *mp = keyNew("spec", KEY_VALUE, "root", KEY_END); compare_key(mp, kdb->split->parents[0]); keySetName(mp, "dir"); keySetString (mp, "root"); compare_key(mp, kdb->split->parents[1]); keySetName(mp, "user"); keySetString (mp, "root"); compare_key(mp, kdb->split->parents[2]); keySetName(mp, "system"); keySetString (mp, "root"); compare_key(mp, kdb->split->parents[3]); /* we cannot exactly know where resolver+dump is located *(depending on alphabet) keySetName(mp, "system/elektra/modules/"KDB_DEFAULT_RESOLVER); keySetString (mp, "modules"); compare_key(mp, kdb->split->parents[4]); */ keySetName(mp, "system/elektra"); keySetString (mp, "default"); compare_key(mp, kdb->split->parents[5]); keySetName(mp, "user/tests/simple"); keySetString (mp, "simple"); compare_key(mp, kdb->split->parents[4]); exit_if_fail (kdb->trie, "trie was not build up successfully"); // output_trie (kdb->trie); Key *searchKey = keyNew("", KEY_END); Key *rmp = keyNew("", KEY_VALUE, "root", KEY_END); elektraKeySetName(rmp, "/", KEY_CASCADING_NAME); Backend *b2 = 0; keySetName (searchKey, "user"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); compare_key(b2->mountpoint, rmp); Backend *backend = 0; keySetName(searchKey, "user/tests/simple"); backend = elektraTrieLookup(kdb->trie, searchKey); succeed_if (backend, "there should be a backend"); compare_key(backend->mountpoint, mp); keySetName(searchKey, "user/tests/simple/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (backend == b2, "should be same backend"); compare_key(b2->mountpoint, mp); keySetName(searchKey, "user/tests/simple/deep/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (backend == b2, "should be same backend"); compare_key(b2->mountpoint, mp); Key *dmp = keyNew ("", KEY_VALUE, "default", KEY_END); keySetName(searchKey, "system/elektra"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (b2 == kdb->defaultBackend, "should be the default backend"); compare_key(b2->mountpoint, dmp); keySetName(searchKey, "system/elektra/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (b2 == kdb->defaultBackend, "should be the default backend"); compare_key(b2->mountpoint, dmp); Key *mmp = keyNew ("system/elektra/modules", KEY_VALUE, "modules", KEY_END); keyAddBaseName (mmp, "default"); /* keySetName(searchKey, "system/elektra/modules/default"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (b2 != kdb->defaultBackend, "should not be the default backend"); compare_key(b2->mountpoint, mmp); */ keyDel (mmp); keyDel (dmp); keyDel (mp); keyDel (rmp); keyDel (searchKey); kdb_del (kdb); keyDel (errorKey); ksDel (modules); }
static void test_default() { printf ("Test mounting with default\n"); KDB *kdb = kdb_new(); Key *errorKey = keyNew(0); KeySet *modules = modules_config(); succeed_if (elektraMountOpen(kdb, root_config(), modules, errorKey) == 0, "could not buildup mount"); succeed_if (elektraMountDefault(kdb, modules, errorKey) == 0, "could not mount default backend"); succeed_if (kdb->split->size == 6, "size of split not correct"); Key *mp = keyNew("spec", KEY_VALUE, "root", KEY_END); compare_key(mp, kdb->split->parents[0]); keySetName(mp, "dir"); keySetString (mp, "root"); compare_key(mp, kdb->split->parents[1]); keySetName(mp, "user"); keySetString (mp, "root"); compare_key(mp, kdb->split->parents[2]); keySetName(mp, "system"); keySetString (mp, "root"); compare_key(mp, kdb->split->parents[3]); keySetName(mp, "system/elektra"); keySetString (mp, "default"); compare_key(mp, kdb->split->parents[5]); // must be last, needed later keySetName(mp, "user/tests/simple"); keySetString (mp, "simple"); compare_key(mp, kdb->split->parents[4]); succeed_if(output_warnings (errorKey), "warnings found"); succeed_if(output_error (errorKey), "error found"); exit_if_fail (kdb->trie, "trie was not build up successfully"); // output_trie (kdb->trie); Key *searchKey = keyNew("", KEY_END); Key *rmp = keyNew("", KEY_VALUE, "root", KEY_END); elektraKeySetName(rmp, "/", KEY_CASCADING_NAME); Backend *b2 = 0; keySetName (searchKey, "user"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); compare_key(b2->mountpoint, rmp); Backend *backend = 0; keySetName(searchKey, "user/tests/simple"); backend = elektraTrieLookup(kdb->trie, searchKey); succeed_if (backend, "there should be a backend"); compare_key(backend->mountpoint, mp); keySetName(searchKey, "user/tests/simple/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (backend == b2, "should be same backend"); compare_key(b2->mountpoint, mp); keySetName(searchKey, "user/tests/simple/deep/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (backend == b2, "should be same backend"); compare_key(b2->mountpoint, mp); Key *dmp = keyNew ("", KEY_VALUE, "default", KEY_END); keySetName(searchKey, "system/elektra"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (b2 == kdb->defaultBackend, "should be the default backend"); compare_key(b2->mountpoint, dmp); keySetName(searchKey, "system/elektra/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (b2 == kdb->defaultBackend, "should be the default backend"); compare_key(b2->mountpoint, dmp); keyDel (dmp); keyDel (mp); keyDel (rmp); keyDel (searchKey); kdb_del (kdb); keyDel (errorKey); ksDel (modules); }
static void test_cascading() { printf ("Test simple mount with cascading\n"); KDB *kdb = kdb_new(); Key *errorKey = keyNew(0); KeySet *modules = modules_config(); succeed_if (elektraMountOpen(kdb, cascading_config(), modules, errorKey) == 0, "could not open trie"); succeed_if (elektraMountDefault(kdb, modules, errorKey) == 0, "could not mount default backend"); succeed_if(output_warnings (errorKey), "warnings found"); succeed_if(output_error (errorKey), "error found"); exit_if_fail (kdb->trie, "kdb->trie was not build up successfully"); succeed_if (kdb->split->size == 7, "size of split not correct"); Key *mp = keyNew("dir/tests/simple", KEY_VALUE, "simple", KEY_END); compare_key(mp, kdb->split->parents[0]); keySetName(mp, "user/tests/simple"); keySetString (mp, "simple"); compare_key(mp, kdb->split->parents[1]); keySetName(mp, "system/tests/simple"); keySetString (mp, "simple"); compare_key(mp, kdb->split->parents[2]); keyDel (mp); // output_split (kdb->split); // output_trie (kdb->trie); Key *searchKey = keyNew("user", KEY_END); Backend *backend = elektraTrieLookup(kdb->trie, searchKey); succeed_if (!backend, "there should be no backend"); keySetName(searchKey, "system"); backend = elektraTrieLookup(kdb->trie, searchKey); succeed_if (!backend, "there should be no backend"); mp = keyNew("", KEY_VALUE, "simple", KEY_END); elektraKeySetName(mp, "/tests/simple", KEY_CASCADING_NAME); keySetName(searchKey, "user/tests/simple"); backend = elektraTrieLookup(kdb->trie, searchKey); succeed_if (backend, "there should be a backend"); compare_key(backend->mountpoint, mp); keySetName(searchKey, "user/tests/simple/below"); Backend *b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (backend == b2, "should be same backend"); compare_key(b2->mountpoint, mp); keySetName(searchKey, "user/tests/simple/deep/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (backend == b2, "should be same backend"); compare_key(b2->mountpoint, mp); keySetName(searchKey, "system/tests/simple"); backend = elektraTrieLookup(kdb->trie, searchKey); succeed_if (backend, "there should be a backend"); compare_key(backend->mountpoint, mp); keySetName(searchKey, "system/tests/simple/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (backend == b2, "should be same backend"); compare_key(b2->mountpoint, mp); keySetName(searchKey, "system/tests/simple/deep/below"); b2 = elektraTrieLookup(kdb->trie, searchKey); succeed_if (b2, "there should be a backend"); succeed_if (backend == b2, "should be same backend"); compare_key(b2->mountpoint, mp); keyDel (errorKey); ksDel (modules); keyDel (mp); keyDel (searchKey); kdb_del (kdb); }
/** * Set a new name to a key. * * A valid name is one of the forms: * @copydetails doxygenNamespaces * * An invalid name either has an invalid namespace or * a wrongly escaped \\ at the end of the name. * * See @link keyname key names @endlink for the exact rules. * * The last form has explicitly set the owner, to let the library * know in which user folder to save the key. A owner is a user name. * If it is not defined (the second form) current user is used. * * You should always follow the guidelines for key tree structure creation. * * A private copy of the key name will be stored, and the @p newName * parameter can be freed after this call. * * .., . and / will be handled as in filesystem paths. A valid name will be build * out of the (valid) name what you pass, e.g. user///sw/../sw//././MyApp -> user/sw/MyApp * * On invalid names, NULL or "" the name will be "" afterwards. * * * @retval size in bytes of this new key name including ending NULL * @retval 0 if newName is an empty string or a NULL pointer (name will be empty afterwards) * @retval -1 if newName is invalid (name will be empty afterwards) * @retval -1 if key was inserted to a keyset before * @param key the key object to work with * @param newName the new key name * @see keyNew(), keySetOwner() * @see keyGetName(), keyGetFullName(), keyName() * @see keySetBaseName(), keyAddBaseName() to manipulate a name * @ingroup keyname */ ssize_t keySetName (Key * key, const char * newName) { return elektraKeySetName (key, newName, 0); }
/**Set a new meta-information. * * Will set a new meta-information pair consisting of * metaName and newMetaString. * * Will add a new Pair for meta-information if metaName was * not added up to now. * * It will modify a existing Pair of meta-information if the * the metaName was inserted already. * * It will remove a meta information if newMetaString is 0. * * @param key the key object to work with * @param metaName the name of the meta information where you * want to change the value * @param newMetaString the new value for the meta information * @retval -1 on error if key or metaName is 0, out of memory * or names are not valid * @retval 0 if the meta-information for metaName was removed * @return size (>0) of newMetaString if meta-information was * successfully added * @see keyGetMeta() * @ingroup keymeta **/ ssize_t keySetMeta (Key * key, const char * metaName, const char * newMetaString) { Key * toSet; char * metaStringDup; ssize_t metaNameSize; ssize_t metaStringSize = 0; if (!key) return -1; if (key->flags & KEY_FLAG_RO_META) return -1; if (!metaName) return -1; metaNameSize = elektraStrLen (metaName); if (metaNameSize == -1) return -1; if (newMetaString) metaStringSize = elektraStrLen (newMetaString); // optimization: we have nothing and want to remove something: if (!key->meta && !newMetaString) return 0; toSet = keyNew (0); if (!toSet) return -1; elektraKeySetName (toSet, metaName, KEY_META_NAME | KEY_EMPTY_NAME); /*Lets have a look if the key is already inserted.*/ if (key->meta) { Key * ret; ret = ksLookup (key->meta, toSet, KDB_O_POP); if (ret) { /*It was already there, so lets drop that one*/ keyDel (ret); key->flags |= KEY_FLAG_SYNC; } } if (newMetaString) { /*Add the meta information to the key*/ metaStringDup = elektraStrNDup (newMetaString, metaStringSize); if (!metaStringDup) { // TODO: actually we might already have changed // the key keyDel (toSet); return -1; } if (toSet->data.v) elektraFree (toSet->data.v); toSet->data.c = metaStringDup; toSet->dataSize = metaStringSize; } else { /*The request is to remove the meta string. So simply drop it.*/ keyDel (toSet); return 0; } if (!key->meta) { /*Create a new place for meta information.*/ key->meta = ksNew (0, KS_END); if (!key->meta) { keyDel (toSet); return -1; } } set_bit (toSet->flags, KEY_FLAG_RO_NAME); set_bit (toSet->flags, KEY_FLAG_RO_VALUE); set_bit (toSet->flags, KEY_FLAG_RO_META); ksAppendKey (key->meta, toSet); key->flags |= KEY_FLAG_SYNC; return metaStringSize; }
/** * 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, const char * file, Key *errorKey) { Backend *backend = elektraBackendAllocate(); KeySet *resolverConfig = ksNew(5, keyNew("system/path", KEY_VALUE, file, KEY_END), KS_END); elektraKeySetName(errorKey, "", KEY_CASCADING_NAME | KEY_EMPTY_NAME); Plugin *resolver = elektraPluginOpen(KDB_DEFAULT_RESOLVER, modules, resolverConfig, errorKey); if (!resolver) { elektraFree(backend); /* error already set in elektraPluginOpen */ return 0; } #if DEBUG && VERBOSE KeySet *tracerConfig = ksNew(5, // does not matter because it is mounted differently in system/elektra/modules: // keyNew("system/logmodule", KEY_VALUE, "1", KEY_END), KS_END); Plugin *tracer = elektraPluginOpen("tracer", modules, tracerConfig, errorKey); if (tracer) { backend->getplugins[RESOLVER_PLUGIN+1] = tracer; backend->setplugins[RESOLVER_PLUGIN+1] = tracer; backend->errorplugins[RESOLVER_PLUGIN+1] = tracer; tracer->refcounter = 3; } #endif 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; }