diff --git a/.gitignore b/.gitignore index af7f37f8f5d..7b7a10f4b8b 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,8 @@ nbproject/ #ignore macOS folder attribute files .DS_Store .directory + +#ignore CLion project files +.idea/ +cmake-build-debug/ +cmake-build-release/ diff --git a/cmake/ElektraConfig.cmake.in b/cmake/ElektraConfig.cmake.in index 01de93aeb80..5a1f29fc93d 100644 --- a/cmake/ElektraConfig.cmake.in +++ b/cmake/ElektraConfig.cmake.in @@ -18,7 +18,7 @@ if (NOT elektra_imported_targets) endif() set (Elektra_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include/@TARGET_INCLUDE_FOLDER@") -set (Elektra_LIBRARIES elektra-core elektra-kdb) +set (Elektra_LIBRARIES elektra-core elektra-kdb elektra-highlevel) find_path (Elektra_TEMPLATES_DIR NAMES template.h diff --git a/cmake/elektra.pc.in b/cmake/elektra.pc.in index d11e3c2bcd9..c2ed33ba4c3 100644 --- a/cmake/elektra.pc.in +++ b/cmake/elektra.pc.in @@ -9,5 +9,5 @@ templatedir=${prefix}/@TARGET_TEMPLATE_FOLDER@ Name: @PACKAGE_NAME@ Description: @PACKAGE_DESCRIPTION@ Version: @KDB_VERSION@ -Libs: -L${libdir} -lelektra-core -lelektra-kdb +Libs: -L${libdir} -lelektra-core -lelektra-kdb -lelektra-highlevel Cflags: -I${includedir} diff --git a/doc/decisions/high_level_api.md b/doc/decisions/high_level_api.md index 1ebc8453b44..7c93bba451f 100644 --- a/doc/decisions/high_level_api.md +++ b/doc/decisions/high_level_api.md @@ -75,13 +75,18 @@ sure to use pass a `KeySet`, that has your whole specification included ### Error Handling ```c -const char * elektraErrorMessage (const ElektraError * error); -kdb_boolean_t elektraErrorAbort (const ElektraError * error); -void elektraErrorFree (ElektraError * error) +ElektraErrorCode elektraErrorCode (ElektraError * error); +const char * elektraErrorDescription (ElektraError * error); +ElektraErrorSeverity elektraErrorSeverity (ElektraError * error); +ElektraErrorGroup elektraErrorGroup (ElektraError * error); +ElektraErrorModule elektraErrorModule (ElektraError * error); + +void elektraErrorFree (ElektraError * error); + ``` -`elektraErrorAbort` tells you if you need to quit your application because of severe -issues that are permanent. Otherwise, developers can just print the message and +`elektraErrorSeverity` tells you if you need to quit your application because of severe +issues that are permanent (severity == ELEKTRA_ERROR_SEVERITY_FATAL). Otherwise, developers can just print the message and continue. (Default settings might be used then.) ### Simple Getters @@ -113,7 +118,7 @@ kdb_long_double_t elektraGetLongDouble (Elektra * elektra, const char * name); ```c size_t elektraArraySize (Elektra * handle, const char * name); -kdb_long_t elektraArrayLong (Elektra * handle, const char * name, size_t elem); +const char * elektraGetStringArrayElement (Elektra * elektra, const char * name, size_t index); // same types as above ``` diff --git a/doc/tutorials/README.md b/doc/tutorials/README.md index 3703cb06e78..804e82d20fb 100644 --- a/doc/tutorials/README.md +++ b/doc/tutorials/README.md @@ -25,6 +25,7 @@ provides. - [Python Bindings](python-kdb.md) - [Ruby Bindings](/src/bindings/swig/ruby/README.md) - [Code Generation](/src/tools/gen/README.md) +- [High Level API](/src/libs/highlevel/README.md) ## System Administrators diff --git a/src/bindings/cpp/include/kdbcontext.hpp b/src/bindings/cpp/include/kdbcontext.hpp index 3669cfcf83f..ba04d839444 100644 --- a/src/bindings/cpp/include/kdbcontext.hpp +++ b/src/bindings/cpp/include/kdbcontext.hpp @@ -262,7 +262,7 @@ class Context : public Subject * @par on_layer is called for every layer in the * specification. * @return the evaluated string - */ + */ std::string evaluate (std::string const & key_name, std::function const & on_layer) const { diff --git a/src/bindings/cpp/include/kdbplugin.hpp b/src/bindings/cpp/include/kdbplugin.hpp index 3c3fe0138f7..e03c18c936c 100644 --- a/src/bindings/cpp/include/kdbplugin.hpp +++ b/src/bindings/cpp/include/kdbplugin.hpp @@ -59,7 +59,7 @@ class Delegator private: /**This function avoid that every return path need to release the - * configuration. */ + * configuration. */ inline static int openHelper (ckdb::Plugin * handle, kdb::KeySet & config, ckdb::Key * errorKey, Builder builder) { if (config.lookup ("/module")) diff --git a/src/bindings/glib/gelektra-kdb.c b/src/bindings/glib/gelektra-kdb.c index 818cdac94ba..8fabc93f9cd 100644 --- a/src/bindings/glib/gelektra-kdb.c +++ b/src/bindings/glib/gelektra-kdb.c @@ -20,7 +20,7 @@ static void gelektra_kdb_finalize (GObject * object) /* Always chain up to the parent class; as with dispose(), finalize() * is guaranteed to exist on the parent's class virtual function table - */ + */ G_OBJECT_CLASS (gelektra_kdb_parent_class)->finalize (object); } diff --git a/src/bindings/glib/gelektra-key.c b/src/bindings/glib/gelektra-key.c index d1e89dfe2ec..1febedc14a4 100644 --- a/src/bindings/glib/gelektra-key.c +++ b/src/bindings/glib/gelektra-key.c @@ -69,7 +69,7 @@ static void gelektra_key_finalize (GObject * object) /* Always chain up to the parent class; as with dispose(), finalize() * is guaranteed to exist on the parent's class virtual function table - */ + */ G_OBJECT_CLASS (gelektra_key_parent_class)->finalize (object); } diff --git a/src/bindings/glib/gelektra-keyset.c b/src/bindings/glib/gelektra-keyset.c index a06a26390ba..23e90ad2095 100644 --- a/src/bindings/glib/gelektra-keyset.c +++ b/src/bindings/glib/gelektra-keyset.c @@ -19,7 +19,7 @@ static void gelektra_keyset_finalize (GObject * object) /* Always chain up to the parent class; as with dispose(), finalize() * is guaranteed to exist on the parent's class virtual function table - */ + */ G_OBJECT_CLASS (gelektra_keyset_parent_class)->finalize (object); } diff --git a/src/bindings/intercept/env/benchmarks/benchmark_getenv.cpp b/src/bindings/intercept/env/benchmarks/benchmark_getenv.cpp index 37e4f50e3f6..b6f93dc46ee 100644 --- a/src/bindings/intercept/env/benchmarks/benchmark_getenv.cpp +++ b/src/bindings/intercept/env/benchmarks/benchmark_getenv.cpp @@ -150,12 +150,12 @@ __attribute__ ((noinline)) void benchmark_kslookup () using namespace kdb; // needed for KS_END kdb::KeySet ks (100, /* - *kdb::Key("user/env/override/some", KEY_END), - *kdb::Key("user/env/override/a/key", KEY_END), - *kdb::Key("user/env/override/b/key", KEY_END), - *kdb::Key("user/env/override/c/key", KEY_END), - *kdb::Key("user/env/override/d/key", KEY_END), - */ + *kdb::Key("user/env/override/some", KEY_END), + *kdb::Key("user/env/override/a/key", KEY_END), + *kdb::Key("user/env/override/b/key", KEY_END), + *kdb::Key("user/env/override/c/key", KEY_END), + *kdb::Key("user/env/override/d/key", KEY_END), + */ KS_END); for (int i = 0; i < nr_keys; ++i) { diff --git a/src/error/exporterrors.cpp b/src/error/exporterrors.cpp index 1a6a69e9442..107be5c6597 100644 --- a/src/error/exporterrors.cpp +++ b/src/error/exporterrors.cpp @@ -111,6 +111,28 @@ ostream & operator<< (ostream & os, parse_t & p) os << endl << endl; + /* Temporarily disable enum generation. + os << "typedef enum {" << endl; + for (size_t i = 1; i < p.size (); ++i) + { + if (p[i]["unused"] == "yes") + { + continue; + } + + if (p[i]["macro"].empty ()) + { + continue; + } + + os << " ELEKTRA_ERROR_CODE_"; + os << p[i]["enum"] << " = " << i << "," << endl; + } + os << "} ElektraErrorCode;" << endl; + + os << endl << endl; + */ + for (size_t i = 1; i < p.size (); ++i) { if (p[i]["unused"] == "yes") diff --git a/src/error/specification b/src/error/specification index dcf6ceb3e19..3f9d0a56a0d 100644 --- a/src/error/specification +++ b/src/error/specification @@ -69,13 +69,13 @@ ingroup:kdb number:9 description:Insufficient permissions to open configuration file for writing. You might want to retry as root. -severity:normal +severity:error ingroup:kdb see:75 109 110 number:10 description:general parse error -severity:normal +severity:error ingroup:kdb macro:PARSE @@ -656,7 +656,7 @@ see:9 75 110 number:110 description:could not open configuration file for reading. -severity:normal +severity:error ingroup:plugin module:storage see:9 75 109 diff --git a/src/include/CMakeLists.txt b/src/include/CMakeLists.txt index 6c8a9f40ef3..75bcde675df 100644 --- a/src/include/CMakeLists.txt +++ b/src/include/CMakeLists.txt @@ -95,6 +95,11 @@ install (FILES kdbinvoke.h kdbutility.h "${CMAKE_CURRENT_BINARY_DIR}/kdbversion.h" + elektra.h + elektra_generic.h + elektra_error.h + elektra_error_codes.h + elektra_conversion.h DESTINATION include/${TARGET_INCLUDE_FOLDER}) diff --git a/src/include/elektra.h b/src/include/elektra.h new file mode 100644 index 00000000000..e27e0c397c4 --- /dev/null +++ b/src/include/elektra.h @@ -0,0 +1,518 @@ +/** + * @file + * + * @brief Elektra High Level API. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#ifndef ELEKTRA_H +#define ELEKTRA_H + +#include "elektra_conversion.h" +#include "elektra_error.h" +#include "kdb.h" +#include "kdbtypes.h" + +/** + * \defgroup highlevel High-level API + * @{ + */ + +typedef struct _Elektra Elektra; + +#define ELEKTRA_TAG(typeName) Elektra##typeName##Tag + +#define ELEKTRA_SET_BY_TAG(typeName) __elektraSet##typeName##ByTag +#define ELEKTRA_SET_ARRAY_ELEMENT_BY_TAG(typeName) __elektraSet##typeName##ArrayElementByTag + +#define ELEKTRA_GET_BY_TAG(typeName) __elektraGet##typeName##ByTag +#define ELEKTRA_GET_ARRAY_ELEMENT_BY_TAG(typeName) __elektraGet##typeName##ArrayElementByTag + +#define ELEKTRA_SET_BY_TAG_SIGNATURE(Type, typeName) \ + void ELEKTRA_SET_BY_TAG (typeName) (Elektra * elektra, ELEKTRA_TAG (typeName) tag, Type value, ElektraError * *error) +#define ELEKTRA_SET_ARRAY_ELEMENT_BY_TAG_SIGNATURE(Type, typeName) \ + void ELEKTRA_SET_ARRAY_ELEMENT_BY_TAG (typeName) (Elektra * elektra, ELEKTRA_TAG (typeName) tag, size_t index, Type value, \ + ElektraError * *error) + +#define ELEKTRA_GET_BY_TAG_SIGNATURE(Type, typeName) Type ELEKTRA_GET_BY_TAG (typeName) (Elektra * elektra, ELEKTRA_TAG (typeName) tag) +#define ELEKTRA_GET_ARRAY_ELEMENT_BY_TAG_SIGNATURE(Type, typeName) \ + Type ELEKTRA_GET_ARRAY_ELEMENT_BY_TAG (typeName) (Elektra * elektra, ELEKTRA_TAG (typeName) tag, size_t index) + +struct ElektraTag +{ + char * keyName; +}; + +#define ELEKTRA_DECLARATIONS(Type, typeName) \ + typedef struct \ + { \ + char * keyName; \ + } ELEKTRA_TAG (typeName); \ + \ + ELEKTRA_SET_BY_TAG_SIGNATURE (Type, typeName); \ + ELEKTRA_SET_ARRAY_ELEMENT_BY_TAG_SIGNATURE (Type, typeName); \ + \ + ELEKTRA_GET_BY_TAG_SIGNATURE (Type, typeName); \ + ELEKTRA_GET_ARRAY_ELEMENT_BY_TAG_SIGNATURE (Type, typeName); + +#define ELEKTRA_DEFINITIONS(Type, typeName, KDB_TYPE, TO_STRING, TO_VALUE) \ + ELEKTRA_SET_BY_TAG_SIGNATURE (Type, typeName) \ + { \ + elektraSetValue (elektra, tag.keyName, TO_STRING (value), KDB_TYPE, error); \ + } \ + \ + ELEKTRA_SET_ARRAY_ELEMENT_BY_TAG_SIGNATURE (Type, typeName) \ + { \ + elektraSetArrayElementValue (elektra, tag.keyName, index, TO_STRING (value), KDB_TYPE, error); \ + } \ + \ + ELEKTRA_GET_BY_TAG_SIGNATURE (Type, typeName) \ + { \ + return TO_VALUE (elektraGetValue (elektra, tag.keyName, KDB_TYPE)); \ + } \ + \ + ELEKTRA_GET_ARRAY_ELEMENT_BY_TAG_SIGNATURE (Type, typeName) \ + { \ + return TO_VALUE (elektraGetArrayElementValue (elektra, tag.keyName, index, KDB_TYPE)); \ + } + +// Elektra built-in types + +#define ELEKTRA_TYPES(X) \ + X (const char *, String) \ + X (kdb_boolean_t, Boolean) \ + X (kdb_char_t, Char) \ + X (kdb_octet_t, Octet) \ + X (kdb_short_t, Short) \ + X (kdb_unsigned_short_t, UnsignedShort) \ + X (kdb_long_t, Long) \ + X (kdb_unsigned_long_t, UnsignedLong) \ + X (kdb_long_long_t, LongLong) \ + X (kdb_unsigned_long_long_t, UnsignedLongLong) \ + X (kdb_float_t, Float) \ + X (kdb_double_t, Double) \ + X (kdb_long_double_t, LongDouble) \ + X (int, Enum) + +ELEKTRA_TYPES (ELEKTRA_DECLARATIONS) + +typedef const char * KDBType; + +extern KDBType KDB_TYPE_STRING; +extern KDBType KDB_TYPE_BOOLEAN; +extern KDBType KDB_TYPE_CHAR; +extern KDBType KDB_TYPE_OCTET; +extern KDBType KDB_TYPE_SHORT; +extern KDBType KDB_TYPE_UNSIGNED_SHORT; +extern KDBType KDB_TYPE_LONG; +extern KDBType KDB_TYPE_UNSIGNED_LONG; +extern KDBType KDB_TYPE_LONG_LONG; +extern KDBType KDB_TYPE_UNSIGNED_LONG_LONG; +extern KDBType KDB_TYPE_FLOAT; +extern KDBType KDB_TYPE_LONG_DOUBLE; +extern KDBType KDB_TYPE_DOUBLE; +extern KDBType KDB_TYPE_ENUM; + +// Setters + +#define ELEKTRA_SET_VALUE(typeName, KDB_TYPE, elektra, keynameOrTag, value, error) \ + elektraSetValue (elektra, _Generic((keynameOrTag), char *: keynameOrTag, ELEKTRA_TAG(typeName): ((ELEKTRA_TAG(typeName) *)&keynameOrTag)->keyName), value, KDB_TYPE, error) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param keynameOrTag The keyname (or a codegenerated Tag) to write to. The keyname is appended to the parent key. + * @param value The new value. + * @param value Pass a reference to an ElektraError pointer. + */ +#define elektraSetString(elektra, keynameOrTag, value, error) ELEKTRA_SET_VALUE (String, "string", elektra, keynameOrTag, value, error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetBoolean(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (Boolean, "boolean", elektra, keynameOrTag, KDB_BOOLEAN_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetChar(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (Char, "char", elektra, keynameOrTag, KDB_CHAR_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetOctet(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (Octet, "octet", elektra, keynameOrTag, KDB_OCTET_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetShort(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (Short, "short", elektra, keynameOrTag, KDB_SHORT_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetUnsignedShort(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (UnsignedShort, "unsigned_short", elektra, keynameOrTag, KDB_UNSIGNED_SHORT_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetLong(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (Long, "long", elektra, keynameOrTag, KDB_LONG_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetUnsignedLong(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (UnsignedLong, "unsigned_long", elektra, keynameOrTag, KDB_UNSIGNED_LONG_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetLongLong(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (LongLong, "long_long", elektra, keynameOrTag, KDB_LONG_LONG_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetUnsignedLongLong(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (UnsignedLongLong, "unsigned_long_long", elektra, keynameOrTag, KDB_UNSIGNED_LONG_LONG_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetFloat(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (Float, "float", elektra, keynameOrTag, KDB_FLOAT_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetDouble(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (Double, "double", elektra, keynameOrTag, KDB_DOUBLE_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +#define elektraSetLongDouble(elektra, keynameOrTag, value, error) \ + ELEKTRA_SET_VALUE (LongDouble, "long_double", elektra, keynameOrTag, KDB_LONG_DOUBLE_TO_STRING (value), error) + +/** + * @copydoc elektraSetString + */ +//#define elektraSetEnum(elektra, keynameOrTag, value, error) \ +//ELEKTRA_SET_VALUE (Enum, "enum", elektra, keynameOrTag, KDB_ENUM_TO_STRING (value), error) + +// Getters + +#define ELEKTRA_GET_VALUE(typeName, KDB_TYPE, elektra, keynameOrTag) \ + elektraGetValue (elektra, _Generic((keynameOrTag), char *: keynameOrTag, ELEKTRA_TAG(typeName): ((ELEKTRA_TAG(typeName) *)&keynameOrTag)->keyName), KDB_TYPE) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param name The keyname to look up. The keyname is appended to the parent key. + * @param index The array index of the desired element, starting with 0. + * @return The value stored at the given key and index. +*/ +#define elektraGetString(elektra, keynameOrTag) ELEKTRA_GET_VALUE (String, "string", elektra, keynameOrTag) + +/** + * @copydoc elektraGetString + */ +#define elektraGetBoolean(elektra, keynameOrTag) KDB_STRING_TO_BOOLEAN (ELEKTRA_GET_VALUE (Boolean, "boolean", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetChar(elektra, keynameOrTag) KDB_STRING_TO_CHAR (ELEKTRA_GET_VALUE (Char, "char", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetOctet(elektra, keynameOrTag) KDB_STRING_TO_OCTET (ELEKTRA_GET_VALUE (Octet, "octet", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetShort(elektra, keynameOrTag) KDB_STRING_TO_SHORT (ELEKTRA_GET_VALUE (Short, "short", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetUnsignedShort(elektra, keynameOrTag) \ + KDB_STRING_TO_UNSIGNED_SHORT (ELEKTRA_GET_VALUE (UnsignedShort, "unsigned_short", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetLong(elektra, keynameOrTag) KDB_STRING_TO_LONG (ELEKTRA_GET_VALUE (Long, "long", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetUnsignedLong(elektra, keynameOrTag) \ + KDB_STRING_TO_UNSIGNED_LONG (ELEKTRA_GET_VALUE (UnsignedLong, "unsigned_long", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetLongLong(elektra, keynameOrTag) KDB_STRING_TO_LONG_LONG (ELEKTRA_GET_VALUE (LongLong, "long_long", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetUnsignedLongLong(elektra, keynameOrTag) \ + KDB_STRING_TO_UNSIGNED_LONG_LONG (ELEKTRA_GET_VALUE (UnsignedLongLong, "unsigned_long_long", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetFloat(elektra, keynameOrTag) KDB_STRING_TO_FLOAT (ELEKTRA_GET_VALUE (Float, "float", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetDouble(elektra, keynameOrTag) KDB_STRING_TO_DOUBLE (ELEKTRA_GET_VALUE (Double, "double", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +#define elektraGetLongDouble(elektra, keynameOrTag) \ + KDB_STRING_TO_LONG_DOUBLE (ELEKTRA_GET_VALUE (LongDouble, "long_double", elektra, keynameOrTag)) + +/** + * @copydoc elektraGetString + */ +//#define elektraGetEnum(elektra, keynameOrTag) \ +//KDB_STRING_TO_ENUM (ELEKTRA_GET_VALUE (Enum, "enum", elektra, keynameOrTag)) + +// Array-Setters + +#define ELEKTRA_SET_ARRAY_ELEMENT_VALUE(typeName, KDB_TYPE, elektra, keynameOrTag, index, value, error) \ + elektraSetArrayElementValue (elektra, _Generic((keynameOrTag), char *: keynameOrTag, ELEKTRA_TAG(typeName): ((ELEKTRA_TAG(typeName) *)&keynameOrTag)->keyName), index, value, KDB_TYPE, error) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param keynameOrTag The keyname (or a codegenerated Tag) to write to. The keyname is appended to the parent key. + * @param value The new value. + * @param value Pass a reference to an ElektraError pointer. + */ +#define elektraSetStringArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (String, "string", elektra, keynameOrTag, index, value, error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetBooleanArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (Boolean, "boolean", elektra, keynameOrTag, index, KDB_BOOLEAN_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetCharArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (Char, "char", elektra, keynameOrTag, index, KDB_CHAR_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetOctetArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (Octet, "octet", elektra, keynameOrTag, index, KDB_OCTET_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetShortArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (Short, "short", elektra, keynameOrTag, index, KDB_SHORT_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetUnsignedShortArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (UnsignedShort, "unsigned_short", elektra, keynameOrTag, index, \ + KDB_UNSIGNED_SHORT_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetLongArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (Long, "long", elektra, keynameOrTag, index, KDB_LONG_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetUnsignedLongArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (UnsignedLong, "unsigned_long", elektra, keynameOrTag, index, KDB_UNSIGNED_LONG_TO_STRING (value), \ + error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetLongLongArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (LongLong, "long_long", elektra, keynameOrTag, index, KDB_LONG_LONG_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetUnsignedLongLongArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (UnsignedLongLong, "unsigned_long_long", elektra, keynameOrTag, index, \ + KDB_UNSIGNED_LONG_LONG_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetFloatArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (Float, "float", elektra, keynameOrTag, index, KDB_FLOAT_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetDoubleArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (Double, "double", elektra, keynameOrTag, index, KDB_DOUBLE_TO_STRING (value), error) + +/** + * @copydoc elektraSetStringArrayElement + */ +#define elektraSetLongDoubleArrayElement(elektra, keynameOrTag, index, value, error) \ + ELEKTRA_SET_ARRAY_ELEMENT_VALUE (LongDouble, "long_double", elektra, keynameOrTag, index, KDB_LONG_DOUBLE_TO_STRING (value), error) + +// Array-Getters + +#define ELEKTRA_GET_ARRAY_ELEMENT_VALUE(typeName, KDB_TYPE, elektra, keynameOrTag, index) \ + elektraGetArrayElementValue (elektra, _Generic((keynameOrTag), char *: keynameOrTag, ELEKTRA_TAG(typeName): ((ELEKTRA_TAG(typeName) *)&keynameOrTag)->keyName), index, KDB_TYPE) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param keyName The keyname (or a codegenerated Tag) to look up. The keyname is appended to the parent key. + * @param value The new value. + * @param index The array index of the desired element, starting with 0. \ + * @return The value stored at the given key and index. +*/ +#define elektraGetStringArrayElement(elektra, keynameOrTag, index) \ + ELEKTRA_GET_ARRAY_ELEMENT_VALUE (String, "string", elektra, keynameOrTag, index) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetBooleanArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_BOOLEAN (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (Boolean, "boolean", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetCharArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_CHAR (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (Char, "char", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetOctetArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_OCTET (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (Octet, "octet", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetShortArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_SHORT (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (Short, "short", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetUnsignedShortArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_UNSIGNED_SHORT (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (UnsignedShort, "unsigned_short", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetLongArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_LONG (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (Long, "long", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetUnsignedLongArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_UNSIGNED_LONG (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (UnsignedLong, "unsigned_long", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetLongLongArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_LONG_LONG (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (LongLong, "long_long", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetUnsignedLongLongArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_UNSIGNED_LONG_LONG ( \ + ELEKTRA_GET_ARRAY_ELEMENT_VALUE (UnsignedLongLong, "unsigned_long_long", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetFloatArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_FLOAT (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (Float, "float", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetDoubleArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_DOUBLE (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (Double, "double", elektra, keynameOrTag, index)) + +/** + * @copydoc elektraGetStringArrayElement + */ +#define elektraGetLongDoubleArrayElement(elektra, keynameOrTag, index) \ + KDB_STRING_TO_LONG_DOUBLE (ELEKTRA_GET_ARRAY_ELEMENT_VALUE (LongDouble, "long_double", elektra, keynameOrTag, index)) + +void __elektraSetEnum (Elektra * elektra, char * name, int value, ElektraError ** error); +void __elektraSetEnumArrayElement (Elektra * elektra, char * name, size_t index, int value, ElektraError ** error); +int __elektraGetEnum (Elektra * elektra, char * keyName); +int __elektraGetEnumArrayElement (Elektra * elektra, char * keyName, int index); + +Elektra * elektraOpen (const char * application, KeySet * defaults, ElektraError ** error); +void elektraClose (Elektra * elektra); +size_t elektraArraySize (Elektra * elektra, const char * keyName); + +void elektraSetValue (Elektra * elektra, const char * name, const char * value, KDBType type, ElektraError ** error); +const char * elektraGetValue (Elektra * elektra, const char * name, KDBType type); + +void elektraSetArrayElementValue (Elektra * elektra, const char * name, size_t index, const char * value, KDBType type, + ElektraError ** error); +const char * elektraGetArrayElementValue (Elektra * elektra, const char * name, size_t index, KDBType type); + +// Generic Setters and Getters + +#define ELEKTRA_GENERIC_SET_ENTRY(typeName) ELEKTRA_TAG (typeName) : ELEKTRA_SET_BY_TAG (typeName), + +#define ELEKTRA_GENERIC_SET_ARRAY_ELEMENT_ENTRY(typeName) ELEKTRA_TAG (typeName) : ELEKTRA_SET_ARRAY_ELEMENT_BY_TAG (typeName), + +#define ELEKTRA_GENERIC_GET_ENTRY(typeName) ELEKTRA_TAG (typeName) : ELEKTRA_GET_BY_TAG (typeName), + +#define ELEKTRA_GENERIC_GET_ARRAY_ELEMENT_ENTRY(typeName) ELEKTRA_TAG (typeName) : ELEKTRA_GET_ARRAY_ELEMENT_BY_TAG (typeName), + +#define ELEKTRA_TAG_NAMES_EXCEPT_STRING(X) \ + X (Boolean) \ + X (Char) \ + X (Octet) \ + X (Short) \ + X (UnsignedShort) \ + X (Long) \ + X (UnsignedLong) \ + X (LongLong) \ + X (UnsignedLongLong) \ + X (Float) \ + X (Double) \ + X (LongDouble) \ + X (Enum) + +#include "elektra_generic.h" + +#define ELEKTRA_TAG_NAMES_GEN(X) + + +/** + * @} + */ + +#endif // ELEKTRA_H diff --git a/src/include/elektra_conversion.h b/src/include/elektra_conversion.h new file mode 100644 index 00000000000..fe525cdb85c --- /dev/null +++ b/src/include/elektra_conversion.h @@ -0,0 +1,45 @@ +/** + * @file + * + * @brief Elektra conversion. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#ifndef ELEKTRA_CONVERSION_H +#define ELEKTRA_CONVERSION_H + +#include "kdbhelper.h" +#include + +#define KDB_STRING_TO_STRING(value) value + +#define KDB_STRING_TO_BOOLEAN(string) (kdb_boolean_t) !strcmp (string, "1") +#define KDB_STRING_TO_CHAR(string) (kdb_char_t) string[0] +#define KDB_STRING_TO_OCTET(string) (kdb_octet_t) strtoul (string, NULL, 10) +#define KDB_STRING_TO_SHORT(string) (kdb_short_t) strtoul (string, NULL, 10) +#define KDB_STRING_TO_UNSIGNED_SHORT(string) (kdb_unsigned_short_t) strtoul (string, NULL, 10) +#define KDB_STRING_TO_LONG(string) (kdb_long_t) strtoul (string, NULL, 10) +#define KDB_STRING_TO_UNSIGNED_LONG(string) (kdb_unsigned_long_t) strtoul (string, NULL, 10) +#define KDB_STRING_TO_LONG_LONG(string) ELEKTRA_LONG_LONG_S (string, NULL, 10) +#define KDB_STRING_TO_UNSIGNED_LONG_LONG(string) ELEKTRA_UNSIGNED_LONG_LONG_S (string, NULL, 10) +#define KDB_STRING_TO_FLOAT(string) strtof (string, NULL) +#define KDB_STRING_TO_DOUBLE(string) strtod (string, NULL) +#define KDB_STRING_TO_LONG_DOUBLE(string) strtold (string, NULL) +#define KDB_STRING_TO_ENUM(string) atoi (string) + +#define KDB_BOOLEAN_TO_STRING(value) ((value ? "1" : "0")) +#define KDB_CHAR_TO_STRING(value) elektraFormat ("%c", value) +#define KDB_OCTET_TO_STRING(value) elektraFormat ("%d", value) +#define KDB_SHORT_TO_STRING(value) elektraFormat ("%d", value) +#define KDB_UNSIGNED_SHORT_TO_STRING(value) elektraFormat ("%d", value) +#define KDB_LONG_TO_STRING(value) elektraFormat (ELEKTRA_LONG_F, value) +#define KDB_UNSIGNED_LONG_TO_STRING(value) elektraFormat (ELEKTRA_UNSIGNED_LONG_F, value) +#define KDB_LONG_LONG_TO_STRING(value) elektraFormat (ELEKTRA_LONG_LONG_F, value) +#define KDB_UNSIGNED_LONG_LONG_TO_STRING(value) elektraFormat (ELEKTRA_UNSIGNED_LONG_LONG_F, value) +#define KDB_FLOAT_TO_STRING(value) elektraFormat ("%f", value) +#define KDB_DOUBLE_TO_STRING(value) elektraFormat ("%f", value) +#define KDB_LONG_DOUBLE_TO_STRING(value) elektraFormat ("%Lf", value) +#define KDB_ENUM_TO_STRING(string) elektraFormat ("%d", value) + +#endif // ELEKTRA_CONVERSION_H diff --git a/src/include/elektra_error.h b/src/include/elektra_error.h new file mode 100644 index 00000000000..6b127bdb854 --- /dev/null +++ b/src/include/elektra_error.h @@ -0,0 +1,29 @@ +/** + * @file + * + * @brief Elektra error. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#ifndef ELEKTRA_ERROR_H +#define ELEKTRA_ERROR_H + +#include "elektra_error_codes.h" + +typedef struct _ElektraError ElektraError; + +typedef enum { ELEKTRA_ERROR_SEVERITY_FATAL = 0, ELEKTRA_ERROR_SEVERITY_ERROR, ELEKTRA_ERROR_SEVERITY_WARNING } ElektraErrorSeverity; + +typedef const char * ElektraErrorGroup; +typedef const char * ElektraErrorModule; + +ElektraErrorCode elektraErrorCode (ElektraError * error); +const char * elektraErrorDescription (ElektraError * error); +ElektraErrorSeverity elektraErrorSeverity (ElektraError * error); +ElektraErrorGroup elektraErrorGroup (ElektraError * error); +ElektraErrorModule elektraErrorModule (ElektraError * error); + +void elektraErrorReset (ElektraError ** error); + +#endif // ELEKTRA_ERROR_H diff --git a/src/include/elektra_error_codes.h b/src/include/elektra_error_codes.h new file mode 100644 index 00000000000..9be80bb60fc --- /dev/null +++ b/src/include/elektra_error_codes.h @@ -0,0 +1,18 @@ +/** + * @file + * + * @brief Elektra error codes. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#ifndef ELEKTRA_ERROR_CODES_H +#define ELEKTRA_ERROR_CODES_H + +#include "kdbtypes.h" + +// TODO Auto-generate an enum error type from the error specification file. + +typedef kdb_long_t ElektraErrorCode; + +#endif // ELEKTRA_ERROR_CODES_H diff --git a/src/include/elektra_error_private.h b/src/include/elektra_error_private.h new file mode 100644 index 00000000000..e665c7c671b --- /dev/null +++ b/src/include/elektra_error_private.h @@ -0,0 +1,27 @@ +/** + * @file + * + * @brief Elektra Error. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#ifndef ELEKTRA_ERROR_PRIVATE_H +#define ELEKTRA_ERROR_PRIVATE_H + +#include "kdb.h" + +struct _ElektraError +{ + ElektraErrorCode code; + const char * description; + ElektraErrorSeverity severity; + ElektraErrorGroup group; + ElektraErrorModule module; +}; + +ElektraError * elektraErrorCreate (ElektraErrorCode code, const char * description, ElektraErrorSeverity severity, ElektraErrorGroup group, + ElektraErrorModule module); +ElektraError * elektraErrorCreateFromKey (Key * key); + +#endif // ELEKTRA_ERROR_PRIVATE_H diff --git a/src/include/elektra_generic.h b/src/include/elektra_generic.h new file mode 100644 index 00000000000..5b3125c8fd9 --- /dev/null +++ b/src/include/elektra_generic.h @@ -0,0 +1,104 @@ +/** + * @file + * + * @brief Included by elektra.h and code generator. Used by the code generator to override the default generic getters/setters. Therefore it has deliberately not an include guard. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#undef elektraSet +#undef elektraSetArrayElement +#undef elektraGet +#undef elektraGetArrayElement + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param tag The codegenerated Tag to write to. + * @param value The new value. + * @param error Pass a reference to an ElektraError pointer. + */ +#define elektraSet(ELEKTRA, TAG, VALUE, ERROR) \ + _Generic((TAG), ELEKTRA_TAG_NAMES_GEN (ELEKTRA_GENERIC_SET_ENTRY) ELEKTRA_TAG_NAMES_EXCEPT_STRING (ELEKTRA_GENERIC_SET_ENTRY) \ + ELEKTRA_TAG (String) \ + : ELEKTRA_SET_BY_TAG (String)) (ELEKTRA, TAG, VALUE, ERROR) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param tag The codegenerated Tag to write to. + * @param value The new value. + * @param error Pass a reference to an ElektraError pointer. + */ +#define elektraSetEnum(ELEKTRA, TAG, VALUE, ERROR) \ + _Generic((TAG), ELEKTRA_TAG_NAMES_GEN (ELEKTRA_GENERIC_SET_ENTRY) ELEKTRA_TAG_NAMES_EXCEPT_STRING (ELEKTRA_GENERIC_SET_ENTRY) \ +char * : __elektraSetEnum \ +) (ELEKTRA, TAG, VALUE, ERROR) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param keynameOrTag The keyname (or a codegenerated Tag) to write to. The keyname is appended to the parent key. + * @param value The new value. + * @param error Pass a reference to an ElektraError pointer. + */ +#define elektraSetArrayElement(ELEKTRA, TAG, VALUE, INDEX, ERROR) \ + _Generic((TAG), ELEKTRA_TAG_NAMES_GEN (ELEKTRA_GENERIC_SET_ARRAY_ELEMENT_ENTRY) \ + ELEKTRA_TAG_NAMES_EXCEPT_STRING (ELEKTRA_GENERIC_SET_ARRAY_ELEMENT_ENTRY) ELEKTRA_TAG (String) \ + : ELEKTRA_SET_ARRAY_ELEMENT_BY_TAG (String)) (ELEKTRA, TAG, VALUE, INDEX, ERROR) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param keyName The keyname (or a codegenerated Tag) to look up. The keyname is appended to the parent key. + * @param value The new value. + * @param index The array index of the desired element, starting with 0. \ + * @return The value stored at the given key and index. + */ +#define elektraSetEnumArrayElement(ELEKTRA, TAG, VALUE, INDEX, ERROR) \ + _Generic((TAG), ELEKTRA_TAG_NAMES_GEN (ELEKTRA_GENERIC_SET_ARRAY_ELEMENT_ENTRY) \ +char * : __elektraSetEnumArrayElement \ +) (ELEKTRA, TAG, VALUE, INDEX, ERROR) + + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param name The keyname to look up. The keyname is appended to the parent key. + * @param index The array index of the desired element, starting with 0. + * @return The value stored at the given key and index. +*/ +#define elektraGet(ELEKTRA, TAG) \ + _Generic((TAG), ELEKTRA_TAG_NAMES_GEN (ELEKTRA_GENERIC_GET_ENTRY) ELEKTRA_TAG_NAMES_EXCEPT_STRING (ELEKTRA_GENERIC_GET_ENTRY) \ + ELEKTRA_TAG (String) \ + : ELEKTRA_GET_BY_TAG (String)) (ELEKTRA, TAG) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param name The keyname to look up. The keyname is appended to the parent key. + * @param index The array index of the desired element, starting with 0. + * @return The value stored at the given key and index. + */ +#define elektraGetEnum(ELEKTRA, TAG) \ + _Generic((TAG), ELEKTRA_TAG_NAMES_GEN (ELEKTRA_GENERIC_GET_ENTRY) ELEKTRA_TAG_NAMES_EXCEPT_STRING (ELEKTRA_GENERIC_GET_ENTRY) \ +char * : __elektraGetEnum \ +) (ELEKTRA, TAG) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param keyName The keyname (or a codegenerated Tag) to look up. The keyname is appended to the parent key. + * @param value The new value. + * @param index The array index of the desired element, starting with 0. \ + * @return The value stored at the given key and index. +*/ +#define elektraGetArrayElement(ELEKTRA, TAG, INDEX) \ + _Generic((TAG), ELEKTRA_TAG_NAMES_GEN (ELEKTRA_GENERIC_GET_ARRAY_ELEMENT_ENTRY) \ + ELEKTRA_TAG_NAMES_EXCEPT_STRING (ELEKTRA_GENERIC_GET_ARRAY_ELEMENT_ENTRY) ELEKTRA_TAG (String) \ + : ELEKTRA_GET_ARRAY_ELEMENT_BY_TAG (String)) (ELEKTRA, TAG, INDEX) + +/** + * @param elektra The elektra instance initialized with the parent key. + * @param keyName The keyname (or a codegenerated Tag) to look up. The keyname is appended to the parent key. + * @param value The new value. + * @param index The array index of the desired element, starting with 0. \ + * @return The value stored at the given key and index. + */ +#define elektraGetEnumArrayElement(ELEKTRA, TAG, INDEX) \ + _Generic((TAG), ELEKTRA_TAG_NAMES_GEN (ELEKTRA_GENERIC_GET_ARRAY_ELEMENT_ENTRY) \ +char * : __elektraGetEnumArrayElement \ +) (ELEKTRA, TAG, INDEX) diff --git a/src/include/elektra_private.h b/src/include/elektra_private.h new file mode 100644 index 00000000000..74be31ed4e6 --- /dev/null +++ b/src/include/elektra_private.h @@ -0,0 +1,22 @@ +/** + * @file + * + * @brief Private declarations. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#ifndef ELEKTRA_PRIVATE_H +#define ELEKTRA_PRIVATE_H + +#include "kdb.h" + +struct _Elektra +{ + KDB * kdb; + Key * parentKey; + KeySet * config; + Key * lookupKey; +}; + +#endif // ELEKTRA_PRIVATE_H diff --git a/src/include/kdbos.h b/src/include/kdbos.h index d02a34ed48b..05cdac46b64 100644 --- a/src/include/kdbos.h +++ b/src/include/kdbos.h @@ -191,7 +191,7 @@ typedef int elektraNamespace; #define KDB_PATH_SEPARATOR '/' /**@brief Escape symbol for special characters in the key name. - * + * * @see @link keyname here @endlink. * */ #define KDB_PATH_ESCAPE '\\' diff --git a/src/include/kdbplugin.h b/src/include/kdbplugin.h index affca2c6de9..ff3e8f9cf95 100644 --- a/src/include/kdbplugin.h +++ b/src/include/kdbplugin.h @@ -35,17 +35,17 @@ #define ELEKTRA_PLUGIN_FUNCTION3(module, variant, function) libelektra_##module##_##variant##_LTX_elektraPlugin##function #else /** - * @brief Declare a plugin's function name suitable for - * compilation variants (see doc/tutorials). - * - * It can be used in the same way as elektraPluginExport(). - * @see ELEKTRA_PLUGIN_EXPORT - * - * @ingroup plugin - * - * @param plugin the name of the plugin - * @param function which function it is (open, close, get, set, error) - */ + * @brief Declare a plugin's function name suitable for + * compilation variants (see doc/tutorials). + * + * It can be used in the same way as elektraPluginExport(). + * @see ELEKTRA_PLUGIN_EXPORT + * + * @ingroup plugin + * + * @param plugin the name of the plugin + * @param function which function it is (open, close, get, set, error) + */ #define ELEKTRA_PLUGIN_FUNCTION(module, function) libelektra_##module##_LTX_elektraPlugin##function #endif @@ -55,13 +55,13 @@ #define ELEKTRA_README3(module, variant) ELEKTRA_QUOTE (readme_##module##_##variant.c) #else /** - * @brief The filename for inclusion of the readme for - * compilation variants (see doc/tutorials). - * - * @ingroup plugin - * - * @param plugin the name of the plugin - */ + * @brief The filename for inclusion of the readme for + * compilation variants (see doc/tutorials). + * + * @ingroup plugin + * + * @param plugin the name of the plugin + */ #define ELEKTRA_README(module) ELEKTRA_README2 (module) #define ELEKTRA_README2(module) ELEKTRA_QUOTE (readme_##module.c) #endif diff --git a/src/libs/CMakeLists.txt b/src/libs/CMakeLists.txt index 6b6340c6ba9..7b901486d21 100644 --- a/src/libs/CMakeLists.txt +++ b/src/libs/CMakeLists.txt @@ -18,4 +18,6 @@ add_subdirectory (invoke) add_subdirectory (elektra) +add_subdirectory (highlevel) + generate_manpage (elektra-libs FILENAME ${CMAKE_CURRENT_SOURCE_DIR}/README.md SECTION 7) diff --git a/src/libs/elektra/internal.c b/src/libs/elektra/internal.c index 2f97e8e19a4..547b13853a6 100644 --- a/src/libs/elektra/internal.c +++ b/src/libs/elektra/internal.c @@ -672,7 +672,7 @@ char * elektraUnescapeKeyNamePart (const char * source, size_t size, char * dest * * May only need half the storage than the source string. * It is not safe to use the same string for source and dest. -**/ + **/ size_t elektraUnescapeKeyName (const char * source, char * dest) { const char * sp = source; diff --git a/src/libs/elektra/key.c b/src/libs/elektra/key.c index 3ed50a942b4..947000289cb 100644 --- a/src/libs/elektra/key.c +++ b/src/libs/elektra/key.c @@ -598,7 +598,7 @@ ssize_t keyDecRef (Key * key) * * You can even add the key to more KeySets: * -* @snippet keyNew.c Ref in multiple KeySets + * @snippet keyNew.c Ref in multiple KeySets * * If you increment only by one with keyIncRef() the same as said above * is valid: diff --git a/src/libs/elektra/keymeta.c b/src/libs/elektra/keymeta.c index b16b71d5572..02d5e1cd3f7 100644 --- a/src/libs/elektra/keymeta.c +++ b/src/libs/elektra/keymeta.c @@ -7,8 +7,8 @@ */ /*************************************************************************** - keymeta.c - Methods for Key manipulation - ------------------- + keymeta.c - Methods for Key manipulation + ------------------- begin : Fri Sep 26 2008 copyright : (C) 2008 by Markus Raab email : elektra@markus-raab.org @@ -182,7 +182,7 @@ int keyRewindMeta (Key * key) * * @see ksNext() for pedant in iterator interface of KeySet * @ingroup keymeta - **/ + **/ const Key * keyNextMeta (Key * key) { Key * ret; diff --git a/src/libs/elektra/keyvalue.c b/src/libs/elektra/keyvalue.c index c5e9e947b2d..c5772e9d5f9 100644 --- a/src/libs/elektra/keyvalue.c +++ b/src/libs/elektra/keyvalue.c @@ -59,7 +59,7 @@ */ -/******************************************* +/******************************************* * General value manipulation methods * *******************************************/ @@ -127,7 +127,7 @@ kdbGetByName(handle,ks,"system/sw/my",KDB_O_SORT|KDB_O_RECURSIVE); ksRewind(ks); while (current=ksNext(ks)) { size_t size=0; - + if (keyIsBin(current)) { size=keyGetValueSize(current); printf("Key %s has a value of size %d bytes. Value: \nComment: %s", diff --git a/src/libs/elektra/split.c b/src/libs/elektra/split.c index 965517d3ec3..932c1a305c3 100644 --- a/src/libs/elektra/split.c +++ b/src/libs/elektra/split.c @@ -50,7 +50,7 @@ * @return a fresh allocated split object * @ingroup split * @see splitDel() -**/ + **/ Split * splitNew (void) { Split * ret = elektraCalloc (sizeof (Split)); @@ -696,7 +696,7 @@ int splitMerge (Split * split, KeySet * dest) * @param split the split object to work with * @ingroup split * -**/ + **/ int splitSync (Split * split) { int needsSync = 0; diff --git a/src/libs/highlevel/CMakeLists.txt b/src/libs/highlevel/CMakeLists.txt new file mode 100644 index 00000000000..0155ac55e16 --- /dev/null +++ b/src/libs/highlevel/CMakeLists.txt @@ -0,0 +1,2 @@ +file (GLOB SOURCES *.c) +add_lib (highlevel SOURCES ${SOURCES} LINK_ELEKTRA elektra-core elektra-kdb elektra-ease) diff --git a/src/libs/highlevel/README.md b/src/libs/highlevel/README.md new file mode 100644 index 00000000000..49105b2d8aa --- /dev/null +++ b/src/libs/highlevel/README.md @@ -0,0 +1,215 @@ + +# High-Level API + +## Introduction + +The goal of the high-hevel API is to increase the usability of libelektra for developers who want to integrate Elektra into their applications. Projects usually do not want to use low-level APIs. +`KDB` and `KeySet` are useful for plugins and to implement APIs but not to be directly used in applications. +The high-level API should be extremely easy to get started with and at the same time it should be hard to use it in a wrong way. +This tutorial gives an introduction for developers who want to elektrify their application using the high-level API. + +## Setup + +First you have to add `elektra-highlevel` to the linked libraries of your application. Note that your need C11 for the high-level API. To be able to use it in your source file, just include the main header with `#include ` at the top of your file. + +## Core Concepts + +### Struct `Elektra` +`Elektra` is the handle you use to access the underlying KDB (hierchical key database) that stores the configuration key-value pairs. All key-value read and write operations expect this handle to be passed as in as a parameter. To create the handle, you simply write: + +```c +ElektraError * error = NULL; +Elektra * elektra = elektraOpen ("/sw/org/myapp/#0/current", NULL, &error); +``` + +Please replace `"/sw/org/myapp/#0/current"` with an appropriate value for your application (see [Namespaces](/doc/tutorials/namespaces.md) for more information). + +The passed in `ElektraError` can be used to check for initialization errors. You can detect initialization errors by comparing it to NULL after calling `elektraOpen`: + +```c +if (error != NULL) +{ + // An error occured +} +``` + +In order to give Elektra the chance to clean up its all allocated ressources, you have to close your instance, when you are done using it, by calling: + +```c +elektraClose (elektra); +``` + +Notice that Elektra is is only thread-safe when you use a handle per thread or protect your handle. If you have mutliple threads accessing key-values, create a separate handle for each thread to avoid concurrency issues. + +### Struct `ElektraError` +The library is designed to hide as many problems a developer can encounter when usign KDB directly. However it is not possible to hide all those issues. As with every library, things can go wrong and there needs to be a way react to errors once they have occurred at runtime. Therefore the high-level API introduces a simplified struct called `ElektraError`, which encapsulates all information neccessary for the developer to handle runtime-errors appropriately in the application. + +Functions that can produce errors accept an ElektraError pointer as parameter, for example: + +```c +Elektra * elektraOpen (const char * application, KeySet * defaults, ElektraError ** error); +``` + +You can use the parameter `defaults` to pass a KDB `KeySet` containing `Key`s with default values to the elektra instance. See [Code Generator](#code-generator) for more information on that. + +In most cases you'll want to set the error variable to NULL before passing it to the function. You can do this either by declaring and initializing a new variable with `ElektraError * error = NULL` or by reusing an already existing error variable by resetting it with `elektraErrorReset (&error)`. + +Notice, that you should always check if an error occurred by comparing it to NULL after the function call. + +If an error happened, it is often useful to show an error message to the user. A description what went wrong is provided in the ElektraError struct and can be accessed by `elektraErrorDescription (error)`. A complete list of the provided accessors for error-details can be found in [elektra_error.h](/src/include/elektra_error.h). + +To avoid leakage of memory, you have to call `elektraErrorReset (&error)` a soon as you are finished resolving the error: + +```c +ElektraError * error = NULL; + +// Call a function and pass the error variable as an argument. +// ... + +if (error != NULL) +{ + + // An error occured, do something about it. + // ... + + elektraErrorReset (&error); +} +``` + +## Reading and writing values + +### Key names +When using `KDB` and `KeySet` directly you would have to specify the whole key name to access a value. In the high-level API you do not have to do this everytime you access a value. Instead, you pass a parent key to `elektraOpen` and use getters and setters which get passed in only the part below that key in the KDB. For example, if you call `elektraOpen` with `"/sw/org/myapp/#0/current"`, you can access your applications configuration value for the key `"/sw/org/myapp/#0/current/message"` with the provided getters and setters by passing them only `"message"` as the name for the configuration value. + +### Read values from the KDB +A typical application will want to read some configuration values at start. This should be made as easy as possibible for the developer. Reading configuration data in most cases is not part of the business logic of the application and therefore should not "pollute" the applications source code with cumbersome setup and file-parsing code. This is exactly where Elektra comes in handy, because you can leave all the configuration file handling and parsing to the underlying layers of Elektra and just use the high-level API to access the desired data. Reading values from KDB can be done with elektra-getter functions that follow a simple naming scheme: + +`elektraGet` + the type of the value you want to read. + +For example, you can get the value for the keyname "message" like this: + +```c +Elektra * elektra = elektraOpen ("/sw/org/myapp/#0/current", NULL, NULL); +const char * message = elektraGetString (elektra, "message"); +elektraClose (elektra); +``` + +Sometimes you'll want to access arrays as well. You can access single elements of an array using the provided array-getters following again a simple naming scheme: + +`elektraGet` + the type of the value you want to read + `ArrayElement`. + +For example, you can get the third value for the array "message" like this: + +```c +Elektra * elektra = elektraOpen ("/sw/org/myapp/#0/current", NULL, NULL); +const char * message = elektraGetStringArrayElement (elektra, "message", 3); +elektraClose (elektra); +``` + +To get the size of the array you would like to access you can use the function `elektraArraySize`: + +```c +Elektra * elektra = elektraOpen ("/sw/org/myapp/#0/current", NULL, NULL); +size_t arraySize = elektraArraySize (elektra, "message"); +elektraClose (elektra); +``` + +For some background information on arrays in Elektra see the [Application Integration](/doc/tutorials/application-integration.md) document. + +Notice that both the getters for primitive types and the getters for array types do not accept error parameters. The library relies on that you are running a correct Elektra setup. If the configuration is well specified, no runtime errors can occur when reading a value. Therefore the getters do not accept an error variable as argument. If there is however a severe internal error, or you try to access a key which you have not specified correctly, then the library will call `exit(EXIT_FAILURE)` to prevent data inconsistencies or exceptions further down in your application. + +You can find the complete list of the available functions for all supported value types in [elektra.h](/src/include/elektra.h) + +### Writing values to the KDB + +Sometimes, after having read a value from the KDB, you will want to write back a modified value. As descibed in [Read values from the KDB](#read-values-from-the-kdb) we follow a naming scheme for getters. The high-level API provides setters folling an analogous naming scheme as well. For example, to write back a modified "message", you can call `elektraSetString`: + +```c +Elektra * elektra = elektraOpen ("/sw/org/myapp/#0/current", NULL, NULL); +elektraSetString (elektra, "message", "This is the new message", NULL); +elektraClose (elektra); +``` + +The counterpart for array-gettes again follows the same naming scheme: + +```c +Elektra * elektra = elektraOpen ("/sw/org/myapp/#0/current", NULL, NULL); +elektraSetStringArrayElement (elektra, "message", "This is the third new message", NULL); +elektraClose (elektra); +``` + +Be sure not to access indexes outside of the arrays bounds. The same rules a described in [Read values from the KDB](#read-values-from-the-kdb) apply here, meaning, that you are responsible for providing a complete and correct specification (see [Application Integration](/doc/tutorials/application-integration.md)). If you try to access a key that you have not specified, the library will call `exit(EXIT_FAILURE)`. + +## Example + +```c +#include +#include + +int main () +{ + ElektraError * error = NULL; + Elektra * elektra = elektraOpen ("/sw/org/myapp/#0/current", NULL, &error); + + if (error != NULL) + { + printf ("Sorry, there seems to be an error with your Elektra setup: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + + printf ("Will exit now...\n"); + exit (EXIT_FAILURE); + } + + const char * message = elektraGetString (elektra, "message"); + + printf ("%s", message); + + elektraClose (elektra); + + return 0; +} +``` + +## Code Generator + +The high-level API is backed by a code generator you can use to generate constants for keynames and a defaults `KeySet` to pass to elektraOpen out of a specification file you provide. Use `kdb gen specification.ini elektra_gen.h -o elektra_gen.h` to generate a elektra_gen.h file and include it in your source file with `#include "elektra_gen.h"`. Read [Code Generation](/src/tools/gen/README.md) for more information on this topic. + +After you have generated the file, you can use the constants prefixed with ELEKTRA_TAG_ as keynames in the getters and setters described in [Read values from the KDB](#read-values-from-the-kdb). Additionally the API provides two alternative functions to use solely with the code generated keynames: `elektraSet` and `elektraGet`. + +The code generator also generates a defaults `KeySet` for you containing the values you have specified as defaults for each key in your specification. It is accessible by the name `ELEKTRA_DEFAULTS` and can be passed as argument for the parameter `defaults` in elektraOpen. + +Here is an example of how this looks like in code: + +```c +#include +#include +#include "elektra_gen.h" + +int main () +{ + ElektraError * error = NULL; + Elektra * elektra = elektraOpen ("/sw/org/myapp/#0/current", ELEKTRA_DEFAULTS, &error); + + if (error != NULL) + { + printf ("Sorry, there seems to be an error with your Elektra setup: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + + printf ("Will exit now...\n"); + exit (EXIT_FAILURE); + } + + // You can either get the message via elektraGetString as you would do it with keynames passed as strings. + const char * message = elektraGetString (elektra, ELEKTRA_TAG_MESSAGE); + + // Alternatively you can use the generic elektraGet method with ELEKTRA_TAG_MESSAGE. + const char * message_ = elektraGet (elektra, ELEKTRA_TAG_MESSAGE); + + printf ("%s", message); + + elektraClose (elektra); + + return 0; +} +``` + diff --git a/src/libs/highlevel/elektra.c b/src/libs/highlevel/elektra.c new file mode 100644 index 00000000000..ec0fc1219c0 --- /dev/null +++ b/src/libs/highlevel/elektra.c @@ -0,0 +1,268 @@ +/** + * @file + * + * @brief Elektra High Level API. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#include "elektra.h" +#include "elektra_conversion.h" +#include "elektra_error_private.h" +#include "elektra_private.h" +#include "kdblogger.h" +#include "kdbprivate.h" +#include + +#include "stdio.h" + +KDBType KDB_TYPE_STRING = "string"; +KDBType KDB_TYPE_BOOLEAN = "boolean"; +KDBType KDB_TYPE_CHAR = "char"; +KDBType KDB_TYPE_OCTET = "octet"; +KDBType KDB_TYPE_SHORT = "short"; +KDBType KDB_TYPE_UNSIGNED_SHORT = "unsigned_short"; +KDBType KDB_TYPE_LONG = "long"; +KDBType KDB_TYPE_UNSIGNED_LONG = "unsigned_long"; +KDBType KDB_TYPE_LONG_LONG = "long_long"; +KDBType KDB_TYPE_UNSIGNED_LONG_LONG = "unsigned_long_long"; +KDBType KDB_TYPE_FLOAT = "float"; +KDBType KDB_TYPE_LONG_DOUBLE = "long_double"; +KDBType KDB_TYPE_DOUBLE = "double"; +KDBType KDB_TYPE_ENUM = "enum"; + +static Key * generateLookupKey (Elektra * elektra, const char * name); + +/** + * \defgroup highlevel High-level API + * @{ + */ + +ELEKTRA_DEFINITIONS (const char *, String, KDB_TYPE_STRING, KDB_STRING_TO_STRING, KDB_STRING_TO_STRING) +ELEKTRA_DEFINITIONS (kdb_boolean_t, Boolean, KDB_TYPE_BOOLEAN, KDB_BOOLEAN_TO_STRING, KDB_STRING_TO_BOOLEAN) +ELEKTRA_DEFINITIONS (kdb_char_t, Char, KDB_TYPE_CHAR, KDB_CHAR_TO_STRING, KDB_STRING_TO_CHAR) +ELEKTRA_DEFINITIONS (kdb_octet_t, Octet, KDB_TYPE_OCTET, KDB_OCTET_TO_STRING, KDB_STRING_TO_OCTET) +ELEKTRA_DEFINITIONS (kdb_short_t, Short, KDB_TYPE_SHORT, KDB_SHORT_TO_STRING, KDB_STRING_TO_SHORT) +ELEKTRA_DEFINITIONS (kdb_unsigned_short_t, UnsignedShort, KDB_TYPE_UNSIGNED_SHORT, KDB_UNSIGNED_SHORT_TO_STRING, + KDB_STRING_TO_UNSIGNED_SHORT) +ELEKTRA_DEFINITIONS (kdb_long_t, Long, KDB_TYPE_LONG, KDB_LONG_TO_STRING, KDB_STRING_TO_LONG) +ELEKTRA_DEFINITIONS (kdb_unsigned_long_t, UnsignedLong, KDB_TYPE_UNSIGNED_LONG, KDB_UNSIGNED_LONG_TO_STRING, KDB_STRING_TO_UNSIGNED_LONG) +ELEKTRA_DEFINITIONS (kdb_long_long_t, LongLong, KDB_TYPE_LONG_LONG, KDB_LONG_LONG_TO_STRING, KDB_STRING_TO_LONG_LONG) +ELEKTRA_DEFINITIONS (kdb_unsigned_long_long_t, UnsignedLongLong, KDB_TYPE_UNSIGNED_LONG_LONG, KDB_UNSIGNED_LONG_LONG_TO_STRING, + KDB_STRING_TO_UNSIGNED_LONG_LONG) +ELEKTRA_DEFINITIONS (kdb_float_t, Float, KDB_TYPE_FLOAT, KDB_FLOAT_TO_STRING, KDB_STRING_TO_FLOAT) +ELEKTRA_DEFINITIONS (kdb_double_t, Double, KDB_TYPE_DOUBLE, KDB_DOUBLE_TO_STRING, KDB_STRING_TO_DOUBLE) +ELEKTRA_DEFINITIONS (kdb_long_double_t, LongDouble, KDB_TYPE_LONG_DOUBLE, KDB_LONG_DOUBLE_TO_STRING, KDB_STRING_TO_LONG_DOUBLE) + +/** + * Initializes a new Elektra instance. + * @param application The parent key for your application. + * @param defaults A KeySet containing default values. Passing NULL means "no default values". + * @return An Elektra instance initialized with the application. + */ +Elektra * elektraOpen (const char * application, KeySet * defaults, ElektraError ** error) +{ + Key * const parentKey = keyNew (application, KEY_END); + KDB * const kdb = kdbOpen (parentKey); + + if (kdb == NULL) + { + *error = elektraErrorCreateFromKey (parentKey); + return NULL; + } + + KeySet * const config = ksNew (0, KS_END); + if (defaults != NULL) + { + ksRewind (defaults); + for (Key * key = ksNext (defaults); key != NULL; key = ksNext (defaults)) + { + Key * const dup = keyDup (key); + const char * name = keyName (key); + keySetName (dup, keyName (parentKey)); + keyAddName (dup, name); + ksAppendKey (config, dup); + } + } + + const int kdbGetResult = kdbGet (kdb, config, parentKey); + + if (kdbGetResult == -1) + { + *error = elektraErrorCreateFromKey (parentKey); + return NULL; + } + + Elektra * const elektra = elektraCalloc (sizeof (struct _Elektra)); + elektra->kdb = kdb; + elektra->parentKey = parentKey; + elektra->config = config; + elektra->lookupKey = keyNew (NULL, KEY_END); + + return elektra; +} + +/** + * Releases all ressources used by the given elektra instance. The elektra instance must not be used anymore after calling this. + * @param elektra An Elektra instance. + */ +void elektraClose (Elektra * elektra) +{ + kdbClose (elektra->kdb, elektra->parentKey); + keyDel (elektra->parentKey); + ksDel (elektra->config); + keyDel (elektra->lookupKey); + + elektraFree (elektra); +} + +size_t elektraArraySize (Elektra * elektra, const char * name) +{ + Key * const key = generateLookupKey (elektra, name); + + KeySet * arrayKeys = elektraArrayGet (key, elektra->config); + size_t size = (size_t)ksGetSize (arrayKeys); + ksDel (arrayKeys); + + return size; +} + +/** + * @} + */ + +// Private functions + +static void saveKey (Elektra * elektra, Key * key, ElektraError ** error) +{ + int ret = 0; + do + { + ksAppendKey (elektra->config, key); + + ret = kdbSet (elektra->kdb, elektra->config, elektra->parentKey); + if (ret == -1) + { + ElektraError * kdbSetError = elektraErrorCreateFromKey (elektra->parentKey); + if (elektraErrorCode (kdbSetError) != 30) // ELEKTRA_ERROR_CONFLICT = 30 + { + *error = kdbSetError; + return; + } + + Key * problemKey = ksCurrent (elektra->config); + if (problemKey != NULL) + { + ELEKTRA_LOG_DEBUG ("problemKey: %s\n", keyName (problemKey)); + } + + key = keyDup (key); + kdbGet (elektra->kdb, elektra->config, elektra->parentKey); + } + } while (ret == -1); +} + +static void checkType (Key * key, KDBType type) +{ + if (strcmp (keyString (keyGetMeta (key, "type")), type)) + { + ELEKTRA_LOG_DEBUG ("Wrong type. Should be: %s\n", type); + exit (EXIT_FAILURE); + } +} + +static Key * generateLookupKey (Elektra * elektra, const char * name) +{ + Key * const lookupKey = elektra->lookupKey; + + keySetName (lookupKey, keyName (elektra->parentKey)); + keyAddName (lookupKey, name); + + return lookupKey; +} + +static Key * generateArrayLookupKey (Elektra * elektra, const char * name, size_t index) +{ + Key * const lookupKey = generateLookupKey (elektra, name); + + char arrayPart[ELEKTRA_MAX_ARRAY_SIZE]; + elektraWriteArrayNumber (arrayPart, index); + keyAddName (lookupKey, arrayPart); + + return lookupKey; +} + +// Set values + +static void setKeyValue (Elektra * elektra, Key * key, KDBType type, const char * value, ElektraError ** error) +{ + keySetMeta (key, "type", type); + keySetString (key, value); + + saveKey (elektra, key, error); +} + +void elektraSetValue (Elektra * elektra, const char * name, const char * value, KDBType type, ElektraError ** error) +{ + Key * const key = keyDup (generateLookupKey (elektra, name)); + setKeyValue (elektra, key, type, value, error); +} + +void __elektraSetEnum (Elektra * elektra, char * name, int value, ElektraError ** error) +{ + Key * const key = keyDup (generateLookupKey (elektra, name)); + setKeyValue (elektra, key, "enum", KDB_ENUM_TO_STRING (value), error); +} + +void elektraSetArrayElementValue (Elektra * elektra, const char * name, size_t index, const char * value, KDBType type, + ElektraError ** error) +{ + Key * const key = keyDup (generateArrayLookupKey (elektra, name, index)); + setKeyValue (elektra, key, type, value, error); +} + +void __elektraSetEnumArrayElement (Elektra * elektra, char * name, size_t index, int value, ElektraError ** error) +{ + Key * const key = keyDup (generateArrayLookupKey (elektra, name, index)); + setKeyValue (elektra, key, "enum", KDB_ENUM_TO_STRING (value), error); +} + +// Get values + +static const char * getKeyValue (Elektra * elektra, Key * key, KDBType type) +{ + Key * const resultKey = ksLookup (elektra->config, key, 0); + if (resultKey == NULL) + { + ELEKTRA_LOG_DEBUG ("Key not found: %s\n", keyName (key)); + exit (EXIT_FAILURE); + } + + checkType (resultKey, type); + + return keyString (resultKey); +} + +const char * elektraGetValue (Elektra * elektra, const char * name, KDBType type) +{ + Key * const key = generateLookupKey (elektra, name); + + return getKeyValue (elektra, key, type); +} + +int __elektraGetEnum (Elektra * elektra, char * keyName) +{ + return KDB_STRING_TO_ENUM (elektraGetValue (elektra, keyName, KDB_TYPE_ENUM)); +} + +const char * elektraGetArrayElementValue (Elektra * elektra, const char * name, size_t index, KDBType type) +{ + Key * const key = generateArrayLookupKey (elektra, name, index); + + return getKeyValue (elektra, key, type); +} + +int __elektraGetEnumArrayElement (Elektra * elektra, char * keyName, int index) +{ + return KDB_STRING_TO_ENUM (elektraGetArrayElementValue (elektra, keyName, index, KDB_TYPE_ENUM)); +} diff --git a/src/libs/highlevel/elektra_error.c b/src/libs/highlevel/elektra_error.c new file mode 100644 index 00000000000..b874a02933b --- /dev/null +++ b/src/libs/highlevel/elektra_error.c @@ -0,0 +1,123 @@ +/** + * @file + * + * @brief Elektra error codes. + * + * @copyright BSD License (see doc/LICENSE.md or http://www.libelektra.org) + */ + +#include "elektra_error.h" +#include "elektra_conversion.h" +#include "elektra_error_private.h" +#include "kdbhelper.h" +#include "kdbprivate.h" +#include + +// elektra_error_private.h + +ElektraError * elektraErrorCreate (ElektraErrorCode code, const char * description, ElektraErrorSeverity severity, ElektraErrorGroup group, + ElektraErrorModule module) +{ + ElektraError * const error = elektraCalloc (sizeof (struct _ElektraError)); + error->code = code; + error->description = description; + error->severity = severity; + error->group = group; + error->module = module; + + return error; +} + +ElektraError * elektraErrorCreateFromKey (Key * key) +{ + const Key * metaKey = keyGetMeta (key, "error"); + + if (NULL == metaKey) + { + return NULL; + } + + ElektraErrorCode code = KDB_STRING_TO_LONG (keyString (keyGetMeta (key, "error/number"))); + const char * description = keyString (keyGetMeta (key, "error/description")); + + const char * severityString = keyString (keyGetMeta (key, "error/severity")); + ElektraErrorSeverity severity = ELEKTRA_ERROR_SEVERITY_FATAL; // Default is FATAL. + if (!elektraStrCmp (severityString, "error")) + { + severity = ELEKTRA_ERROR_SEVERITY_ERROR; + } + else if (!elektraStrCmp (severityString, "warning")) + { + severity = ELEKTRA_ERROR_SEVERITY_WARNING; + } + + ElektraErrorGroup group = keyString (keyGetMeta (key, "error/ingroup")); + ElektraErrorModule module = keyString (keyGetMeta (key, "error/module")); + + return elektraErrorCreate (code, description, severity, group, module); +} + +// elektra_error.h + +/** + * \addtogroup highlevel High-level API + * @{ + */ + +/** + * @return Code of the given error. + */ +ElektraErrorCode elektraErrorCode (ElektraError * error) +{ + return error->code; +} + +/** + * @return Description for the given error. + */ +const char * elektraErrorDescription (ElektraError * error) +{ + return error->description; +} + +/** + * @return Severity of the given error. + */ +ElektraErrorSeverity elektraErrorSeverity (ElektraError * error) +{ + return error->severity; +} + +/** + * @return Group of the given error. + */ +ElektraErrorGroup elektraErrorGroup (ElektraError * error) +{ + return error->group; +} + +/** + * @return Module of the given error. + */ +ElektraErrorModule elektraErrorModule (ElektraError * error) +{ + return error->module; +} + +/** + * @brief Frees memory used by the error and sets the referenced error variable to NULL. + */ +void elektraErrorReset (ElektraError ** error) +{ + if (*error == NULL) + { + return; + } + + elektraFree (*error); + *error = NULL; +} + +/** + * @} + */ diff --git a/src/libs/tools/include/plugindatabase.hpp b/src/libs/tools/include/plugindatabase.hpp index 6b14137a93b..d6699dabdf9 100644 --- a/src/libs/tools/include/plugindatabase.hpp +++ b/src/libs/tools/include/plugindatabase.hpp @@ -180,20 +180,20 @@ class PluginVariantDatabase : public ModulesPluginDatabase public: /** * @brief constructor that takes a configuration keyset for plugins - * + * * takes the list of plugins provided by the ModulesPluginDatabase and * removes all plugins that are disabled in the system config which was * given to the constructor. - * + * * example: removes the `simpleini` plugin if an entry like - * + * * system/elektra/plugins/simpleini/disable = 1 - * + * * exists in the keyset handed to the constructor - * + * * @note the constructor should be called with a keyset containing * the keys for system/elektra/plugins - * + * * @param conf keyset containing keys from system/elektra/plugins */ explicit PluginVariantDatabase (const KeySet & conf); @@ -203,15 +203,15 @@ class PluginVariantDatabase : public ModulesPluginDatabase /** * @brief returns a list of plugin variants for the plugin - * + * * takes the genconf function provided by plugins to generate variants. * variants can be disabled through the system configuration handed to * the constructor of the class. - * + * * example: ignores a variant `spacesep` delivered by genconf if an entry like - * + * * system/elektra/plugins/simpleini/variants/spacesep/disable = 1 - * + * * exists in the keyset handed to the constructor * * @note if no plugin variant could be found, an empty vector will be returned. @@ -225,17 +225,17 @@ class PluginVariantDatabase : public ModulesPluginDatabase private: /** * @brief returns a list of plugin variants created from the system config - * + * * considered are keys below system/elektra/plugins//variants - * + * * @note variants listed in @p genconfToIgnore are not added to the result. * it is expected that they were added at another point already * (e.g. explicit override check). - * + * * @param whichplugin is the plugin for which we want all variants * @param sysconf is a keyset containing the system config for system/elektra/plugins * @param genconfToIgnore is a keyset containing variants to ignore from the sysconf - * + * * @return a vector of pluginspecs with variant configurations */ std::vector getPluginVariantsFromSysconf (PluginSpec const & whichplugin, KeySet const & sysconf, @@ -243,18 +243,18 @@ class PluginVariantDatabase : public ModulesPluginDatabase /** * @brief returns a list of plugin variants created from the genconf config - * + * * does take a keyset with config from the `genconf` plugin function, but also * an additional @p sysconf keyset with config from system/elektra/plugins to * ensure overrides and disabled variants. - * + * * the function does also add all variants from @p sysconf that were not mentioned * in @p genconf yet. - * + * * @param whichplugin is the plugin for which we want all variants * @param genconf is a keyset containing the genconf config from the plugin * @param sysconf is a keyset containing the system config for system/elektra/plugins - * + * * @return a vector of pluginspecs with variant configurations */ std::vector getPluginVariantsFromGenconf (PluginSpec const & whichplugin, KeySet const & genconf, @@ -262,45 +262,45 @@ class PluginVariantDatabase : public ModulesPluginDatabase /** * @brief builds a sysconf key from several inputs - * + * * builds a key like: - * + * * system/elektra/plugin//variants// - * + * * @note the function does not add a value and it does not lookup the key in any * keyset, it just creates the key by adding every part as basename. - * + * * @param whichplugin is the plugin for which we want a key * @param variant is the plugin variant for which we want a key * @param attr is the attribute of a variant for which we want a key, e.g. info or config - * + * * @return a newly created key matching the inputs which can be used for lookups for example */ Key buildVariantSysconfKey (PluginSpec const & whichplugin, std::string const & variant, const std::string attr) const; /** * @brief adds all keys of a keyset below a certain key to another keyset, rebased - * + * * lets take the input keyset (@p conf): - * + * * system/elektra/plugins/simpleini/variants/spacesep * system/elektra/plugins/simpleini/variants/spacesep/config * system/elektra/plugins/simpleini/variants/spacesep/config/format = % % * system/elektra/plugins/simpleini/variants/spacesep/config/ignorewhitespace = 1 - * + * * and the input key (@p below): - * + * * system/elektra/plugins/simpleini/variants/spacesep/config - * + * * and the new base key (@p newbase): - * + * * system/ - * + * * then we get the following keys in the output keyset (@p targetconf): - * + * * system/format = % % * system/ignorewhitespace = 1 - * + * * @param below the parent key for everything we want to add to the target keyset * @param conf the keyset of which we want to add the keys to the target keyset * @param newbase the new base key used in the rebasing process diff --git a/src/libs/tools/src/backendbuilder.cpp b/src/libs/tools/src/backendbuilder.cpp index 90ea12088a9..b6ad3441654 100644 --- a/src/libs/tools/src/backendbuilder.cpp +++ b/src/libs/tools/src/backendbuilder.cpp @@ -404,9 +404,9 @@ void BackendBuilder::recommendPlugin (std::string name) * @pre Needs to be a unique new name (use refname if you want to add the same module multiple times) * * Will automatically resolve virtual plugins to actual plugins. - * - * Also calls the checkconf function if provided by the plugin. The checkconf function has the - * following signature: int checkconf (Key * errorKey, KeySet * config) and allows a plugin to + * + * Also calls the checkconf function if provided by the plugin. The checkconf function has the + * following signature: int checkconf (Key * errorKey, KeySet * config) and allows a plugin to * verify its configuration at mount time. * * @see resolveNeeds() diff --git a/src/libs/tools/src/backends.cpp b/src/libs/tools/src/backends.cpp index 24ccbbf78e3..a7475a01588 100644 --- a/src/libs/tools/src/backends.cpp +++ b/src/libs/tools/src/backends.cpp @@ -113,7 +113,7 @@ BackendInfo Backends::findBackend (std::string const & mountPath, KeySet mountCo /** * @brief Unmount a backend by given mountPath * - * @param mountPath the given mountpoint + * @param mountPath the given mountpoint * * Uses findBackend() to locate the backend. * diff --git a/src/libs/tools/src/plugins.cpp b/src/libs/tools/src/plugins.cpp index e74c7dcd9d6..00bad882e27 100644 --- a/src/libs/tools/src/plugins.cpp +++ b/src/libs/tools/src/plugins.cpp @@ -214,7 +214,7 @@ void Plugins::checkResolver (Plugin & plugin) /** Check ordering of plugins. - */ + */ void Plugins::checkOrdering (Plugin & plugin) { std::string order; @@ -234,7 +234,7 @@ void Plugins::checkOrdering (Plugin & plugin) } /** Check conflicts of plugins. - */ + */ void Plugins::checkConflicts (Plugin & plugin) { { diff --git a/src/plugins/base64/base64_functions.c b/src/plugins/base64/base64_functions.c index 1f494fad92f..debb0f4105f 100644 --- a/src/plugins/base64/base64_functions.c +++ b/src/plugins/base64/base64_functions.c @@ -11,7 +11,7 @@ static const char padding = '='; * @param input holds the data to be encoded * @param inputLength tells how many bytes the input buffer is holding. * @returns an allocated string holding the Base64 encoded input data or NULL if the string can not be allocated. Must be freed by the - caller. + * caller. */ char * PLUGIN_FUNCTION (base64Encode) (const kdb_octet_t * input, const size_t inputLength) #ifdef __llvm__ @@ -92,7 +92,7 @@ static kdb_octet_t getBase64Index (const char character, int * errorFlag) * @brief decodes Base64 encoded data. * @param input holds the Base64 encoded data string * @param output will be set to an allocated buffer holding the decoded data or NULL if the allocation failed. Must be freed by the caller - on success. + * on success. * @param outputLength will be set to the amount of decoded bytes. * @retval 1 on success * @retval -1 if the provided string has not been encoded with Base64 diff --git a/src/plugins/ccode/ccode.c b/src/plugins/ccode/ccode.c index b52ce8984b3..8e54614876a 100644 --- a/src/plugins/ccode/ccode.c +++ b/src/plugins/ccode/ccode.c @@ -16,9 +16,9 @@ #include /** - * Gives the integer number 0-15 to a corresponding - * hex character '0'-'9', 'a'-'f' or 'A'-'F'. - */ + * Gives the integer number 0-15 to a corresponding + * hex character '0'-'9', 'a'-'f' or 'A'-'F'. + */ static inline int elektraHexcodeConvFromHex (char c) { if (c == '0') @@ -146,11 +146,11 @@ int elektraCcodeClose (Plugin * handle, Key * key ELEKTRA_UNUSED) } /** Reads the value of the key and decodes all escaping - * codes into the buffer. - * @pre the buffer needs to be as large as value's size. - * @param cur the key holding the value to decode - * @param buf the buffer to write to - */ + * codes into the buffer. + * @pre the buffer needs to be as large as value's size. + * @param cur the key holding the value to decode + * @param buf the buffer to write to + */ void elektraCcodeDecode (Key * cur, CCodeData * d) { size_t valsize = keyGetValueSize (cur); @@ -230,12 +230,12 @@ int elektraCcodeGet (Plugin * handle, KeySet * returned, Key * parentKey) /** Reads the value of the key and encodes it in - * c-style in the buffer. - * - * @param cur the key which value is to encode - * @param buf the buffer - * @pre the buffer needs to have twice as much space as the value's size - */ + * c-style in the buffer. + * + * @param cur the key which value is to encode + * @param buf the buffer + * @pre the buffer needs to have twice as much space as the value's size + */ void elektraCcodeEncode (Key * cur, CCodeData * d) { size_t valsize = keyGetValueSize (cur); diff --git a/src/plugins/crypto/gpg.c b/src/plugins/crypto/gpg.c index 998faff8892..b5a19686d90 100644 --- a/src/plugins/crypto/gpg.c +++ b/src/plugins/crypto/gpg.c @@ -128,7 +128,8 @@ static char * genGpgCandidate (Key * errorKey, char * dir, const char * file) * @brief lookup binary file bin in the PATH environment variable. * @param errorKey holds an error description in case of failure. * @param bin the binary file to look for - * @param result holds an allocated string containing the full path to the binary file or NULL in case of error. Must be freed by the caller. + * @param result holds an allocated string containing the full path to the binary file or NULL in case of error. Must be freed by the + * caller. * @retval -1 if an error occurred. See errorKey for a description. * @retval 0 if the binary could not be found within PATH. * @retval 1 if the binary was found and the full path was stored in result. diff --git a/src/plugins/crypto/helper.c b/src/plugins/crypto/helper.c index a678d209114..7be5195f6c7 100644 --- a/src/plugins/crypto/helper.c +++ b/src/plugins/crypto/helper.c @@ -22,7 +22,7 @@ * @param saltLen is set to the length of the salt. Ignored if NULL is provided. * @retval 1 on success * @retval -1 on error. errorKey holds a description. -*/ + */ int CRYPTO_PLUGIN_FUNCTION (getSaltFromMetakey) (Key * errorKey, Key * k, kdb_octet_t ** salt, kdb_unsigned_long_t * saltLen) { size_t saltLenInternal = 0; @@ -57,7 +57,7 @@ int CRYPTO_PLUGIN_FUNCTION (getSaltFromMetakey) (Key * errorKey, Key * k, kdb_oc * @param saltLen is set to the length of the salt. Ignored if NULL is provided. * @retval 1 on success * @retval -1 on error. errorKey holds a description. -*/ + */ int CRYPTO_PLUGIN_FUNCTION (getSaltFromPayload) (Key * errorKey, Key * k, kdb_octet_t ** salt, kdb_unsigned_long_t * saltLen) { static const size_t headerLen = sizeof (kdb_unsigned_long_t); @@ -96,11 +96,11 @@ int CRYPTO_PLUGIN_FUNCTION (getSaltFromPayload) (Key * errorKey, Key * k, kdb_oc } /** -* @brief read the encrypted password form the configuration and decrypt it. -* @param errorKey holds an error description in case of failure. -* @param config holds the plugin configuration. -* @returns the decrypted master password as (Elektra) Key or NULL in case of error. Must be freed by the caller. -*/ + * @brief read the encrypted password form the configuration and decrypt it. + * @param errorKey holds an error description in case of failure. + * @param config holds the plugin configuration. + * @returns the decrypted master password as (Elektra) Key or NULL in case of error. Must be freed by the caller. + */ Key * CRYPTO_PLUGIN_FUNCTION (getMasterPassword) (Key * errorKey, KeySet * config) { Key * master = ksLookupByName (config, ELEKTRA_CRYPTO_PARAM_MASTER_PASSWORD, 0); diff --git a/src/plugins/crypto/openssl_operations.c b/src/plugins/crypto/openssl_operations.c index 8058b2e9bdc..8575490ed63 100644 --- a/src/plugins/crypto/openssl_operations.c +++ b/src/plugins/crypto/openssl_operations.c @@ -508,7 +508,7 @@ int elektraCryptoOpenSSLDecrypt (elektraCryptoHandle * handle, Key * k, Key * er * @param errorKey holds an error description in case of failure. * @param length the number of random bytes to be generated. * @returns allocated buffer holding a hex-encoded random string or NULL in case of error. Must be freed by the caller. - */ + */ char * elektraCryptoOpenSSLCreateRandomString (Key * errorKey, const kdb_unsigned_short_t length) { kdb_octet_t buffer[length]; diff --git a/src/plugins/fstab/fstab.c b/src/plugins/fstab/fstab.c index c63384d8520..354dd22af42 100644 --- a/src/plugins/fstab/fstab.c +++ b/src/plugins/fstab/fstab.c @@ -17,18 +17,18 @@ #define MAX_NUMBER_SIZE 10 /** @param name is a buffer with KDB_MAX_PATH_LENGTH space. - * @param fstabEntry will be used to get the name: - * @param swapIndex will count up for every swap - * - * - mnt_type will be checked if it is swap - * - * TODO Improvements: - * - no counting up of swap? - * - handle mountpoints none? - * - * Some logic to define the filesystem name when it is not - * so obvious. - */ + * @param fstabEntry will be used to get the name: + * @param swapIndex will count up for every swap + * + * - mnt_type will be checked if it is swap + * + * TODO Improvements: + * - no counting up of swap? + * - handle mountpoints none? + * + * Some logic to define the filesystem name when it is not + * so obvious. + */ void elektraFstabFsName (char * fsname, struct mntent * fstabEntry, unsigned int * swapIndex) { diff --git a/src/plugins/hexcode/hexcode.c b/src/plugins/hexcode/hexcode.c index 7cb2e9348e6..f94759a213d 100644 --- a/src/plugins/hexcode/hexcode.c +++ b/src/plugins/hexcode/hexcode.c @@ -18,9 +18,9 @@ #include /** - * Gives the integer number 0-15 to a corresponding - * hex character '0'-'9', 'a'-'f' or 'A'-'F'. - */ + * Gives the integer number 0-15 to a corresponding + * hex character '0'-'9', 'a'-'f' or 'A'-'F'. + */ static inline int elektraHexcodeConvFromHex (char c) { if (c == '0') @@ -60,11 +60,11 @@ static inline int elektraHexcodeConvFromHex (char c) } /** Reads the value of the key and decodes all escaping - * codes into the buffer. - * @pre the buffer needs to be as large as value's size. - * @param cur the key holding the value to decode - * @param buf the buffer to write to - */ + * codes into the buffer. + * @pre the buffer needs to be as large as value's size. + * @param cur the key holding the value to decode + * @param buf the buffer to write to + */ void elektraHexcodeDecode (Key * cur, CHexData * hd) { size_t valsize = keyGetValueSize (cur); @@ -148,9 +148,9 @@ int elektraHexcodeGet (Plugin * handle, KeySet * returned, Key * parentKey) /** - * Gives the integer number 0-15 to a corresponding - * hex character '0'-'9', 'a'-'f' or 'A'-'F'. - */ + * Gives the integer number 0-15 to a corresponding + * hex character '0'-'9', 'a'-'f' or 'A'-'F'. + */ static inline char elektraHexcodeConvToHex (int c) { switch (c) @@ -194,12 +194,12 @@ static inline char elektraHexcodeConvToHex (int c) /** Reads the value of the key and encodes it in - * c-style in the buffer. - * - * @param cur the key which value is to encode - * @param buf the buffer - * @pre the buffer needs to have thrice as much space as the value's size - */ + * c-style in the buffer. + * + * @param cur the key which value is to encode + * @param buf the buffer + * @pre the buffer needs to have thrice as much space as the value's size + */ void elektraHexcodeEncode (Key * cur, CHexData * hd) { size_t valsize = keyGetValueSize (cur); diff --git a/src/plugins/iconv/iconv.c b/src/plugins/iconv/iconv.c index 8dc0d1f9d39..b92ca682879 100644 --- a/src/plugins/iconv/iconv.c +++ b/src/plugins/iconv/iconv.c @@ -57,7 +57,7 @@ int kdbbNeedsUTF8Conversion (Plugin * handle) /** * Converts string to (@p direction = @c UTF8_TO) and from * (@p direction = @c UTF8_FROM) UTF-8. - * + * * Since Elektra provides portability for key names and string values between * different codesets, you should use this helper in your backend to convert * to and from universal UTF-8 strings, when storing key names, values and diff --git a/src/plugins/ni/nickel-1.1.0/include/bohr/ni.h b/src/plugins/ni/nickel-1.1.0/include/bohr/ni.h index de7ef633dc0..584ed916e16 100644 --- a/src/plugins/ni/nickel-1.1.0/include/bohr/ni.h +++ b/src/plugins/ni/nickel-1.1.0/include/bohr/ni.h @@ -1,256 +1,256 @@ /****************************************************************************** -* Nickel - a library for hierarchical maps and .ini files -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: ni.h 349 2008-01-19 18:18:22Z chaz $ -******************************************************************************/ + * Nickel - a library for hierarchical maps and .ini files + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: ni.h 349 2008-01-19 18:18:22Z chaz $ + ******************************************************************************/ /****************************************************************************** -* Extensive documentation for Nickel is maintained on the Bohr Game Libraries -* website: http://www.chaoslizard.org/devel/bohr/wiki/Docs/Ni -* -* I'll give a brief overview here anyway, for those who're too lazy to look at -* the real documentation. But really, check out the website for details. -* -* Nickel, at heart, stores nodes, each of which has a name, value, and any -* number of children. Children are stored in a hash table for quick lookup. -* Built around this is a set of functions for building such a map from a -* standard Windows .ini file, as well as writing back to a file format that, if -* the map is carefully constructed or read from a .ini file, is roughly -* compatible with the Windows GetPrivateProfile* functions. -* -* The only hard-coded size limit in Nickel is the length of node names, which -* are capped at elektraNi_KEY_SIZE-1 (127, currently) bytes (not UTF-8 characters) to -* give a reasonable maximum boundary on search time. Otherwise, you're limited -* only by available memory. Thus, Nickel can parse files as big as the C -* standard library can handle, and node values can be as big as will fit in -* memory. The number of children a node can have, as well as the size of the -* entire tree, is also limited only by available memory. -* -* There is some wasted memory with each node--it allocates a number (32, -* currently) of initial spaces (each sizeof(void *)) in the hash table of the -* node's children, so resizing (an expensive operation) occurs less frequently. -* Also, it doubles the capacity of the hash table when it gets 3/4 full, so -* searching has a good average-case running time, but this means there's always -* some wasted space. -* -* Following are the details of the files that Nickel can parse and write. -* -* Files should be UTF-8 (or plain ol' ASCII) encoded, though Nickel can handle -* arbitrary binary data too. -* -* On reading, Nickel treats all newline flavors (at least, CR, LF, and CRLF) as -* simply LF (\n in C). This applies EVEN INSIDE QUOTED STRINGS (see below). -* If you need a CR (\r in C) character in a node's name/value, you must escape -* it (see below), that is, put a literal "\r" (backslash, lower r). -* -* Though this is not enforced, the first few characters of a Nickel-compatible -* (as per version 1 of the API) .ini file should be: -* -* ;Ni1 -* -* (that's semicolon, upper N, lower i, digit 1) followed by a newline. This -* gives a machine-parsable sequence that future Nickel versions or other -* parsers can use to identify the file format, while being a .ini comment (see -* below) and thus ignored by anything that shouldn't care. Though it's not -* currently checked in Nickel (it'll try to parse anything you throw at it), it -* may be in future versions. -* -* There are two kinds of data Nickel looks for in .ini files: names and values. -* A name is a sequence of characters inside a number of [] (square brackets), -* which denotes a section heading, OR before an = (equals sign), which denotes -* that the value for the node follows. Either way a name is encountered, a -* node with that name will be created (or, if the named node already exists, -* its value or children will be modified, depending on what comes next). -* -* Both names and values can have surrounding "" (double quotes). When the -* parser encounters an opening " (double quote), it parses all data until a -* closing " (double quote), even spanning newlines, in the context of the name -* or value. The parser supports string concatenation whereby: -* -* "some" "thing" -* -* is equivalent to: -* -* "something" -* -* Whitespace must be the only characters between closing " (double quote) and -* re-opening " (double quote) for this to work (or, in values, there can be a -* \ (backslash) and a newline--see escaping, below). -* -* Comments are initiated with the ; (semicolon). Any ; (semicolon) outside of -* double quotes begins a comment (except when escaped, see below). Comments go -* until the end of the line (and cannot be continued onto the next line with \ -* (backslash), as in some languages). -* -* Any line deemed invalid (e.g. blank or without an = (equals sign) or [] -* (square brackets)) is ignored as a comment. -* -* Nickel understands escape sequences similar to those in C. Nickel translates -* these escape sequences regardless of whether it's inside quotes or not. It -* treats the following sequences the same as C: -* -* \a \b \f \n \r \t \v \' \" \? \\ \ooo and \xhh -* -* where ooo is up to 3 octal digits (0-7), hh is up to 2 hex digits (0-9, a-f, -* or A-F), and all other characters are literally as they're written there. -* The behavior of the hex escape (\xhh) may differ from how C handles it in -* that I believe C allows the string of hex digits to be longer than 2. And -* I'm not sure how C handles octal constants bigger than 255, but Nickel takes -* the whole octal value and uses the result modulus 256. But that's just -* semantics. -* -* Nickel also understands the following escape sequences, which exist only to -* allow .ini reserved characters in names and values in the file: -* -* \; \[ \] \= -* -* These are simply replaced with the character following the backslash. -* -* Note that escape sequences aren't always necessary, but are always parsed if -* present. Thus the following two lines are equivalent: -* -* poo = \ \="\[ ; here, the = and [ are escaped -* poo = "\\ =\"[" ; here, double quotes are used and \ and " are escaped -* -* and indicate the node has a value of: \ (backslash), space, = (equals sign), -* " (double quote), and [ (opening square bracket). In the example, the double -* quotes aren't necessary on the second line, but are there to illustrate that -* the escape sequences are the same inside and outside of quotes (except that -* in quotes, if a " (double quote) is encountered unescaped, it obviously ends -* the quote). -* -* In values only, it is possible to escape a literal newline to instruct Nickel -* to continue consuming the next line as part of the value. This escape -* consists of a \ (backslash) as the last non-whitespace character on a line, -* ignoring comments. If following a quoted string, the \ (backslash) should -* come after the closing " (quote). If the string immediately before the \ -* (backslash) is quoted, the \ (backslash)-newline pair is simply omitted, but -* if the previous string was unquoted, the pair is replaced by a single space, -* regardless of how much intervening space there actually was. Thus, the -* following lines all create equivalent nodes: -* -* poo = abc def ; just the string "abc def" -* poo = abc \ ; no quotes, lots of spaces, and continue on the next line -* "def" ; quotes here just for shits and giggles--not necessary -* poo = "abc " \ ; first line with quotes, then continue on the next line -* def ; which could also have quotes ("def"), doesn't matter -* -* with the 7-character value "abc def". -* -* Surrounding names and values, whitespace is eaten by the parser. This -* happens after comments are removed (see the above example). If you really -* want a node whose name or value begins or ends with spaces, enclose it in -* quotes. Inside names and values, whitespace is maintained. The exception to -* this is with the line-continuation escape, where, if the string immediately -* preceding the \ (backslash) was unquoted, spaces trailing on the top line or -* beginning the second line are all replaced with a single space, or if the -* preceding string was quoted, no space is inserted and initial space on the -* following line is ignored. See the above example for clarification on this. -* -* Lines giving values to named nodes (e.g. name = value) become children of the -* node given in the most recent previous section (e.g. [name]), or the root -* node if there have been no sections yet. You can define subsections (e.g. -* [[name]]) by specifying increasing numbers of [ (opening square bracket) -* characters. Sections with the same number of brackets become children of the -* most recently preceding parent defined with fewer brackets; sections with -* more brackets become deeper children, and sections with fewer brackets are -* closer to the root. The following example shows the root gaining two -* children, "child1" (with value "teh suz" and child "sub_child1") and "child2" -* (with its own child "sub_child2"): -* -* child1 = teh suz ; create child1 as a child of the root, give it a value -* [ child2 ] ; another root child, anything below is child2's child -* [[sub_child2 ]] ; sub_child2, having more [, is under child2 -* [child1] ; back up to root's child child1 -* sub_child1= ; this is a child of the previous section, i.e., child1 -* -* (Spaces were added and the order was slightly obfuscated to show these things -* are unimportant.) Note that the parser ignores the number of ] (closing -* square brackets) for the sake of keeping insignificant typos from causing -* errors, but to stay compatible with future versions of Nickel or other -* parsers, you should close each section with the same number of ] (closing -* square brackets) as it was opened with. -* -* Also note that if you skip steps in your subsections, e.g.: -* -* [child1] -* [[[ sub_sub_child1 ]]] -* -* empty children are inserted to make up the difference (here, "child1" has an -* unnamed child, which has a child "sub_sub_child1"). -* -* If a name is given more than once under the same parent in a file, the last -* instance overrides all previous instances. Thus: -* -* [child1] -* sub = asdf -* [child1] -* sub = again -* -* gives "child1" a child called "sub", and gives it the value "again". Note -* that there is only one "child1", and the value "asdf" is overwritten by -* "again" for "sub". -* -* It's valid to specify empty names. Here: -* -* [] -* = -* -* creates a node with an empty name as the child of the root, and gives it a -* child with an empty name and empty value. -* -* One more note: the parser is pretty lax--it will glean as much valid -* information from a line as it can, ignoring errors if it can still get -* something useful. This can lead to weird results. Consider the following -* lines: -* -* [section] child = value -* # comments = cool! -* -* Here, because anything other than a comment after the ] (closing square -* bracket) is invalid, the parser ignores "child = value" on the first line. -* Also, because # (hash mark) isn't the standard for initiating a comment, the -* second line creates a child of "section" named "# comments", with the value -* "cool!". Keep your files valid and standard and you won't have issues. -* -* This gives you an idea how the parser works. More examples are in order for -* future revisions of this document, but as I imagine this'll mostly be used -* for simple .ini parsing, what's above is sufficient for now. -* -* While Nickel should be able to parse any Windows-compatible .ini file, it -* won't necessarily output to a format that Windows will understand. Some -* circumstances it will generate an incompatible file are: -* -* * The tree is more than one level deep -* * A node's name or value contains a special character: [ = \ ; etc. (as -* these may be escaped by Nickel) -* * A node's name or value has initial or trailing whitespace (as Nickel will -* put such a string inside quotes) -* -* Nickel can always parse a file it generates; it's just that Windows doesn't -* understand some of Nickel's syntax, I believe, like nested headings, escaped -* characters, and quotes. Also, if you read a Windows-compatible .ini file -* into memory and write it right back out to disk, you'll get a Windows- -* compatible .ini file as long as no special characters are in any node's -* value. Nickel is fairly good about escaping special characters only when -* necessary (as of v1.1.0, anyway), but if maximum compatibility with other -* parsers is your goal, avoid special characters in names and values. -* -* It's also worth noting that since Nickel builds an in-memory map based on the -* .ini file, and writing files uses the in-memory representation of the data, -* comments in the file are entirely lost. This is unfortunate, but means that -* Nickel runs quickly enough to be used inside, say, a game, since accessing -* the data doesn't require costly disk reads. -* -* It's also unfortunate that order is lost between reading and writing. This -* is due to hashing mixing things up. The speed gain from hashing entries -* greatly outweighs maintaining order, in my mind, and keeping an index of the -* order nodes were added would take more overhead than I believe it's worth. -* -* Thus concludes my lengthy explanation of Nickel's .ini parser. -******************************************************************************/ + * Extensive documentation for Nickel is maintained on the Bohr Game Libraries + * website: http://www.chaoslizard.org/devel/bohr/wiki/Docs/Ni + * + * I'll give a brief overview here anyway, for those who're too lazy to look at + * the real documentation. But really, check out the website for details. + * + * Nickel, at heart, stores nodes, each of which has a name, value, and any + * number of children. Children are stored in a hash table for quick lookup. + * Built around this is a set of functions for building such a map from a + * standard Windows .ini file, as well as writing back to a file format that, if + * the map is carefully constructed or read from a .ini file, is roughly + * compatible with the Windows GetPrivateProfile* functions. + * + * The only hard-coded size limit in Nickel is the length of node names, which + * are capped at elektraNi_KEY_SIZE-1 (127, currently) bytes (not UTF-8 characters) to + * give a reasonable maximum boundary on search time. Otherwise, you're limited + * only by available memory. Thus, Nickel can parse files as big as the C + * standard library can handle, and node values can be as big as will fit in + * memory. The number of children a node can have, as well as the size of the + * entire tree, is also limited only by available memory. + * + * There is some wasted memory with each node--it allocates a number (32, + * currently) of initial spaces (each sizeof(void *)) in the hash table of the + * node's children, so resizing (an expensive operation) occurs less frequently. + * Also, it doubles the capacity of the hash table when it gets 3/4 full, so + * searching has a good average-case running time, but this means there's always + * some wasted space. + * + * Following are the details of the files that Nickel can parse and write. + * + * Files should be UTF-8 (or plain ol' ASCII) encoded, though Nickel can handle + * arbitrary binary data too. + * + * On reading, Nickel treats all newline flavors (at least, CR, LF, and CRLF) as + * simply LF (\n in C). This applies EVEN INSIDE QUOTED STRINGS (see below). + * If you need a CR (\r in C) character in a node's name/value, you must escape + * it (see below), that is, put a literal "\r" (backslash, lower r). + * + * Though this is not enforced, the first few characters of a Nickel-compatible + * (as per version 1 of the API) .ini file should be: + * + * ;Ni1 + * + * (that's semicolon, upper N, lower i, digit 1) followed by a newline. This + * gives a machine-parsable sequence that future Nickel versions or other + * parsers can use to identify the file format, while being a .ini comment (see + * below) and thus ignored by anything that shouldn't care. Though it's not + * currently checked in Nickel (it'll try to parse anything you throw at it), it + * may be in future versions. + * + * There are two kinds of data Nickel looks for in .ini files: names and values. + * A name is a sequence of characters inside a number of [] (square brackets), + * which denotes a section heading, OR before an = (equals sign), which denotes + * that the value for the node follows. Either way a name is encountered, a + * node with that name will be created (or, if the named node already exists, + * its value or children will be modified, depending on what comes next). + * + * Both names and values can have surrounding "" (double quotes). When the + * parser encounters an opening " (double quote), it parses all data until a + * closing " (double quote), even spanning newlines, in the context of the name + * or value. The parser supports string concatenation whereby: + * + * "some" "thing" + * + * is equivalent to: + * + * "something" + * + * Whitespace must be the only characters between closing " (double quote) and + * re-opening " (double quote) for this to work (or, in values, there can be a + * \ (backslash) and a newline--see escaping, below). + * + * Comments are initiated with the ; (semicolon). Any ; (semicolon) outside of + * double quotes begins a comment (except when escaped, see below). Comments go + * until the end of the line (and cannot be continued onto the next line with \ + * (backslash), as in some languages). + * + * Any line deemed invalid (e.g. blank or without an = (equals sign) or [] + * (square brackets)) is ignored as a comment. + * + * Nickel understands escape sequences similar to those in C. Nickel translates + * these escape sequences regardless of whether it's inside quotes or not. It + * treats the following sequences the same as C: + * + * \a \b \f \n \r \t \v \' \" \? \\ \ooo and \xhh + * + * where ooo is up to 3 octal digits (0-7), hh is up to 2 hex digits (0-9, a-f, + * or A-F), and all other characters are literally as they're written there. + * The behavior of the hex escape (\xhh) may differ from how C handles it in + * that I believe C allows the string of hex digits to be longer than 2. And + * I'm not sure how C handles octal constants bigger than 255, but Nickel takes + * the whole octal value and uses the result modulus 256. But that's just + * semantics. + * + * Nickel also understands the following escape sequences, which exist only to + * allow .ini reserved characters in names and values in the file: + * + * \; \[ \] \= + * + * These are simply replaced with the character following the backslash. + * + * Note that escape sequences aren't always necessary, but are always parsed if + * present. Thus the following two lines are equivalent: + * + * poo = \ \="\[ ; here, the = and [ are escaped + * poo = "\\ =\"[" ; here, double quotes are used and \ and " are escaped + * + * and indicate the node has a value of: \ (backslash), space, = (equals sign), + * " (double quote), and [ (opening square bracket). In the example, the double + * quotes aren't necessary on the second line, but are there to illustrate that + * the escape sequences are the same inside and outside of quotes (except that + * in quotes, if a " (double quote) is encountered unescaped, it obviously ends + * the quote). + * + * In values only, it is possible to escape a literal newline to instruct Nickel + * to continue consuming the next line as part of the value. This escape + * consists of a \ (backslash) as the last non-whitespace character on a line, + * ignoring comments. If following a quoted string, the \ (backslash) should + * come after the closing " (quote). If the string immediately before the \ + * (backslash) is quoted, the \ (backslash)-newline pair is simply omitted, but + * if the previous string was unquoted, the pair is replaced by a single space, + * regardless of how much intervening space there actually was. Thus, the + * following lines all create equivalent nodes: + * + * poo = abc def ; just the string "abc def" + * poo = abc \ ; no quotes, lots of spaces, and continue on the next line + * "def" ; quotes here just for shits and giggles--not necessary + * poo = "abc " \ ; first line with quotes, then continue on the next line + * def ; which could also have quotes ("def"), doesn't matter + * + * with the 7-character value "abc def". + * + * Surrounding names and values, whitespace is eaten by the parser. This + * happens after comments are removed (see the above example). If you really + * want a node whose name or value begins or ends with spaces, enclose it in + * quotes. Inside names and values, whitespace is maintained. The exception to + * this is with the line-continuation escape, where, if the string immediately + * preceding the \ (backslash) was unquoted, spaces trailing on the top line or + * beginning the second line are all replaced with a single space, or if the + * preceding string was quoted, no space is inserted and initial space on the + * following line is ignored. See the above example for clarification on this. + * + * Lines giving values to named nodes (e.g. name = value) become children of the + * node given in the most recent previous section (e.g. [name]), or the root + * node if there have been no sections yet. You can define subsections (e.g. + * [[name]]) by specifying increasing numbers of [ (opening square bracket) + * characters. Sections with the same number of brackets become children of the + * most recently preceding parent defined with fewer brackets; sections with + * more brackets become deeper children, and sections with fewer brackets are + * closer to the root. The following example shows the root gaining two + * children, "child1" (with value "teh suz" and child "sub_child1") and "child2" + * (with its own child "sub_child2"): + * + * child1 = teh suz ; create child1 as a child of the root, give it a value + * [ child2 ] ; another root child, anything below is child2's child + * [[sub_child2 ]] ; sub_child2, having more [, is under child2 + * [child1] ; back up to root's child child1 + * sub_child1= ; this is a child of the previous section, i.e., child1 + * + * (Spaces were added and the order was slightly obfuscated to show these things + * are unimportant.) Note that the parser ignores the number of ] (closing + * square brackets) for the sake of keeping insignificant typos from causing + * errors, but to stay compatible with future versions of Nickel or other + * parsers, you should close each section with the same number of ] (closing + * square brackets) as it was opened with. + * + * Also note that if you skip steps in your subsections, e.g.: + * + * [child1] + * [[[ sub_sub_child1 ]]] + * + * empty children are inserted to make up the difference (here, "child1" has an + * unnamed child, which has a child "sub_sub_child1"). + * + * If a name is given more than once under the same parent in a file, the last + * instance overrides all previous instances. Thus: + * + * [child1] + * sub = asdf + * [child1] + * sub = again + * + * gives "child1" a child called "sub", and gives it the value "again". Note + * that there is only one "child1", and the value "asdf" is overwritten by + * "again" for "sub". + * + * It's valid to specify empty names. Here: + * + * [] + * = + * + * creates a node with an empty name as the child of the root, and gives it a + * child with an empty name and empty value. + * + * One more note: the parser is pretty lax--it will glean as much valid + * information from a line as it can, ignoring errors if it can still get + * something useful. This can lead to weird results. Consider the following + * lines: + * + * [section] child = value + * # comments = cool! + * + * Here, because anything other than a comment after the ] (closing square + * bracket) is invalid, the parser ignores "child = value" on the first line. + * Also, because # (hash mark) isn't the standard for initiating a comment, the + * second line creates a child of "section" named "# comments", with the value + * "cool!". Keep your files valid and standard and you won't have issues. + * + * This gives you an idea how the parser works. More examples are in order for + * future revisions of this document, but as I imagine this'll mostly be used + * for simple .ini parsing, what's above is sufficient for now. + * + * While Nickel should be able to parse any Windows-compatible .ini file, it + * won't necessarily output to a format that Windows will understand. Some + * circumstances it will generate an incompatible file are: + * + * * The tree is more than one level deep + * * A node's name or value contains a special character: [ = \ ; etc. (as + * these may be escaped by Nickel) + * * A node's name or value has initial or trailing whitespace (as Nickel will + * put such a string inside quotes) + * + * Nickel can always parse a file it generates; it's just that Windows doesn't + * understand some of Nickel's syntax, I believe, like nested headings, escaped + * characters, and quotes. Also, if you read a Windows-compatible .ini file + * into memory and write it right back out to disk, you'll get a Windows- + * compatible .ini file as long as no special characters are in any node's + * value. Nickel is fairly good about escaping special characters only when + * necessary (as of v1.1.0, anyway), but if maximum compatibility with other + * parsers is your goal, avoid special characters in names and values. + * + * It's also worth noting that since Nickel builds an in-memory map based on the + * .ini file, and writing files uses the in-memory representation of the data, + * comments in the file are entirely lost. This is unfortunate, but means that + * Nickel runs quickly enough to be used inside, say, a game, since accessing + * the data doesn't require costly disk reads. + * + * It's also unfortunate that order is lost between reading and writing. This + * is due to hashing mixing things up. The speed gain from hashing entries + * greatly outweighs maintaining order, in my mind, and keeping an index of the + * order nodes were added would take more overhead than I believe it's worth. + * + * Thus concludes my lengthy explanation of Nickel's .ini parser. + ******************************************************************************/ #ifndef __bohr_ni_h__ diff --git a/src/plugins/ni/nickel-1.1.0/src/buf.c b/src/plugins/ni/nickel-1.1.0/src/buf.c index 9cc7c7f6d32..56cda7ce523 100644 --- a/src/plugins/ni/nickel-1.1.0/src/buf.c +++ b/src/plugins/ni/nickel-1.1.0/src/buf.c @@ -1,9 +1,9 @@ /****************************************************************************** -* Nickel - a library for hierarchical maps and .ini files -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: buf.c 332 2008-01-13 18:32:02Z chaz $ -******************************************************************************/ + * Nickel - a library for hierarchical maps and .ini files + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: buf.c 332 2008-01-13 18:32:02Z chaz $ + ******************************************************************************/ #include "internal.h" diff --git a/src/plugins/ni/nickel-1.1.0/src/hash.c b/src/plugins/ni/nickel-1.1.0/src/hash.c index e9f6236cd0a..d467c153584 100644 --- a/src/plugins/ni/nickel-1.1.0/src/hash.c +++ b/src/plugins/ni/nickel-1.1.0/src/hash.c @@ -1,9 +1,9 @@ /****************************************************************************** -* Nickel - a library for hierarchical maps and .ini files -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: hash.c 344 2008-01-19 04:45:41Z chaz $ -******************************************************************************/ + * Nickel - a library for hierarchical maps and .ini files + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: hash.c 344 2008-01-19 04:45:41Z chaz $ + ******************************************************************************/ #include "internal.h" diff --git a/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_hash.h b/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_hash.h index 10fb1cf69f8..18b056ae545 100644 --- a/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_hash.h +++ b/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_hash.h @@ -1,10 +1,10 @@ /****************************************************************************** -* Darmstadtium - a library of data structures -* Ds_hash - a hash table library -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: ds_hash.h 317 2008-01-05 21:45:34Z chaz $ -******************************************************************************/ + * Darmstadtium - a library of data structures + * Ds_hash - a hash table library + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: ds_hash.h 317 2008-01-05 21:45:34Z chaz $ + ******************************************************************************/ #ifndef __bohr_ds_hash_h__ diff --git a/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_str.h b/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_str.h index a9d1086ce5f..d9bdeafcfbd 100644 --- a/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_str.h +++ b/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_str.h @@ -1,10 +1,10 @@ /****************************************************************************** -* Darmstadtium - a library of data structures -* Ds_str - a string library -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: ds_str.h 323 2008-01-06 03:55:26Z chaz $ -******************************************************************************/ + * Darmstadtium - a library of data structures + * Ds_str - a string library + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: ds_str.h 323 2008-01-06 03:55:26Z chaz $ + ******************************************************************************/ #ifndef __bohr_ds_str_h__ diff --git a/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_vector.h b/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_vector.h index fdd3dc00621..2a21422e443 100644 --- a/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_vector.h +++ b/src/plugins/ni/nickel-1.1.0/src/include/bohr/ds_vector.h @@ -1,10 +1,10 @@ /****************************************************************************** -* Darmstadtium - a library of data structures -* Ds_vector - a vector (growable array) library -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: ds_vector.h 317 2008-01-05 21:45:34Z chaz $ -******************************************************************************/ + * Darmstadtium - a library of data structures + * Ds_vector - a vector (growable array) library + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: ds_vector.h 317 2008-01-05 21:45:34Z chaz $ + ******************************************************************************/ // You must be careful about including this file multiple times. Each time it's diff --git a/src/plugins/ni/nickel-1.1.0/src/internal.h b/src/plugins/ni/nickel-1.1.0/src/internal.h index 0adac4fadcc..6eba779a41b 100644 --- a/src/plugins/ni/nickel-1.1.0/src/internal.h +++ b/src/plugins/ni/nickel-1.1.0/src/internal.h @@ -1,9 +1,9 @@ /****************************************************************************** -* Nickel - a library for hierarchical maps and .ini files -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: internal.h 331 2008-01-13 18:28:41Z chaz $ -******************************************************************************/ + * Nickel - a library for hierarchical maps and .ini files + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: internal.h 331 2008-01-13 18:28:41Z chaz $ + ******************************************************************************/ #ifndef __internal_h__ diff --git a/src/plugins/ni/nickel-1.1.0/src/io.c b/src/plugins/ni/nickel-1.1.0/src/io.c index 98641a4d7c5..a9c4f4be092 100644 --- a/src/plugins/ni/nickel-1.1.0/src/io.c +++ b/src/plugins/ni/nickel-1.1.0/src/io.c @@ -1,9 +1,9 @@ /****************************************************************************** -* Nickel - a library for hierarchical maps and .ini files -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: io.c 345 2008-01-19 17:02:54Z chaz $ -******************************************************************************/ + * Nickel - a library for hierarchical maps and .ini files + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: io.c 345 2008-01-19 17:02:54Z chaz $ + ******************************************************************************/ #include "internal.h" diff --git a/src/plugins/ni/nickel-1.1.0/src/nickel.c b/src/plugins/ni/nickel-1.1.0/src/nickel.c index fff7d18ffd2..3df56aaad19 100644 --- a/src/plugins/ni/nickel-1.1.0/src/nickel.c +++ b/src/plugins/ni/nickel-1.1.0/src/nickel.c @@ -1,9 +1,9 @@ /****************************************************************************** -* Nickel - a library for hierarchical maps and .ini files -* One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: nickel.c 339 2008-01-18 19:27:01Z chaz $ -******************************************************************************/ + * Nickel - a library for hierarchical maps and .ini files + * One of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: nickel.c 339 2008-01-18 19:27:01Z chaz $ + ******************************************************************************/ #include "internal.h" diff --git a/src/plugins/ni/nickel-1.1.0/src/tests/ni.c b/src/plugins/ni/nickel-1.1.0/src/tests/ni.c index bc581cfce96..bfdb101c695 100644 --- a/src/plugins/ni/nickel-1.1.0/src/tests/ni.c +++ b/src/plugins/ni/nickel-1.1.0/src/tests/ni.c @@ -1,9 +1,9 @@ /****************************************************************************** -* Nickel - a library for hierarchical maps and .ini files -* Part of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: ni.c 349 2008-01-19 18:18:22Z chaz $ -******************************************************************************/ + * Nickel - a library for hierarchical maps and .ini files + * Part of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: ni.c 349 2008-01-19 18:18:22Z chaz $ + ******************************************************************************/ #include #include diff --git a/src/plugins/ni/testmod_ni.c b/src/plugins/ni/testmod_ni.c index a7d3526b353..698c6ef1133 100644 --- a/src/plugins/ni/testmod_ni.c +++ b/src/plugins/ni/testmod_ni.c @@ -3,11 +3,11 @@ ****************************************************************************/ /****************************************************************************** -* Nickel - a library for hierarchical maps and .ini files -* Part of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) -* Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. -* $Id: ni.c 349 2008-01-19 18:18:22Z chaz $ -******************************************************************************/ + * Nickel - a library for hierarchical maps and .ini files + * Part of the Bohr Game Libraries (see chaoslizard.org/devel/bohr) + * Copyright (C) 2008 Charles Lindsay. Some rights reserved; see COPYING. + * $Id: ni.c 349 2008-01-19 18:18:22Z chaz $ + ******************************************************************************/ #ifdef HAVE_KDBCONFIG_H #include "kdbconfig.h" diff --git a/src/plugins/type/types.hpp b/src/plugins/type/types.hpp index 6fd93db2fea..bf0f69b2c25 100644 --- a/src/plugins/type/types.hpp +++ b/src/plugins/type/types.hpp @@ -89,11 +89,11 @@ class TType : public Type }; /** - * Reversible Type - * This checks even more pedantic, if the type is reversible - * to the same string. - * E.g. -1 might get to highest value (but this is not guaranteed)! - * */ + * Reversible Type + * This checks even more pedantic, if the type is reversible + * to the same string. + * E.g. -1 might get to highest value (but this is not guaranteed)! + * */ template class RType : public Type { @@ -117,11 +117,11 @@ class RType : public Type }; /** - * Reversible Type with min, max values - * This checks even more pedantic, if the type is reversible - * to the same string. - * E.g. -1 might get to highest value (but this is not guaranteed)! - * */ + * Reversible Type with min, max values + * This checks even more pedantic, if the type is reversible + * to the same string. + * E.g. -1 might get to highest value (but this is not guaranteed)! + * */ template class MType : public Type { diff --git a/src/plugins/xmltool/stream.c b/src/plugins/xmltool/stream.c index 8e94e9ebefe..e357e4462aa 100644 --- a/src/plugins/xmltool/stream.c +++ b/src/plugins/xmltool/stream.c @@ -337,8 +337,8 @@ ssize_t keyToStreamBasename (const Key * key, FILE * stream, const char * parent + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://www.libelektra.org elektra.xsd"> * @endverbatim * * @param ks the KeySet to serialise diff --git a/src/plugins/yajl/iterator.c b/src/plugins/yajl/iterator.c index 5b791d13527..987ac722e81 100644 --- a/src/plugins/yajl/iterator.c +++ b/src/plugins/yajl/iterator.c @@ -24,7 +24,7 @@ keyNameReverseIterator elektraKeyNameGetReverseIterator (const Key * k) * * @param it the iterator to iterate * - * @return + * @return */ int elektraKeyNameReverseNext (keyNameReverseIterator * it) { diff --git a/src/tools/gen/support/__init__.pyc b/src/tools/gen/support/__init__.pyc new file mode 100644 index 00000000000..42170d1f053 Binary files /dev/null and b/src/tools/gen/support/__init__.pyc differ diff --git a/src/tools/gen/support/c_elektra.py b/src/tools/gen/support/c_elektra.py new file mode 100644 index 00000000000..d5120607998 --- /dev/null +++ b/src/tools/gen/support/c_elektra.py @@ -0,0 +1,26 @@ +from support.gen import * +from support.util import * + +class CSupportElektra(CSupport): + def funcname(self, key): + if key.startswith('/'): + return self.funcpretty(key[1:]) + elif key.startswith('user/'): + return self.funcpretty(key[5:]) + elif key.startswith('system/'): + return self.funcpretty(key[7:]) + else: + raise Exception("invalid keyname " + key) + + def getfuncname(self, key): + return "elektraGet"+self.funcname(key) + + def setfuncname(self, key): + return "elektraSet"+self.funcname(key) + + def funcpretty(self, key): + return ''.join(x for x in key.title() if not x == '/' and not x == '_') + +if __name__ == "__main__": + import doctest + doctest.testmod() diff --git a/src/tools/gen/support/elektra_gen.py b/src/tools/gen/support/elektra_gen.py new file mode 100644 index 00000000000..3ead91d8573 --- /dev/null +++ b/src/tools/gen/support/elektra_gen.py @@ -0,0 +1,110 @@ +from support.gen import * +from support.util import * + + +class ElektraGenSupport(Support): + def normalized_key(self, key): + result = key + if key.startswith('/'): + result = result[1:] + elif key.startswith('user/'): + result = result[5:] + elif key.startswith('system/'): + result = result[7:] + else: + raise Exception("invalid keyname '" + key + "'") + + if key.endswith('/'): + result = result[:-1] + elif key.endswith('/#'): + result = result[:-2] + + return result + + def key_to_uppercase(self, key): + return key.upper().replace('/','_').replace('#','') + + def key_to_camelcase(self, key): + return ''.join(x for x in key.title() if not x == '/' and not x == '_') + + def tag(self, key): + return "ELEKTRA_TAG_" + self.tag_name(key) + + def tag_name(self, key): + normalized = self.normalized_key(key) + return self.key_to_uppercase(normalized) + + def upcase_first_letter(self, s): + return s[:1].upper() + s[1:] + + def type_of(self, info): + if "gen/type" in info: + type = info["gen/type"] + elif "type" in info: + type = info["type"] + else: + raise Exception("Missing type.") + + if type in ["enum", "string", "boolean", "char", "octet", "short", "unsigned_short", "long", "unsigned_long", "long_long", "unsigned_long_long", "float", "double", "long_double"]: + return type + else: + raise Exception("Invalid type: '" + type + "'") + + def kdb_type_to_tag_type(self, type): + result = "" + for part in type.split('_'): + result += self.upcase_first_letter(part) + + return ("Elektra" + result + "Tag") + + def tag_type(self, key, info): + """Return the type for given parameter""" + type = self.type_of(info) + if type == "enum": + return self.enum_type(key) + "Tag" + else: + return self.kdb_type_to_tag_type(type) + + def check_default(self, key, info): + if "default" in info: + return True + else: + raise Exception("Key '" + key + "' doesn't have a default value!") + + def default_value(self, key, info): + value = info["default"] + type = self.type_of(info) + if type == "enum": + enum_values = self.toarray(info, "check/enum") + return enum_values.index(value) + else: + if value.startswith('"') and value.endswith('"'): + value = value[1:] + value = value[:-1] + return value + + def enum_typedef(self, key, info): + normalized = self.normalized_key(key) + prefix = "ELEKTRA_ENUM_"+ self.key_to_uppercase(normalized) + + result = "typedef enum {\n" + + enum_values = self.toarray(info, "check/enum") + for i, v in enumerate(enum_values): + case = prefix + "_" + v.upper() + result += case + " = " + str(i) + ",\n" + + result += "} " + self.enum_type(key) + ";" + + return result + + def enum_type(self, key): + return "Elektra" + self.enum_type_name(key) + + def enum_type_name(self, key): + normalized = self.normalized_key(key) + return "Enum" + self.key_to_camelcase(normalized) + +if __name__ == "__main__": + import doctest + doctest.testmod() diff --git a/src/tools/gen/support/elektra_gen.pyc b/src/tools/gen/support/elektra_gen.pyc new file mode 100644 index 00000000000..981cae144c6 Binary files /dev/null and b/src/tools/gen/support/elektra_gen.pyc differ diff --git a/src/tools/gen/support/gen.pyc b/src/tools/gen/support/gen.pyc new file mode 100644 index 00000000000..88e785d5a03 Binary files /dev/null and b/src/tools/gen/support/gen.pyc differ diff --git a/src/tools/gen/support/util.pyc b/src/tools/gen/support/util.pyc new file mode 100644 index 00000000000..684c70234bb Binary files /dev/null and b/src/tools/gen/support/util.pyc differ diff --git a/src/tools/gen/template/elektra_gen.c b/src/tools/gen/template/elektra_gen.c new file mode 100644 index 00000000000..82433212086 --- /dev/null +++ b/src/tools/gen/template/elektra_gen.c @@ -0,0 +1,25 @@ +/** + * @file + * + * @brief + * + * @copyright BSD License (see doc/LICENSE.md or https://www.libelektra.org) + */ + +#compiler-settings +directiveStartToken = @ +cheetahVarStartToken = $ +#end compiler-settings +@from support.elektra_gen import * +@set support = ElektraGenSupport() + +#include +#include +#include +#include "elektra_gen.h" + +@for $key, $info in $parameters.iteritems() +@if $support.type_of($info) == "enum" +ELEKTRA_DEFINITIONS ($support.enum_type($key), $support.enum_type_name($key), "enum", KDB_ENUM_TO_STRING, KDB_STRING_TO_ENUM) +@end if +@end for diff --git a/src/tools/gen/template/elektra_gen.h b/src/tools/gen/template/elektra_gen.h new file mode 100644 index 00000000000..035b0ef4052 --- /dev/null +++ b/src/tools/gen/template/elektra_gen.h @@ -0,0 +1,64 @@ +/** + * @file + * + * @brief + * + * @copyright BSD License (see doc/LICENSE.md or https://www.libelektra.org) + */ + +#compiler-settings +directiveStartToken = @ +cheetahVarStartToken = $ +#end compiler-settings +@from support.elektra_gen import * +@set support = ElektraGenSupport() + +/** + * Enums + */ + +@for $key, $info in $parameters.iteritems() +@if $support.type_of($info) == "enum" +$support.enum_typedef($key, $info) + +@end if +@end for +/** + * Default KeySet + */ + +#define ELEKTRA_DEFAULTS ksNew ($len($parameters), \ +@for $key, $info in $parameters.iteritems() +@if $support.check_default($key, $info) +keyNew ("$key", KEY_VALUE, "$support.default_value(key, info)", KEY_META, "type", "$support.type_of(info)", KEY_END), \ +@end if +@end for +KS_END) + +/** + * Elektra Tags + */ + +@for $key, $info in $parameters.iteritems() +#define $support.tag($key) ($support.tag_type(key, info)){"$key"} +@end for + +/** + * Types + */ + +@for $key, $info in $parameters.iteritems() +@if $support.type_of($info) == "enum" +ELEKTRA_DECLARATIONS($support.enum_type($key), $support.enum_type_name($key)) +@end if +@end for + +#undef ELEKTRA_TAG_NAMES_GEN +#define ELEKTRA_TAG_NAMES_GEN(X) \ +@for $key, $info in $parameters.iteritems() +@if $support.type_of($info) == "enum" +X($support.enum_type_name($key)) \ +@end if +@end for + +#include diff --git a/src/tools/gen/tests/elektra_gen.ini b/src/tools/gen/tests/elektra_gen.ini new file mode 100644 index 00000000000..d3fd28da0ca --- /dev/null +++ b/src/tools/gen/tests/elektra_gen.ini @@ -0,0 +1,63 @@ +[/server/serverScreen] +check/enum/#0=off +check/enum/#1=on +check/enum/#2=blank +default=off +type=enum + +[/customtypekey] +type=customtype +gen/type=string +default=A value + +[/stringkey] +type=string +default=A string + +[/booleankey] +type=boolean +default=1 + +[/charkey] +type=char +default=c + +[/octetkey] +type=octet +default=1 + +[/shortkey] +type=short +default=1 + +[/unsignedshortkey] +type=unsigned_short +default=1 + +[/longkey] +type=long +default=1 + +[/unsignedlongkey] +type=unsigned_long +default=1 + +[/longlongkey] +type=long_long +default=1 + +[/unsignedlonglongkey] +type=unsigned_long_long +default=1 + +[/floatkey] +type=float +default=1.1 + +[/doublekey] +type=double +default=1.1 + +[/longdoublekey] +type=long_double +default=1.1 diff --git a/src/tools/kdb/cmdline.hpp b/src/tools/kdb/cmdline.hpp index 8bd55921ca8..4ecac43dbcb 100644 --- a/src/tools/kdb/cmdline.hpp +++ b/src/tools/kdb/cmdline.hpp @@ -42,9 +42,9 @@ class Cmdline } /** The synopsis of the command - * Currently it is only printed out. - * May be used to determine number of - * commands in the future. + * Currently it is only printed out. + * May be used to determine number of + * commands in the future. */ std::string synopsis; @@ -100,7 +100,7 @@ class Cmdline std::string executable; /** The given name for the current command. - * This is the second parameter. */ + * This is the second parameter. */ std::string commandName; /** The arguments given on the commandline. */ diff --git a/src/tools/kdb/command.hpp b/src/tools/kdb/command.hpp index bdd386e6a38..4a365cd34a8 100644 --- a/src/tools/kdb/command.hpp +++ b/src/tools/kdb/command.hpp @@ -64,100 +64,100 @@ class Command virtual ~Command (); /** - * @return the text representing which short options are needed - * by this command. - * - * @note the :, which indicates that an optional argument is needed, - * is added automatically. - * HV (for help and version) are automatically added. - * All options are sorted and made unique before passed - * to getopt. - * - */ + * @return the text representing which short options are needed + * by this command. + * + * @note the :, which indicates that an optional argument is needed, + * is added automatically. + * HV (for help and version) are automatically added. + * All options are sorted and made unique before passed + * to getopt. + * + */ virtual std::string getShortOptions () = 0; /** - * @return a string describing describe what parameter the - * command needs or an empty line if none. - * - * The return value should be: - * - * @code - * [] - * @endcode - * - * if you want the help to be printed like: - * - * @code - * Usage: kdb set [] - * @endcode - * - * The string may be empty if no arguments are taken. - */ + * @return a string describing describe what parameter the + * command needs or an empty line if none. + * + * The return value should be: + * + * @code + * [] + * @endcode + * + * if you want the help to be printed like: + * + * @code + * Usage: kdb set [] + * @endcode + * + * The string may be empty if no arguments are taken. + */ virtual std::string getSynopsis () = 0; /** - * @return a one line help text - * - * The help text is shown in the overview of the command - * and as first line of normal help text given by -H or --help - * - * The sentence should end with an dot. - * No newline should occur in the sentence. - * - * @see getLongHelpText for the other help text lines - */ + * @return a one line help text + * + * The help text is shown in the overview of the command + * and as first line of normal help text given by -H or --help + * + * The sentence should end with an dot. + * No newline should occur in the sentence. + * + * @see getLongHelpText for the other help text lines + */ virtual std::string getShortHelpText () = 0; /** - * @return a long description of what the command does. - * - * May contain multiple lines or paragraphs. - * A line should not exceed 72 characters. - * The text should not start or end with an newline feed. - * - * @code - * Long description what the command does. - * Even more explanation. - * @endcode - * - * The long description should not repeat what the - * short help text already said, because the - * short help text will be the first line - * when help is shown. - * - * @see getShortHelpText for the first line - * - * The long text should describe all elements - * of the synopsis. - * - * @see getSynopsis for the synopsis - * - * It should not describe any of the commandline - * options, but rather use the cmdline option - * parsing system. - * - * @see getShortOptions to express available options - */ + * @return a long description of what the command does. + * + * May contain multiple lines or paragraphs. + * A line should not exceed 72 characters. + * The text should not start or end with an newline feed. + * + * @code + * Long description what the command does. + * Even more explanation. + * @endcode + * + * The long description should not repeat what the + * short help text already said, because the + * short help text will be the first line + * when help is shown. + * + * @see getShortHelpText for the first line + * + * The long text should describe all elements + * of the synopsis. + * + * @see getSynopsis for the synopsis + * + * It should not describe any of the commandline + * options, but rather use the cmdline option + * parsing system. + * + * @see getShortOptions to express available options + */ virtual std::string getLongHelpText () = 0; /** - * Execute the command. - * - * @pre The options are parsed already. - * - * You need to take care if there is the correct number - * of arguments with the correct contents. - * This is needed because of optional parameters. - * - * @retval 0 if the command could be executed successfully. - * - * @return a positive number if any other error occurred. - * No help is shown in this situation. - * - * @throw invalid_argument if the cmdline arguments could - * not be processed successfully. - */ + * Execute the command. + * + * @pre The options are parsed already. + * + * You need to take care if there is the correct number + * of arguments with the correct contents. + * This is needed because of optional parameters. + * + * @retval 0 if the command could be executed successfully. + * + * @return a positive number if any other error occurred. + * No help is shown in this situation. + * + * @throw invalid_argument if the cmdline arguments could + * not be processed successfully. + */ virtual int execute (Cmdline const & cmdline) = 0; }; diff --git a/src/tools/qt-gui/src/confignode.hpp b/src/tools/qt-gui/src/confignode.hpp index 68be6a57503..acf3f28f636 100644 --- a/src/tools/qt-gui/src/confignode.hpp +++ b/src/tools/qt-gui/src/confignode.hpp @@ -140,12 +140,12 @@ class ConfigNode : public QObject QSharedPointer getChildByName (QString & name) const; /** - * @brief Returns a child on a given index. - * - * @param index The index of the wanted child. - * - * @return The child on the given index. - */ + * @brief Returns a child on a given index. + * + * @param index The index of the wanted child. + * + * @return The child on the given index. + */ Q_INVOKABLE QSharedPointer getChildByIndex (int index) const; /** diff --git a/src/tools/qt-gui/src/datacontainer.hpp b/src/tools/qt-gui/src/datacontainer.hpp index a63a6ac2992..8f30b47999c 100644 --- a/src/tools/qt-gui/src/datacontainer.hpp +++ b/src/tools/qt-gui/src/datacontainer.hpp @@ -38,128 +38,131 @@ class DataContainer : public QObject } /** - * @brief The old name of a ConfigNode. Used when creating EditKeyCommands. - * @return The old name of a ConfigNode. - */ + * @brief The old name of a ConfigNode. Used when creating EditKeyCommands. + * @return The old name of a ConfigNode. + */ Q_INVOKABLE QString oldName () const; /** - * @brief Sets the old name of a ConfigNode. Used when creating EditKeyCommands. - * @param name The old name of a ConfigNode. - */ + * @brief Sets the old name of a ConfigNode. Used when creating EditKeyCommands. + * @param name The old name of a ConfigNode. + */ Q_INVOKABLE void setOldName (const QString & name); /** - * @brief The old value of a ConfigNode. Used when creating EditKeyCommands. - * @return The old value of a ConfigNode. - */ + * @brief The old value of a ConfigNode. Used when creating EditKeyCommands. + * @return The old value of a ConfigNode. + */ Q_INVOKABLE QString oldValue () const; /** - * @brief Sets the old value of a ConfigNode. Used when creating EditKeyCommands. - * @param value The old value of a ConfigNode. - */ + * @brief Sets the old value of a ConfigNode. Used when creating EditKeyCommands. + * @param value The old value of a ConfigNode. + */ Q_INVOKABLE void setOldValue (const QString & value); /** - * @brief The old metadata of a ConfigNode. Used when creating EditKeyCommands. - * @return The old metadata of a ConfigNode. - */ + * @brief The old metadata of a ConfigNode. Used when creating EditKeyCommands. + * @return The old metadata of a ConfigNode. + */ Q_INVOKABLE QVariantMap oldMetadata () const; /** - * @brief Sets the old metadata of a ConfigNode. Used when creating EditKeyCommands. - * @param metadata The old metadata of a ConfigNode. - */ + * @brief Sets the old metadata of a ConfigNode. Used when creating EditKeyCommands. + * @param metadata The old metadata of a ConfigNode. + */ Q_INVOKABLE void setOldMetadata (TreeViewModel * metadata); /** - * @brief The new name of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. - * @return The new name of a ConfigNode. - */ + * @brief The new name of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. + * @return The new name of a ConfigNode. + */ Q_INVOKABLE QString newName () const; /** - * @brief Sets the new name of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. - * @param name The new name of a ConfigNode. - */ + * @brief Sets the new name of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. + * @param name The new name of a ConfigNode. + */ Q_INVOKABLE void setNewName (const QString & name); /** - * @brief The new value of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. - * @param name The new value of a ConfigNode. - */ + * @brief The new value of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. + * @param name The new value of a ConfigNode. + */ Q_INVOKABLE QString newValue () const; /** - * @brief Sets the new value of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. - * @param name The new value of a ConfigNode. - */ + * @brief Sets the new value of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. + * @param name The new value of a ConfigNode. + */ Q_INVOKABLE void setNewValue (const QString & value); /** - * @brief The new metadata of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. - * @param name The new metadata of a ConfigNode. - */ + * @brief The new metadata of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. + * @param name The new metadata of a ConfigNode. + */ Q_INVOKABLE QVariantMap newMetadata () const; /** - * @brief Sets the new metadata of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. - * @param name The new metadata of a ConfigNode. - */ + * @brief Sets the new metadata of a ConfigNode. Used when creating EditKeyCommands and NewKeyCommands. + * @param name The new metadata of a ConfigNode. + */ Q_INVOKABLE void setNewMetadata (const QVariantMap & metadata); /** - * @brief The name of the ConfigNode that will be the root ConfigNode when importing a configuration from file. Used when creating ImportConfigurationCommands. - * @return The name of the ConfigNode that will be the root ConfigNode when importing a configuration from file. - */ + * @brief The name of the ConfigNode that will be the root ConfigNode when importing a configuration from file. Used when creating + * ImportConfigurationCommands. + * @return The name of the ConfigNode that will be the root ConfigNode when importing a configuration from file. + */ Q_INVOKABLE QString importName () const; /** - * @brief Sets the name of the ConfigNode that will be the root ConfigNode when importing a configuration from file. Used when creating ImportConfigurationCommands. - * @param name The name of the ConfigNode that will be the root ConfigNode when importing a configuration from file. - */ + * @brief Sets the name of the ConfigNode that will be the root ConfigNode when importing a configuration from file. Used when + * creating ImportConfigurationCommands. + * @param name The name of the ConfigNode that will be the root ConfigNode when importing a configuration from file. + */ Q_INVOKABLE void setImportName (const QString & name); /** - * @brief The format of the file that contains the configuration to import. Used when creating ImportConfigurationCommands. - * @return The format of the file that contains the configuration to import. - */ + * @brief The format of the file that contains the configuration to import. Used when creating ImportConfigurationCommands. + * @return The format of the file that contains the configuration to import. + */ Q_INVOKABLE QString format () const; /** - * @brief Sets the format of the file that contains the configuration to import. Used when creating ImportConfigurationCommands. - * @param form The format of the file that contains the configuration to import. - */ + * @brief Sets the format of the file that contains the configuration to import. Used when creating ImportConfigurationCommands. + * @param form The format of the file that contains the configuration to import. + */ Q_INVOKABLE void setFormat (const QString & form); /** - * @brief The system path of the file that contains the configuration to import. Used when creating ImportConfigurationCommands. - * @return The system path of the file that contains the configuration to import. - */ + * @brief The system path of the file that contains the configuration to import. Used when creating ImportConfigurationCommands. + * @return The system path of the file that contains the configuration to import. + */ Q_INVOKABLE QString file () const; /** - * @brief Sets the system path of the file that contains the configuration to import. Used when creating ImportConfigurationCommands. - * @param fil The system path of the file that contains the configuration to import. - */ + * @brief Sets the system path of the file that contains the configuration to import. Used when creating + * ImportConfigurationCommands. + * @param fil The system path of the file that contains the configuration to import. + */ Q_INVOKABLE void setFile (const QString & fil); /** - * @brief The merge strategies used when importing a configuration from file. Used when creating ImportConfigurationCommands. - * @return The merge strategies used when importing a configuration from file. - */ + * @brief The merge strategies used when importing a configuration from file. Used when creating ImportConfigurationCommands. + * @return The merge strategies used when importing a configuration from file. + */ Q_INVOKABLE QVariantList mergeStrategies () const; /** - * @brief Sets the merge strategies used when importing a configuration from file. Used when creating ImportConfigurationCommands. - * @param strategies The merge strategies used when importing a configuration from file. - */ + * @brief Sets the merge strategies used when importing a configuration from file. Used when creating ImportConfigurationCommands. + * @param strategies The merge strategies used when importing a configuration from file. + */ Q_INVOKABLE void setMergeStrategies (const QVariantList & strategies); /** - * @brief Sets all properties to empty values. - */ + * @brief Sets all properties to empty values. + */ Q_INVOKABLE void clearData (); private: diff --git a/src/tools/qt-gui/src/guibackend.hpp b/src/tools/qt-gui/src/guibackend.hpp index d787d8577ea..b5e322ca98d 100644 --- a/src/tools/qt-gui/src/guibackend.hpp +++ b/src/tools/qt-gui/src/guibackend.hpp @@ -38,10 +38,10 @@ class GUIBackend : public QObject } /** - * @brief Creates a new backend on a mountpoint. - * - * @param mountpoint The mountpoint of the new backend. - */ + * @brief Creates a new backend on a mountpoint. + * + * @param mountpoint The mountpoint of the new backend. + */ Q_INVOKABLE void createBackend (const QString & mountpoint); /** @@ -156,7 +156,8 @@ class GUIBackend : public QObject * @brief Triggers a messagedialog in the GUI. * @param title The title of the messagedialog in the GUI. * @param text The text of the messagedialog in the GUI.This is the text that will be initially shown to the user. - * @param detailedText The detailed text of the messagedialog in the GUI.The user will have to click on a button to access this text. + * @param detailedText The detailed text of the messagedialog in the GUI.The user will have to click on a button to access this + * text. */ void showMessage (QString title, QString text, QString detailedText) const; }; diff --git a/src/tools/qt-gui/src/guisettings.hpp b/src/tools/qt-gui/src/guisettings.hpp index 3ddddf360c9..f2391543bd7 100644 --- a/src/tools/qt-gui/src/guisettings.hpp +++ b/src/tools/qt-gui/src/guisettings.hpp @@ -45,9 +45,9 @@ class GUISettings : public QObject } /** - * @brief highlightColor The color of the highlight bar in the views. - * @return The color of the highlight bar in the views. - */ + * @brief highlightColor The color of the highlight bar in the views. + * @return The color of the highlight bar in the views. + */ QColor highlightColor () const; /** @@ -148,8 +148,8 @@ public slots: void useSystemIconThemeChanged (); /** - * @brief This signal is emitted if the viewermode setting has changed. - */ + * @brief This signal is emitted if the viewermode setting has changed. + */ void viewermodeChanged (); private: diff --git a/src/tools/qt-gui/src/markdownconverter/discountmarkdownconverter.cpp b/src/tools/qt-gui/src/markdownconverter/discountmarkdownconverter.cpp index 9b63227e791..a5f75bab0f9 100644 --- a/src/tools/qt-gui/src/markdownconverter/discountmarkdownconverter.cpp +++ b/src/tools/qt-gui/src/markdownconverter/discountmarkdownconverter.cpp @@ -1,34 +1,34 @@ /* -* Copyright 2013 Christian Loose -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* (1) Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* (2) Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* (3) The name of the author may not be used to -* endorse or promote products derived from this software without -* specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright 2013 Christian Loose + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * (1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * (2) Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * (3) The name of the author may not be used to + * endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #include "discountmarkdownconverter.h" extern "C" { diff --git a/src/tools/qt-gui/src/markdownconverter/discountmarkdownconverter.h b/src/tools/qt-gui/src/markdownconverter/discountmarkdownconverter.h index c219808c35d..f3c3f9f8ced 100644 --- a/src/tools/qt-gui/src/markdownconverter/discountmarkdownconverter.h +++ b/src/tools/qt-gui/src/markdownconverter/discountmarkdownconverter.h @@ -1,34 +1,34 @@ /* -* Copyright 2013 Christian Loose -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* (1) Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* (2) Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* (3) The name of the author may not be used to -* endorse or promote products derived from this software without -* specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright 2013 Christian Loose + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * (1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * (2) Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * (3) The name of the author may not be used to + * endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef DISCOUNTMARKDOWNCONVERTER_H #define DISCOUNTMARKDOWNCONVERTER_H diff --git a/src/tools/qt-gui/src/markdownconverter/markdownconverter.h b/src/tools/qt-gui/src/markdownconverter/markdownconverter.h index 0fd5d9381a7..62d8a4cbea3 100644 --- a/src/tools/qt-gui/src/markdownconverter/markdownconverter.h +++ b/src/tools/qt-gui/src/markdownconverter/markdownconverter.h @@ -1,34 +1,34 @@ /* -* Copyright 2013 Christian Loose -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* (1) Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* (2) Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* (3) The name of the author may not be used to -* endorse or promote products derived from this software without -* specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright 2013 Christian Loose + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * (1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * (2) Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * (3) The name of the author may not be used to + * endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef MARKDOWNCONVERTER_H #define MARKDOWNCONVERTER_H diff --git a/src/tools/qt-gui/src/markdownconverter/markdowndocument.h b/src/tools/qt-gui/src/markdownconverter/markdowndocument.h index 6cfaf2a0a67..fd67d585d73 100644 --- a/src/tools/qt-gui/src/markdownconverter/markdowndocument.h +++ b/src/tools/qt-gui/src/markdownconverter/markdowndocument.h @@ -1,34 +1,34 @@ /* -* Copyright 2013 Christian Loose -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* (1) Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* (2) Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* (3) The name of the author may not be used to -* endorse or promote products derived from this software without -* specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright 2013 Christian Loose + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * (1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * (2) Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * (3) The name of the author may not be used to + * endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef MARKDOWNDOCUMENT_H #define MARKDOWNDOCUMENT_H diff --git a/src/tools/qt-gui/src/markdownconverter/template/htmltemplate.cpp b/src/tools/qt-gui/src/markdownconverter/template/htmltemplate.cpp index b30eb09b0ef..40dc2e2f313 100644 --- a/src/tools/qt-gui/src/markdownconverter/template/htmltemplate.cpp +++ b/src/tools/qt-gui/src/markdownconverter/template/htmltemplate.cpp @@ -1,34 +1,34 @@ /* -* Copyright 2014 Christian Loose -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* (1) Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* (2) Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* (3) The name of the author may not be used to -* endorse or promote products derived from this software without -* specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright 2014 Christian Loose + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * (1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * (2) Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * (3) The name of the author may not be used to + * endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #include "htmltemplate.h" #include diff --git a/src/tools/qt-gui/src/markdownconverter/template/htmltemplate.h b/src/tools/qt-gui/src/markdownconverter/template/htmltemplate.h index 61dcf85a00e..24c92cd508e 100644 --- a/src/tools/qt-gui/src/markdownconverter/template/htmltemplate.h +++ b/src/tools/qt-gui/src/markdownconverter/template/htmltemplate.h @@ -1,34 +1,34 @@ /* -* Copyright 2014 Christian Loose -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* (1) Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* (2) Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* (3) The name of the author may not be used to -* endorse or promote products derived from this software without -* specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright 2014 Christian Loose + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * (1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * (2) Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * (3) The name of the author may not be used to + * endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef HTMLTEMPLATE_H #define HTMLTEMPLATE_H diff --git a/src/tools/qt-gui/src/markdownconverter/template/template.h b/src/tools/qt-gui/src/markdownconverter/template/template.h index e552e996417..9956b7457ba 100644 --- a/src/tools/qt-gui/src/markdownconverter/template/template.h +++ b/src/tools/qt-gui/src/markdownconverter/template/template.h @@ -1,34 +1,34 @@ /* -* Copyright 2014 Christian Loose -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* (1) Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* (2) Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in -* the documentation and/or other materials provided with the -* distribution. -* -* (3) The name of the author may not be used to -* endorse or promote products derived from this software without -* specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -* POSSIBILITY OF SUCH DAMAGE. -*/ + * Copyright 2014 Christian Loose + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * (1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * (2) Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * (3) The name of the author may not be used to + * endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ #ifndef TEMPLATE_H #define TEMPLATE_H diff --git a/src/tools/qt-gui/src/treeviewmodel.hpp b/src/tools/qt-gui/src/treeviewmodel.hpp index 86b6362166b..f1a4b5ebab4 100644 --- a/src/tools/qt-gui/src/treeviewmodel.hpp +++ b/src/tools/qt-gui/src/treeviewmodel.hpp @@ -158,16 +158,17 @@ class TreeViewModel : public QAbstractListModel Q_INVOKABLE QVariantMap get (const int & idx) const; /** - * @brief Find a search term in the model. - * - * @param term The search term of interest. - * - * @return A model which includes all ConfigNodes that have the search term in their name, value or metakeys. - */ + * @brief Find a search term in the model. + * + * @param term The search term of interest. + * + * @return A model which includes all ConfigNodes that have the search term in their name, value or metakeys. + */ Q_INVOKABLE QVariant find (const QString & term); /** - * @brief Inserts a new ConfigNode at a specified index into this TreeViewModel. This method is used if this TreeViewModel is holding metakeys. + * @brief Inserts a new ConfigNode at a specified index into this TreeViewModel. This method is used if this TreeViewModel is + * holding metakeys. * @param row The index the new ConfigNode is supposed to be inserted at. * @param key The key that holds the metadata. * @param name The name of the parent ConfigNode that holds the metadata. @@ -175,7 +176,8 @@ class TreeViewModel : public QAbstractListModel void insertMetaRow (int row, kdb::Key key, const QString & name); /** - * @brief Inserts a new ConfigNode at a specified index into this TreeViewModel. This method is used if this TreeViewModel is holding non metakey ConfigNodes. + * @brief Inserts a new ConfigNode at a specified index into this TreeViewModel. This method is used if this TreeViewModel is + * holding non metakey ConfigNodes. * @param row The index the new ConfigNode is supposed to be inserted at. * @param node The ConfigNode that is supposed to be inserted. * @param addParent Determines if the parentModel of the ConfigNode should be set with this TreeViewModel. @@ -198,7 +200,8 @@ class TreeViewModel : public QAbstractListModel Q_INVOKABLE kdb::Key createNewKey (const QString & path, const QString & value, const QVariantMap metaData); /** - * @brief Appends a ConfigNode to this TreeViewModel. At the time of insertion the index of the ConfigNode will be the largest in this model. + * @brief Appends a ConfigNode to this TreeViewModel. At the time of insertion the index of the ConfigNode will be the largest in + * this model. * * @param node The ConfigNode that is appended to this TreeViewModel. */ @@ -299,8 +302,8 @@ class TreeViewModel : public QAbstractListModel kdb::tools::merging::MergeConflictStrategy * getMergeStrategy (const QString & mergeStrategy); /** - * @brief Connect to system D-Bus - */ + * @brief Connect to system D-Bus + */ void connectDBus (); protected: @@ -311,7 +314,8 @@ class TreeViewModel : public QAbstractListModel * @brief Triggers a messagedialog in the GUI. * @param title The title of the messagedialog in the GUI. * @param text The text of the messagedialog in the GUI.This is the text that will be initially shown to the user. - * @param detailedText The detailed text of the messagedialog in the GUI.The user will have to click on a button to access this text. + * @param detailedText The detailed text of the messagedialog in the GUI.The user will have to click on a button to access this + * text. */ void showMessage (QString title, QString text, QString detailedText) const; /** diff --git a/src/tools/qt-gui/src/undomanager.hpp b/src/tools/qt-gui/src/undomanager.hpp index 254d4e70d7e..db1f4e9b40c 100644 --- a/src/tools/qt-gui/src/undomanager.hpp +++ b/src/tools/qt-gui/src/undomanager.hpp @@ -21,9 +21,10 @@ class QUndoStack; * @brief The UndoManager class * * To add your own command, implement a class that inherits from QUndoCommand. This class will have an undo and redo method respectively. - * ATTENTION: you have to put the code of THE FIRST ACTION into the redo method. Redo will be called automatically when the command is pushed onto the QUndoStack. - * If you put the code of the initial action somewhere in your code and then create the new command, the action will be performed twice. In the undo - * method you have to put the code that reverts the initial action. To execute the command, push your new command on the stack. + * ATTENTION: you have to put the code of THE FIRST ACTION into the redo method. Redo will be called automatically when the command is + * pushed onto the QUndoStack. If you put the code of the initial action somewhere in your code and then create the new command, the action + * will be performed twice. In the undo method you have to put the code that reverts the initial action. To execute the command, push your + * new command on the stack. */ class UndoManager : public QObject { diff --git a/src/tools/rest-backend/config.cpp b/src/tools/rest-backend/config.cpp index 7eee799fb3d..3a690762308 100644 --- a/src/tools/rest-backend/config.cpp +++ b/src/tools/rest-backend/config.cpp @@ -19,10 +19,10 @@ namespace kdbrest /** * @brief initializes application configuration variables - * + * * can use compile-time defaults if no dynamic configuration * is available. can also force the application to stop. - * + * * @param config the configuration to use * @return true in case of success, false otherwise */ diff --git a/src/tools/rest-backend/conversion_application.cpp b/src/tools/rest-backend/conversion_application.cpp index 102d0382de8..ba5ac263bc8 100644 --- a/src/tools/rest-backend/conversion_application.cpp +++ b/src/tools/rest-backend/conversion_application.cpp @@ -20,7 +20,7 @@ namespace kdbrest /** * @brief the constructor of the conversion endpoint application - * + * * @param srv a service container */ ConversionApp::ConversionApp (cppcms::service & srv) : cppcms::application (srv) @@ -34,7 +34,7 @@ ConversionApp::ConversionApp (cppcms::service & srv) : cppcms::application (srv) /** * @brief handler for the conversion resource - * + * * the function parses the content of a request, takes a snippet * and configuration format as input and converts the snippet into * the desired output format. diff --git a/src/tools/rest-backend/crypto.cpp b/src/tools/rest-backend/crypto.cpp index 28da00fc00b..c03e9a49545 100644 --- a/src/tools/rest-backend/crypto.cpp +++ b/src/tools/rest-backend/crypto.cpp @@ -21,11 +21,11 @@ namespace crypto /** * @brief encrypts a string with sha256 encryption - * + * * openssl based encryption function that utilizes the sha256 * encryption algorithm to encrypt a string. useful for password * encryption. - * + * * @param input the unencrypted input string * @param output the target string for the encrypted version * @return bool whether the encryption succeeded or not diff --git a/src/tools/rest-backend/database_application.cpp b/src/tools/rest-backend/database_application.cpp index 4d124f9c9b3..0c1c9bda052 100644 --- a/src/tools/rest-backend/database_application.cpp +++ b/src/tools/rest-backend/database_application.cpp @@ -31,7 +31,7 @@ namespace kdbrest /** * @brief the constructor of the database endpoint application - * + * * @param srv a service container */ DatabaseApp::DatabaseApp (cppcms::service & srv) : cppcms::application (srv) @@ -51,10 +51,10 @@ DatabaseApp::DatabaseApp (cppcms::service & srv) : cppcms::application (srv) /** * @brief root resource handler - * + * * the function delegates work to different helper methods * based on the HTTP method in the current request. - * + * * for a GET request, it serves a list of entries. * for a POST request, it attempts an insert. */ @@ -86,14 +86,14 @@ void DatabaseApp::getAllEntries () /** * @brief search resource handler - * + * * the function delegates work to different helper methods * based on the HTTP method in the current request. - * + * * for a GET request, it serves a list of entries, while * taking an additional GET parameter into account to limit * the resulting entry list. - * + * * @param keyPart a part of a possible entry key to reduce search space */ void DatabaseApp::getEntriesByPrefix (std::string keyPart) @@ -119,15 +119,15 @@ void DatabaseApp::getEntriesByPrefix (std::string keyPart) /** * @brief unique entry resource handler - * + * * the function delegates work to different helper methods * based on the HTTP method in the current request. * it operates on a well-specified unique resource. - * + * * for a GET request, it serves detailed information of an entry. * for a PUT request, it attempts an update on an entry. * for a DELETE request, it attempts the deletion of an entry. - * + * * @param key the unique snippet key of an entry resource */ void DatabaseApp::getUniqueEntry (std::string key) @@ -163,7 +163,7 @@ void DatabaseApp::getUniqueEntry (std::string key) /** * @brief handles the retrieval of a list of snippet entries - * + * * @param req a request * @param resp a response * @param keyPart a part of a possible entry key to reduce search space @@ -190,7 +190,7 @@ void DatabaseApp::handleGet (cppcms::http::request & req, cppcms::http::response /** * @brief handles a request to retrieve details for a single snippet entry - * + * * @param req a request * @param resp a response * @param key the unique snippet key of the entry which shall be retrieved @@ -281,7 +281,7 @@ void DatabaseApp::handleGetUnique (cppcms::http::request & req, cppcms::http::re /** * @brief handles a creation request for a new snippet entry - * + * * @param req a request * @param resp a response */ @@ -434,7 +434,7 @@ void DatabaseApp::handleDelete (cppcms::http::request & req, cppcms::http::respo /** * @brief attempts to parse input data from a request data pack - * + * * @param response a response for error output * @param requestData a json value containing all request post data * @param input_data the target struct to place input data in @@ -728,7 +728,7 @@ model::Entry DatabaseApp::buildAndValidateEntry (cppcms::http::request & req, cp /** * @brief extracts the max number of rows to print from a request - * + * * @param req a request * @return the max number of rows to print or the default value if not set */ @@ -757,7 +757,7 @@ inline int DatabaseApp::getMaxrows (cppcms::http::request & req) const /** * @brief extracts the offset parameter from a request - * + * * @param req a request * @return the offset extracted from the request parameter, if not set 0 */ @@ -782,7 +782,7 @@ inline int DatabaseApp::getOffset (cppcms::http::request & req) const /** * @brief filters a vector of snippet entries based on parameters of a request - * + * * @param req a request * @param entries the entry vector to filter */ @@ -808,7 +808,7 @@ inline void DatabaseApp::processFiltering (cppcms::http::request & req, std::vec /** * @brief sorts a vector of snippet entries based on parameters of a request - * + * * @param req a request * @param entries the entry vector to sort */ @@ -847,10 +847,10 @@ inline void DatabaseApp::processSorting (cppcms::http::request & req, std::vecto /** * @brief creates the output for a list of snippet entries - * + * * @note not all snippets in the list may actually be printed to the output. * which snippets are used in the output depends on additional parameters. - * + * * @param req a request * @param resp a response * @param entries a list of snippets, of which some may be used for the output diff --git a/src/tools/rest-backend/exceptions.hpp b/src/tools/rest-backend/exceptions.hpp index b16da010379..68715f1da7d 100644 --- a/src/tools/rest-backend/exceptions.hpp +++ b/src/tools/rest-backend/exceptions.hpp @@ -119,7 +119,7 @@ class NoCurrentUserException : public ElektraRestException /** * @brief exception to be used for plugins. - * + * * @param msg custom exception error message */ class FileformatPluginException : public ElektraRestException diff --git a/src/tools/rest-backend/main.cpp b/src/tools/rest-backend/main.cpp index d2c0697f2d8..05c71b92ad2 100644 --- a/src/tools/rest-backend/main.cpp +++ b/src/tools/rest-backend/main.cpp @@ -18,7 +18,7 @@ /** * @brief main function that bootstraps the application - * + * * @param argc command line argument count * @param argv command line argument list * @return 0 in case the service terminated gracefullly, diff --git a/src/tools/rest-backend/model_configformat.hpp b/src/tools/rest-backend/model_configformat.hpp index 39298a9d560..7622c04168a 100644 --- a/src/tools/rest-backend/model_configformat.hpp +++ b/src/tools/rest-backend/model_configformat.hpp @@ -27,7 +27,7 @@ namespace model /** * @brief model class for a pluginformat and config snippet - * + * * the model encapsulates a pluginformat and a config snippet in * string representation. the pluginformat tells in what format * the snippet is in. additionally, validation information is @@ -46,16 +46,16 @@ class ConfigFormat /** * @brief constructor based on pluginformat and configuration. - * + * * this constructor is used to represent a fully converted configuration - * along with its file format, so it can be used for further - * operations. - * - * @param pf The PluginFormat to be used - * @param cfg The configuration in the given format as string + * along with its file format, so it can be used for further + * operations. + * + * @param pf The PluginFormat to be used + * @param cfg The configuration in the given format as string * @param validated If the configuration snippet has successfully * passed a validation round-trip - */ + */ ConfigFormat (const PluginFormat & pf, const std::string & cfg, const bool validated = false) : m_pluginformat (pf), m_config (cfg), m_validated (validated) { @@ -63,19 +63,19 @@ class ConfigFormat /** * @brief getter for the pluginformat - * - * @return PluginFormat that is used - */ + * + * @return PluginFormat that is used + */ PluginFormat getPluginformat () const { return m_pluginformat; } /** - * @brief getter for the converted configuration as string - * - * @return Configuration as string - */ + * @brief getter for the converted configuration as string + * + * @return Configuration as string + */ std::string getConfig () const { return m_config; @@ -83,7 +83,7 @@ class ConfigFormat /** * @brief getter for the validation status - * + * * @return True if conversion has passed validation */ bool isValidated () const @@ -93,7 +93,7 @@ class ConfigFormat /** * @brief setter for validation status - * + * * @param val If the conversion has passed validation */ void setValidated (bool val) diff --git a/src/tools/rest-backend/model_entry.hpp b/src/tools/rest-backend/model_entry.hpp index cf86a29f7b9..3350a25a310 100644 --- a/src/tools/rest-backend/model_entry.hpp +++ b/src/tools/rest-backend/model_entry.hpp @@ -40,7 +40,7 @@ namespace model /** * @brief model class for a configuration snippet entry - * + * * this class encapsulates all information that belongs to * a configuration snippet entry, including the snippet itself. */ @@ -49,24 +49,24 @@ class Entry : public kdb::Key public: /** - * @brief constructs an Entry object based on a kdb::Key object - * - * @param key An object of type kdb::Key - */ + * @brief constructs an Entry object based on a kdb::Key object + * + * @param key An object of type kdb::Key + */ Entry (kdb::Key & k) : kdb::Key (k) { } /** * @brief constructs an Entry based on its public key - * - * Constructs an Entry object based on a key name (string). - * It implicitely constructs a kdb::Key object by super(). - * Adds the base config repository path to the entry name, so - * it is a valid key to be used with KDB. - * - * @param keyName A string to be used as key name - */ + * + * Constructs an Entry object based on a key name (string). + * It implicitely constructs a kdb::Key object by super(). + * Adds the base config repository path to the entry name, so + * it is a valid key to be used with KDB. + * + * @param keyName A string to be used as key name + */ Entry (std::string entryName) : kdb::Key (Config::instance ().getConfig ().get ("kdb.path.configs") + std::string ("/") + entryName, KEY_END) { @@ -74,17 +74,17 @@ class Entry : public kdb::Key /** * @brief constructs an Entry based on its public key parts - * - * Constructs an Entry object based on four key parts (strings). - * It implicitely constructs a kdb::Key object by super(). - * It also adds the base config repository path to the entry name, so - * it is a valid key to be used with KDB. - * - * @param organization The organization for the Entry - * @param application The application for the Entry - * @param scope The scope for the Entry - * @param slug The unique slug for the Entry - */ + * + * Constructs an Entry object based on four key parts (strings). + * It implicitely constructs a kdb::Key object by super(). + * It also adds the base config repository path to the entry name, so + * it is a valid key to be used with KDB. + * + * @param organization The organization for the Entry + * @param application The application for the Entry + * @param scope The scope for the Entry + * @param slug The unique slug for the Entry + */ Entry (const std::string & organization, const std::string & application, const std::string & scope, const std::string & slug) : kdb::Key (Config::instance ().getConfig ().get ("kdb.path.configs") + std::string ("/") + organization + std::string ("/") + application + std::string ("/") + scope + std::string ("/") + slug, @@ -94,13 +94,13 @@ class Entry : public kdb::Key /** * @brief attempts to add a subkey to the entry key - * + * * If the secure flag is set, does check if the given * key is really a sub key. If not, nothing is added. - * + * * @param key The key do be added as sub key * @param secure Whether to check if @p k is real subkey - */ + */ void addSubkey (kdb::Key k, bool secure = false) { if (!secure || k.isBelow (static_cast (*this))) @@ -111,10 +111,10 @@ class Entry : public kdb::Key /** * @brief attempts to add all keys of the keyset as subkey - * + * * If the secure flag is set, it is checked whether the keys * in the keyset are really subkeys. otherwise, nothing is added. - * + * * @param ks a keyset that should be added to the entry subkeys * @param secure whether to check if @p ks keys are really subkeys */ @@ -128,14 +128,14 @@ class Entry : public kdb::Key /** * @brief getter for the subkeys keyset - * - * Getter for the kdb::KeySet containing all added sub keys. - * Returned will be a reference. That means changes to the - * subkeys vector will affect the entry. This allows for - * removal of subkeys. - * - * @return kdb::KeySet with all sub keys - */ + * + * Getter for the kdb::KeySet containing all added sub keys. + * Returned will be a reference. That means changes to the + * subkeys vector will affect the entry. This allows for + * removal of subkeys. + * + * @return kdb::KeySet with all sub keys + */ kdb::KeySet & getSubkeys () { return m_subkeys; @@ -143,13 +143,13 @@ class Entry : public kdb::Key /** * @brief getter for the public part of the key name - * - * Getter for the public name of the entry. That is the key name - * without the repository prefix. So if all keys are stored - * under a certain path, this path is erased from the key name. - * - * @return Key name without the storage path prefix - */ + * + * Getter for the public name of the entry. That is the key name + * without the repository prefix. So if all keys are stored + * under a certain path, this path is erased from the key name. + * + * @return Key name without the storage path prefix + */ std::string getPublicName () const { return this->getName ().erase (0, Config::instance ().getConfig ().get ("kdb.path.configs").length () + 1); @@ -157,17 +157,17 @@ class Entry : public kdb::Key /** * @brief getter for the splitted public key part - * - * Getter for the public name parts of the entry. That is a - * vector containing the four entry parts (organization, - * application, scope and unique slug). - * The public name is split at the separator "/" and the - * resulting parts are added to the vector in chronological order, - * so the first part of the entry name (key name) will also be - * the first entry in the resulting vector. - * - * @return vector containing all four public key parts - */ + * + * Getter for the public name parts of the entry. That is a + * vector containing the four entry parts (organization, + * application, scope and unique slug). + * The public name is split at the separator "/" and the + * resulting parts are added to the vector in chronological order, + * so the first part of the entry name (key name) will also be + * the first entry in the resulting vector. + * + * @return vector containing all four public key parts + */ std::vector getPublicNameParts () const { std::vector result; @@ -178,61 +178,61 @@ class Entry : public kdb::Key /** * @brief getter for the organization part of the public name - * - * @return The organization of the entry - */ + * + * @return The organization of the entry + */ std::string getOrganization () const { return this->getPublicNameParts ().at (0); } /** - * @brief getter for the application part of the public name - * - * @return The application of the entry - */ + * @brief getter for the application part of the public name + * + * @return The application of the entry + */ std::string getApplication () const { return this->getPublicNameParts ().at (1); } /** - * @brief getter for the scope part of the public name - * + * @brief getter for the scope part of the public name + * * @return The scope of the entry - */ + */ std::string getScope () const { return this->getPublicNameParts ().at (2); } /** - * @brief getter for the unique slug part of the public name - * - * @return The unique slug of the entry - */ + * @brief getter for the unique slug part of the public name + * + * @return The unique slug of the entry + */ std::string getSlug () const { return this->getPublicNameParts ().at (3); } /** - * @brief setter for the author of the entry - * - * @note the author is stored as meta data of the key. - * - * @param author The author as string - */ + * @brief setter for the author of the entry + * + * @note the author is stored as meta data of the key. + * + * @param author The author as string + */ void setAuthor (const std::string & author) { this->setMeta (ELEKTRA_REST_MODEL_ENTRY_META_AUTHOR, author); } /** - * @brief getter for the author of the entry - * - * @return The author as string - */ + * @brief getter for the author of the entry + * + * @return The author as string + */ std::string getAuthor () const { if (this->hasMeta (ELEKTRA_REST_MODEL_ENTRY_META_AUTHOR)) @@ -242,22 +242,22 @@ class Entry : public kdb::Key } /** - * @brief setter for the creation date of the entry - * - * @note the creation date is stored as timestamp as meta data of the key. - * - * @param created_at The creation date as long - */ + * @brief setter for the creation date of the entry + * + * @note the creation date is stored as timestamp as meta data of the key. + * + * @param created_at The creation date as long + */ void setCreatedAt (const long created_at) { this->setMeta (ELEKTRA_REST_MODEL_ENTRY_META_CREATEDAT, created_at); } /** - * @brief getter for the creation date of the entry - * - * @return The creation date as timestamp as long - */ + * @brief getter for the creation date of the entry + * + * @return The creation date as timestamp as long + */ long getCreatedAt () const { if (this->hasMeta (ELEKTRA_REST_MODEL_ENTRY_META_CREATEDAT)) @@ -267,22 +267,22 @@ class Entry : public kdb::Key } /** - * @brief setter for the title of the entry - * - * @note the title is stored as meta data of the key. - * - * @param title The title as string - */ + * @brief setter for the title of the entry + * + * @note the title is stored as meta data of the key. + * + * @param title The title as string + */ void setTitle (const std::string & title) { this->setMeta (ELEKTRA_REST_MODEL_ENTRY_META_TITLE, title); } /** - * @brief getter for the title of the entry - * - * @return The title as string - */ + * @brief getter for the title of the entry + * + * @return The title as string + */ std::string getTitle () const { if (this->hasMeta (ELEKTRA_REST_MODEL_ENTRY_META_TITLE)) @@ -292,22 +292,22 @@ class Entry : public kdb::Key } /** - * @brief setter for the description of the entry - * - * @note the description is stored as meta data of the key. - * - * @param desc The description as string - */ + * @brief setter for the description of the entry + * + * @note the description is stored as meta data of the key. + * + * @param desc The description as string + */ void setDescription (const std::string & desc) { this->setMeta (ELEKTRA_REST_MODEL_ENTRY_META_DESCRIPTION, desc); } /** - * @brief getter for the description of the entry - * - * @return The description as string - */ + * @brief getter for the description of the entry + * + * @return The description as string + */ std::string getDescription () const { if (this->hasMeta (ELEKTRA_REST_MODEL_ENTRY_META_DESCRIPTION)) @@ -317,23 +317,23 @@ class Entry : public kdb::Key } /** - * @brief setter for the tags of the entry - * - * @note the tags are stored as a single string as meta data of - * the key. - * - * @param tags A vector containing all tags as string - */ + * @brief setter for the tags of the entry + * + * @note the tags are stored as a single string as meta data of + * the key. + * + * @param tags A vector containing all tags as string + */ void setTags (const std::vector & tags) { this->setMeta (ELEKTRA_REST_MODEL_ENTRY_META_TAGS, boost::algorithm::join (tags, " ")); } /** - * @brief getter for the tags of the entry - * - * @return A vector containing all tags as string - */ + * @brief getter for the tags of the entry + * + * @return A vector containing all tags as string + */ std::vector getTags () const { if (this->hasMeta (ELEKTRA_REST_MODEL_ENTRY_META_TAGS)) @@ -352,11 +352,11 @@ class Entry : public kdb::Key } /** - * @brief checks if the entry is tagged with a certain tag - * - * @param tag A string repesenting a tag to be checked for - * @return True if the entry is tagged with the tag - */ + * @brief checks if the entry is tagged with a certain tag + * + * @param tag A string repesenting a tag to be checked for + * @return True if the entry is tagged with the tag + */ bool hasTag (const std::string & tag) const { std::vector tags = this->getTags (); @@ -365,7 +365,7 @@ class Entry : public kdb::Key /** * @brief setter for the upload plugin of the entry - * + * * @param format The plugin name as string */ void setUploadPlugin (const std::string & plugin) @@ -374,10 +374,10 @@ class Entry : public kdb::Key } /** - * @brief getter for the upload plugin of the entry - * - * @return The plugin name as string - */ + * @brief getter for the upload plugin of the entry + * + * @return The plugin name as string + */ std::string getUploadPlugin () const { if (this->hasMeta (ELEKTRA_REST_MODEL_ENTRY_META_UPLOADPLUGIN)) @@ -387,22 +387,22 @@ class Entry : public kdb::Key } /** - * @brief setter for the value of the entry - * - * @note the value is stored as the value of the key. - * - * @param content A string containing the value - */ + * @brief setter for the value of the entry + * + * @note the value is stored as the value of the key. + * + * @param content A string containing the value + */ void setValue (std::string & content) { this->set (content); } /** - * @brief getter for the value of the entry - * - * @return A string containing the value - */ + * @brief getter for the value of the entry + * + * @return A string containing the value + */ std::string getValue () const { return this->get (); @@ -410,7 +410,7 @@ class Entry : public kdb::Key /** * @brief compares two entries based on their key - * + * * @param l left entry * @param r right entry * @return true if public key name of l < r @@ -422,7 +422,7 @@ class Entry : public kdb::Key /** * @brief compares two entries based on their title - * + * * @param l left entry * @param r right entry * @return true if title of l < r @@ -434,7 +434,7 @@ class Entry : public kdb::Key /** * @brief compares two entries based on their creation date - * + * * @param l left entry * @param r right entry * @return true if creation date of l < r @@ -446,7 +446,7 @@ class Entry : public kdb::Key /** * @brief compares two entries based on their author - * + * * @param l left entry * @param r right entry * @return true if author of l < r @@ -458,7 +458,7 @@ class Entry : public kdb::Key /** * @brief compares two entries based on their organization - * + * * @param l left entry * @param r right entry * @return true if organization of l < r @@ -470,7 +470,7 @@ class Entry : public kdb::Key /** * @brief compares two entries based on their application - * + * * @param l left entry * @param r right entry * @return true if application of l < r @@ -482,7 +482,7 @@ class Entry : public kdb::Key /** * @brief compares two entries based on their scope - * + * * @param l left entry * @param r right entry * @return true if scope of l < r @@ -494,7 +494,7 @@ class Entry : public kdb::Key /** * @brief compares two entries based on their slug - * + * * @param l left entry * @param r right entry * @return true if slug of l < r diff --git a/src/tools/rest-backend/model_importedconfig.hpp b/src/tools/rest-backend/model_importedconfig.hpp index bdbd7c53cba..336e2267f64 100644 --- a/src/tools/rest-backend/model_importedconfig.hpp +++ b/src/tools/rest-backend/model_importedconfig.hpp @@ -26,7 +26,7 @@ namespace model /** * @brief model class for imported configuration snippets - * + * * this class encapsulates a pluginformat and a keyset representing * a configuration snippet. */ @@ -36,33 +36,33 @@ class ImportedConfig public: /** * @brief constructor based on a PluginFormat and keyset - * - * It is used to represent a fully imported configuration - * along with its file format, so it can be used for further - * operations. - * - * @param pf The PluginFormat to be used - * @param ks The configuration as kdb::Keys in a kdb::KeySet - */ + * + * It is used to represent a fully imported configuration + * along with its file format, so it can be used for further + * operations. + * + * @param pf The PluginFormat to be used + * @param ks The configuration as kdb::Keys in a kdb::KeySet + */ ImportedConfig (const PluginFormat & pf, const kdb::KeySet & ks) : m_pluginformat (pf), m_ks (ks) { } /** - * @brief getter for the PluginFormat - * - * @return PluginFormat that is used - */ + * @brief getter for the PluginFormat + * + * @return PluginFormat that is used + */ PluginFormat getPluginformat () const { return m_pluginformat; } /** - * @brief getter for the kdb::KeySet - * - * @return kdb::KeySet that contains the configuration keys - */ + * @brief getter for the kdb::KeySet + * + * @return kdb::KeySet that contains the configuration keys + */ kdb::KeySet getKeySet () const { return m_ks; diff --git a/src/tools/rest-backend/model_pluginformat.hpp b/src/tools/rest-backend/model_pluginformat.hpp index d9e4ab279dc..5dd08a9bc3b 100644 --- a/src/tools/rest-backend/model_pluginformat.hpp +++ b/src/tools/rest-backend/model_pluginformat.hpp @@ -22,7 +22,7 @@ namespace model /** * @brief model class for a plugin name along with its format - * + * * this class encapsulates all information that is necessary to * find a plugin and configuration snippets supported by it. */ @@ -38,10 +38,10 @@ class PluginFormat } /** - * @brief copy constructor - * - * @param pf The foreign PluginFormat - */ + * @brief copy constructor + * + * @param pf The foreign PluginFormat + */ PluginFormat (const PluginFormat & pf) { m_fileformat = pf.m_fileformat; @@ -52,11 +52,11 @@ class PluginFormat /** * @brief constructor based on the format and the pluginname - * - * @param format The fileformat as string (e.g. ini, xml) - * @param plugin The pluginname as string (e.g. ni, xmltool) + * + * @param format The fileformat as string (e.g. ini, xml) + * @param plugin The pluginname as string (e.g. ni, xmltool) * @param statuses The plugin statuses as vector (e.g. maintained, limited) - */ + */ PluginFormat (const std::string & format, const std::string & plugin, const std::vector statuses = std::vector (), const kdb::KeySet config = kdb::KeySet ()) { @@ -71,20 +71,20 @@ class PluginFormat } /** - * @brief getter for the file format as string - * - * @return File format as string - */ + * @brief getter for the file format as string + * + * @return File format as string + */ std::string getFileformat () const { return m_fileformat; } /** - * @brief getter for the plugin name as string - * - * @return Plugin name as string - */ + * @brief getter for the plugin name as string + * + * @return Plugin name as string + */ std::string getPluginname () const { return m_pluginname; @@ -92,13 +92,13 @@ class PluginFormat /** * @brief getter for the plugin name with appended config params - * + * * example: * - plugin name: simpleini * - plugin config: * system/format = % % * - returns: simpleini format=% % - * + * * @return plugin name with config params */ std::string getPluginnameWithConfig () const @@ -113,7 +113,7 @@ class PluginFormat /** * @brief getter for the plugin statuses as vector - * + * * @return All plugin statuses in a vector */ std::vector getPluginstatuses () const @@ -123,7 +123,7 @@ class PluginFormat /** * @brief getter for the plugin configuration - * + * * @return A keyset containing the plugin config */ const kdb::KeySet getConfig () const diff --git a/src/tools/rest-backend/model_user.hpp b/src/tools/rest-backend/model_user.hpp index 4436435003a..050f56f8208 100644 --- a/src/tools/rest-backend/model_user.hpp +++ b/src/tools/rest-backend/model_user.hpp @@ -34,7 +34,7 @@ namespace model /** * @brief model class for a REST service user - * + * * this class encapsulates all information that belongs to a user. */ class User : public kdb::Key @@ -42,37 +42,37 @@ class User : public kdb::Key public: /** - * @brief constructs an User object based on a kdb::Key object - * - * @param key A kdb::Key object - */ + * @brief constructs an User object based on a kdb::Key object + * + * @param key A kdb::Key object + */ User (const kdb::Key & k) : kdb::Key (k) { } /** - * @brief constructs an User object based on a username - * - * It implicitely constructs a kdb::Key object by super(). - * Adds the base user repository path to the username, so it - * is a valid key to be use with KDB. - * - * @param username The username to be used for the key - */ + * @brief constructs an User object based on a username + * + * It implicitely constructs a kdb::Key object by super(). + * Adds the base user repository path to the username, so it + * is a valid key to be use with KDB. + * + * @param username The username to be used for the key + */ User (const std::string username) : kdb::Key (Config::instance ().getConfig ().get ("kdb.path.users") + std::string ("/") + username, KEY_END) { } /** - * @brief attempts to add a key as subkey of the entry - * + * @brief attempts to add a key as subkey of the entry + * * If the secure flag is set, does check if the given * key is really a sub key. If not, nothing is added. - * + * * @param key The key do be added as sub key * @param secure Whether to check if @p k is real subkey - */ + */ void addSubkey (kdb::Key k, bool secure = false) { if (!secure || k.isBelow (static_cast (*this))) @@ -82,29 +82,29 @@ class User : public kdb::Key } /** - * @brief getter for the kdb::KeySet containing all added sub keys - * - * Returned will be a reference. That means changes to the - * subkeys keyset will affect the user. This allows for - * removal of subkeys. - * - * @return kdb::KeySet with all sub keys - */ + * @brief getter for the kdb::KeySet containing all added sub keys + * + * Returned will be a reference. That means changes to the + * subkeys keyset will affect the user. This allows for + * removal of subkeys. + * + * @return kdb::KeySet with all sub keys + */ kdb::KeySet & getSubkeys () { return this->m_subkeys; } /** - * @brief getter for a sub key by name - * - * If no sub key with the given name exists, an exception + * @brief getter for a sub key by name + * + * If no sub key with the given name exists, an exception * will be thrown. - * - * @param name The name of the sub key to look for - * @return The requested sub key - * @throws kdbrest::exception::SubkeyNotFoundException - */ + * + * @param name The name of the sub key to look for + * @return The requested sub key + * @throws kdbrest::exception::SubkeyNotFoundException + */ kdb::Key getSubkey (const std::string name) const { for (auto elem : this->m_subkeys) @@ -118,40 +118,40 @@ class User : public kdb::Key } /** - * @brief getter for the username - * - * @return Username as string - */ + * @brief getter for the username + * + * @return Username as string + */ std::string getUsername () const { return this->getName ().erase (0, Config::instance ().getConfig ().get ("kdb.path.users").length () + 1); } /** - * @brief setter for the password hash - * - * @param passwordHash Password hash as string - */ + * @brief setter for the password hash + * + * @param passwordHash Password hash as string + */ void setPasswordHash (std::string passwordHash) { this->set (passwordHash); } /** - * @brief getter for the password hash - * - * @return Password hash as string - */ + * @brief getter for the password hash + * + * @return Password hash as string + */ std::string getPasswordHash () const { return this->get (); } /** - * @brief setter for the email - * - * @param email Email as string - */ + * @brief setter for the email + * + * @param email Email as string + */ void setEmail (std::string email) { kdb::Key k; @@ -168,10 +168,10 @@ class User : public kdb::Key } /** - * @brief getter for the email - * - * @return Email as string - */ + * @brief getter for the email + * + * @return Email as string + */ std::string getEmail () const { try @@ -186,14 +186,14 @@ class User : public kdb::Key } /** - * @brief setter for the rank - * - * The rank may be anything between (including) + * @brief setter for the rank + * + * The rank may be anything between (including) * ELEKTRA_REST_USER_MIN_RANK and * ELEKTRA_REST_USER_MAX_RANK - * - * @param rank Rank as integer - */ + * + * @param rank Rank as integer + */ void setRank (int rank) { kdb::Key k; @@ -210,13 +210,13 @@ class User : public kdb::Key } /** - * @brief getter for the rank - * + * @brief getter for the rank + * * If no rank is set yet, the default rank for users * will be returned. * - * @return Rank as integer - */ + * @return Rank as integer + */ int getRank () const { try @@ -231,10 +231,10 @@ class User : public kdb::Key } /** - * @brief setter for the creation date - * - * @param created_at Timestamp when the user has been created - */ + * @brief setter for the creation date + * + * @param created_at Timestamp when the user has been created + */ void setCreatedAt (const long created_at) { kdb::Key k; @@ -251,10 +251,10 @@ class User : public kdb::Key } /** - * @brief getter for the creation date - * - * @return Timestamp when the user has been created - */ + * @brief getter for the creation date + * + * @return Timestamp when the user has been created + */ long getCreatedAt () const { try @@ -270,7 +270,7 @@ class User : public kdb::Key /** * @brief compares two users based on their username - * + * * @param l left user * @param r right user * @return true if the username of l < r @@ -282,7 +282,7 @@ class User : public kdb::Key /** * @brief compares two users based on their email - * + * * @param l left user * @param r right user * @return true if the email of l < r @@ -294,7 +294,7 @@ class User : public kdb::Key /** * @brief compares two users based on their creation date - * + * * @param l left user * @param r right user * @return true if the creation date of l < r @@ -306,7 +306,7 @@ class User : public kdb::Key /** * @brief compares two users based on their rank - * + * * @param l left user * @param r right user * @return true if the rank of l < r diff --git a/src/tools/rest-backend/root_application.cpp b/src/tools/rest-backend/root_application.cpp index 5e7695caa95..54b9157e70c 100644 --- a/src/tools/rest-backend/root_application.cpp +++ b/src/tools/rest-backend/root_application.cpp @@ -59,7 +59,7 @@ RootApp::RootApp (cppcms::service & srv) : cppcms::application (srv) /** * @brief handler for the root of the whole rest service - * + * * responds with a redirect to a configurable link, should be * the API description. */ @@ -93,7 +93,7 @@ void RootApp::welcome () /** * @brief handler for the version resource of the endpoint - * + * * responds with versions for the API and the used Elektra version. */ void RootApp::version () @@ -175,7 +175,7 @@ void RootApp::version () /** * @brief helper method that allows to set custom data within the response. - * + * * @param response a response * @param data a plain string containing the response body data * @param content_type the content type to be used for the response @@ -193,7 +193,7 @@ void RootApp::setOkRaw (cppcms::http::response & response, const std::string dat /** * @brief helper method that allows to set json data within the response. - * + * * @param response a response * @param data json data to be used as body in response * @param content_type the content type to be used for the response @@ -212,7 +212,7 @@ void RootApp::setOk (cppcms::http::response & response, cppcms::json::value & da /** * @brief helper method that allows to set a message and a localization string within the response. - * + * * @param response a response * @param message a message, i.e. success message because of http 200 * @param loca a localization string, may not contain spaces (e.g. USER_CREATED_SUCCESSFULLY) @@ -224,7 +224,7 @@ void RootApp::setOk (cppcms::http::response & response, const std::string messag /** * @brief helper method that allows to set a method not allowed response - * + * * @param response a response * @param message a message, i.e. method not allowed message because of http 405 * @param loca a localization string, may not contain spaces (e.g. METHOD_NOT_ALLOWED) @@ -236,7 +236,7 @@ void RootApp::setMethodNotAllowed (cppcms::http::response & response, const std: /** * @brief helper method that allows to set a not acceptable response - * + * * @param response a response * @param message a message, i.e. not acceptable message because of http 406 * @param loca a localization string, may not contain spaces (e.g. UNSUPPORTED_CONTENT_TYPE) @@ -248,7 +248,7 @@ void RootApp::setNotAcceptable (cppcms::http::response & response, const std::st /** * @brief helper method that allows to set a unprocessable entity response - * + * * @param response a response * @param message a message, i.e. unprocessable entity message because of http 422 * @param loca a localization string, may not contain spaces (e.g. USER_ALREADY_EXISTS) @@ -260,7 +260,7 @@ void RootApp::setUnprocessableEntity (cppcms::http::response & response, const s /** * @brief helper method that allows to set an unauthorized response - * + * * @param response a response * @param message a message, i.e. unauthorized message because of http 401 * @param loca a localization string, may not contain spaces (e.g. NEED_AUTHENTICATION) @@ -272,7 +272,7 @@ void RootApp::setUnauthorized (cppcms::http::response & response, const std::str /** * @brief helper method that allows to set a bad request response - * + * * @param response a response * @param message a message, i.e. bad request message because of http 400 * @param loca a localization string, may not contain spaces (e.g. USER_MISSING_USERNAME) @@ -284,7 +284,7 @@ void RootApp::setBadRequest (cppcms::http::response & response, const std::strin /** * @brief helper method that allows to set a not found response - * + * * @param response a response * @param message a message, i.e. not found message because of http 404 * @param loca a localization string, may not contain spaces (e.g. USER_DOES_NOT_EXIST) @@ -296,7 +296,7 @@ void RootApp::setNotFound (cppcms::http::response & response, const std::string /** * @brief helper method that allows to set an internal server error response - * + * * @param response a response * @param message a message, i.e. internal server error message because of http 500 * @param loca a localization string, may not contain spaces (e.g. AUTH_CREATE_TOKEN_ERROR) @@ -308,7 +308,7 @@ void RootApp::setInternalServerError (cppcms::http::response & response, const s /** * @brief helper method that allows to send a redirect response containing a location header - * + * * @param response a response * @param location the location the browser is sent to, should be an URL */ @@ -320,7 +320,7 @@ void RootApp::setSeeOther (cppcms::http::response & response, const std::string /** * @brief helper method that attempts to parse post data as json - * + * * @param request a request * @return a json value containing the parsed post data */ @@ -341,7 +341,7 @@ cppcms::json::value RootApp::parsePostDataAsJson (cppcms::http::request & reques /** * @brief helper method that sets the http status of a response, as well as an error message and loca string - * + * * @param response a response * @param status the http status to set * @param message a message to use in response body @@ -367,7 +367,7 @@ void RootApp::setHttpStatus (cppcms::http::response & response, const int status /** * @brief helper method that sets CORS headers for a response, as well as allowed methods - * + * * @param response a response * @param allowedMethods a comma separated list of allowed methods, e.g. "GET,POST,PUT,OPTIONS" */ diff --git a/src/tools/rest-backend/service.hpp b/src/tools/rest-backend/service.hpp index a524e9a43ff..dddab16671e 100644 --- a/src/tools/rest-backend/service.hpp +++ b/src/tools/rest-backend/service.hpp @@ -41,10 +41,10 @@ namespace service /** * @brief service offering search and filter functionality - * + * * Service that is responsible for doing search specific tasks such as * filtering a result set based on search parameters. - * + * * It is designed as singleton, so all applications using it will share * the same instance, which allows for further logic if necessary. */ @@ -68,12 +68,12 @@ class SearchEngine : public singleton /** * @brief service offering storage functionality - * + * * Service that is responsible for storing configuration and user * entries in the kdb database. Besides storing it is also capable of * updating and deleting of single entries, as well as looking up * single and multiple entries at the same time. - * + * * It is designed as singleton, so all applications using it will share * the same instance, which allows for further logic if necessary. */ @@ -119,10 +119,10 @@ class StorageEngine : public singleton /** * @brief service offering conversion functionality - * + * * Service that is responsible for converting configuration entries * into the various configuration formats with help of enabled plugins. - * + * * It is designed as singleton, so all applications using it will share * the same instance, which allows for further logic if necessary. */ @@ -170,7 +170,7 @@ const std::string REGEX_CHECK_KEY_IS_ARRAY = /** * @brief service offering application configuration retrieval - * + * * this service can be used to load the application configuration * on start up. it is based on elektra. */ diff --git a/src/tools/rest-backend/service_config.cpp b/src/tools/rest-backend/service_config.cpp index 7168ace1287..da30ba20b22 100644 --- a/src/tools/rest-backend/service_config.cpp +++ b/src/tools/rest-backend/service_config.cpp @@ -22,10 +22,10 @@ namespace service /** * @brief can be used to load the configuration of the whole application - * + * * the configuration is loaded from the key database provided by elektra. * the result can be used to bootstrap the application (cppcms service). - * + * * @param profile the profile for which the configuration should be loaded * @return the loaded configuration as cppcms::json::value */ @@ -46,10 +46,10 @@ cppcms::json::value ConfigEngine::loadApplicationConfiguration (const std::strin /** * @brief can be used to transform a kdb::KeySet into cppcms::json::value - * + * * will iterate through the keyset and use a helper method to add the key * values to the json::value - * + * * @param ks the keyset that needs to be transformed * @return a cppcms::json::value containing the configuration from the keyset */ @@ -84,10 +84,10 @@ cppcms::json::value ConfigEngine::transformKeysetToJsonValue (const kdb::KeySet /** * @brief can be used to set a key value to a cppcms::json::value - * + * * checks the path for an array and recursively sets the value then. * for objects the path is simply set. - * + * * @param config the current configuration value * @param path remaining path to set * @param key the elektra key containing the value to set @@ -153,10 +153,10 @@ void ConfigEngine::handleValueInsertion (cppcms::json::value & config, const std /** * @brief tries to retrieve the correct key value (correct format/type) and stores it - * + * * if the key does not have meta data specifying the type, it will first be * tried to convert the value as number, then as string - * + * * @param config a json value * @param key the key which holds the value to store */ diff --git a/src/tools/rest-backend/service_convert.cpp b/src/tools/rest-backend/service_convert.cpp index e09802c14ff..cb5f019a54a 100644 --- a/src/tools/rest-backend/service_convert.cpp +++ b/src/tools/rest-backend/service_convert.cpp @@ -117,7 +117,7 @@ model::PluginFormat ConvertEngine::findSuitablePlugin (const std::string & forma /** * @brief loads a list of enabled formats and plugins - * + * * Loads the configuration for the enabled formats from the * key database, parses them and stores them as enabled formats. * @@ -165,7 +165,7 @@ std::vector ConvertEngine::loadEnabledFormats () /** * @brief export entry to specific configuration format - * + * * If the format is not supported, an exception is thrown. * * @param format a format that shall be used for the export @@ -193,7 +193,7 @@ model::ConfigFormat ConvertEngine::exportTo (const std::string format, model::En /** * @brief can be used to export an entry with the specified plugin. - * + * * @note This function does a round-trip check to validated whether * the snippet was exported successfully (completely) without * losing any information. @@ -284,7 +284,7 @@ model::ConfigFormat ConvertEngine::exportTo (const model::PluginFormat & plugin, /** * @brief Can be used to convert an entry into all enabled file formats. - * + * * The sub keys of the entry will be taken and converted into the * enabled formats. To do this, a temporary file will be used, because * the storage plugins, which do the conversion, can operate on files @@ -322,7 +322,7 @@ std::vector ConvertEngine::exportToAll (model::Entry & entr /** * @brief converts a config string with format into an entry object - * + * * Can be used to convert a configuration given as string into * a usable kdb::KeySet which is stored in an ImportedConfig model. * @@ -385,7 +385,7 @@ model::ImportedConfig ConvertEngine::import (const std::string & config, const s /** * @brief takes a provider list and extracts the storage format - * + * * @param providers a string containing provided functionality of a plugin * @return the storage format or "none" in case none was found */ diff --git a/src/tools/rest-backend/service_search.cpp b/src/tools/rest-backend/service_search.cpp index 67cff18129f..0084c8faa2a 100644 --- a/src/tools/rest-backend/service_search.cpp +++ b/src/tools/rest-backend/service_search.cpp @@ -21,7 +21,7 @@ namespace service /** * @brief Can be used to filter an entry vector based on a name prefix. - * + * * All entries that do not start with the given name prefix will be * removed from the result. * diff --git a/src/tools/rest-backend/service_storage.cpp b/src/tools/rest-backend/service_storage.cpp index 3202b8d9828..251c447a064 100644 --- a/src/tools/rest-backend/service_storage.cpp +++ b/src/tools/rest-backend/service_storage.cpp @@ -33,9 +33,9 @@ StorageEngine::StorageEngine () /** * @brief Can be used to create an entry in the database. - * + * * Will add the entry and all subkeys to the database (configuration). - * + * * @param entry A custom Entry object holding information to store. * @return true if the entry was stored, false if something went wrong * @throws kdbrest::exception::EntryAlreadyExistsException in case an @@ -86,9 +86,9 @@ bool StorageEngine::createEntry (model::Entry & entry) /** * @brief Allows for updating of a database entry. - * + * * Will renew the entry and all its subkeys (configuration). - * + * * @param entry A custom Entry object holding current information. * @return true if the entry was updated, false if not * @throw kdbrest::exception::EntryNotFoundException in case the entry @@ -150,9 +150,9 @@ bool StorageEngine::updateEntry (model::Entry & entry) /** * @brief Allows for deleting of a database entry. - * + * * Will delete the entry iteself as well as all meta data and subkeys (configuration). - * + * * @param entry A custom Entry object that should be deleted. * @return true if the entry was deleted successfully, false otherwise * @throw kdbrest::exception::EntryNotFoundException in case the entry @@ -211,8 +211,8 @@ bool StorageEngine::deleteEntry (model::Entry & entry) /** * @brief Checks if an entry exists - * - * Can be used to determine if an entry with the given name + * + * Can be used to determine if an entry with the given name * exists in the database or not. * * @param key A string containing the entry name @@ -233,7 +233,7 @@ bool StorageEngine::entryExists (const std::string & key) /** * @brief attempts to retrieve an entry from the database - * + * * Can be used to get an entry from the database, * base on a given name. * @@ -257,14 +257,14 @@ model::Entry StorageEngine::getEntry (const std::string & key) /** * @brief retrieves all entries from the database - * + * * Fetches all entries from the database and returns them * as a vector. The database keys will be converted into Entry * objects with their configuration stored as sub keys. - * + * * Returned will be a copy of the entry list that is currently in the * cache. - * + * * @param force If the cache should be re-fetched. * @return A vector containing all entries of the database */ @@ -283,16 +283,16 @@ std::vector StorageEngine::getAllEntries (bool force) /** * @brief retireves all entries from the database - * + * * Fetches all entries from the database and returns them * as a vector. The database keys will be converted into Entry * objects with their configuration stored as sub keys. - * - * Returned will be a reference to the entry list that is currently + * + * Returned will be a reference to the entry list that is currently * in the cache. This reference should be used carefully, because * the list is not thread-safe. Should be used for search operations * only. - * + * * @param force If the cache should be re-fetched. * @return A vector containing all entries of the database */ @@ -348,9 +348,9 @@ void StorageEngine::loadAllEntries () /** * @brief Can be used to create an user entry in the database. - * + * * Will add the user and all subkeys to the database (additional information). - * + * * @param user A custom User object holding information to store. * @return true if the user was stored, false if something went wrong * @throws kdbrest::exception::UserAlreadyExistsException in case an @@ -398,9 +398,9 @@ bool StorageEngine::createUser (model::User & user) /** * @brief Allows for updating of an user entry. - * + * * Will renew the entry and all its subkeys (additional user information). - * + * * @param user A custom User object holding current information. * @return true if the user was updated, false if not * @throw kdbrest::exception::UserNotFoundException in case the user to @@ -459,9 +459,9 @@ bool StorageEngine::updateUser (model::User & user) /** * @brief Allows for deleting of an user entry. - * + * * Will delete the entry iteself as well as all subkeys (additional user information). - * + * * @param user A custom User object that should be deleted. * @return true if the user was deleted successfully, false otherwise * @throw kdbrest::exception::UserNotFoundException in case the user @@ -517,8 +517,8 @@ bool StorageEngine::deleteUser (model::User & user) /** * @brief checks if a user exists in the database - * - * Can be used to determine if aa user with the given name + * + * Can be used to determine if aa user with the given name * exists in the database or not. * * @param username A string containing the user name @@ -539,7 +539,7 @@ bool StorageEngine::userExists (const std::string & username) /** * @brief retrieves a user from the database - * + * * Can be used to get a user from the database, * base on a given name. * @@ -563,11 +563,11 @@ model::User StorageEngine::getUser (const std::string & username) /** * @brief retrieves all users from the database - * + * * Fetches all users from the database and returns them * as a vector. The database keys will be converted into User * objects with their personal information stored as sub keys. - * + * * @param force whether to force a cache refresh * @return A vector containing all users of the database */ @@ -586,14 +586,14 @@ std::vector StorageEngine::getAllUsers (bool force) /** * @brief retrieves all users from the database - * + * * Fetches all users from the database and returns them * as a vector. The database keys will be converted into User * objects with their personal information stored as sub keys. - * + * * @note This function returns a reference to the internal cache. * Changes to the vector can therefore cause unexpected behavior! - * + * * @param force whether to force a cache refresh * @return A vector reference containing all users of the database */ diff --git a/src/tools/rest-backend/user_application.cpp b/src/tools/rest-backend/user_application.cpp index acf22f0ec22..0b445c55151 100644 --- a/src/tools/rest-backend/user_application.cpp +++ b/src/tools/rest-backend/user_application.cpp @@ -27,7 +27,7 @@ namespace kdbrest /** * @brief the constructor of the user endpoint application. - * + * * @param srv a service container */ UserApp::UserApp (cppcms::service & srv) : cppcms::application (srv) @@ -41,9 +41,9 @@ UserApp::UserApp (cppcms::service & srv) : cppcms::application (srv) /** * @brief the main handle function for this endpoint. - * + * * it maps requests based on their HTTP method to the corresponding handlers. - * + * * @param username a username that may be provided as resource parameter */ void UserApp::handle (std::string username) @@ -95,9 +95,9 @@ void UserApp::handle (std::string username) /** * @brief helper method for dispatching of GET requests - * + * * performs authentication and permission checks if necessary - * + * * @param req a request * @param resp a response * @param username an optional username that should be used as target resource @@ -170,9 +170,9 @@ void UserApp::handleDispatchGet (cppcms::http::request & req, cppcms::http::resp /** * @brief helper method for dispatching of PUT requests - * + * * performs authentication and permission checks if necessary - * + * * @param req a request * @param resp a response * @param username an optional username that should be used as target resource @@ -221,9 +221,9 @@ void UserApp::handleDispatchPut (cppcms::http::request & req, cppcms::http::resp /** * @brief helper method for dispatching of DELETE requests - * + * * performs authentication and permission checks if necessary - * + * * @param req a request * @param resp a response * @param username an optional username that should be used as target resource @@ -271,7 +271,7 @@ void UserApp::handleDispatchDelete (cppcms::http::request & req, cppcms::http::r /** * @brief handles the retirval of a specific user entry - * + * * @param resp a response * @param username the username of the user whose information shall be retrieved */ @@ -298,7 +298,7 @@ void UserApp::handleGetUnique (cppcms::http::response & resp, const std::string /** * @brief handles the retrieval of a list of user entries - * + * * @param req a request * @param resp a response */ @@ -314,7 +314,7 @@ void UserApp::handleGet (cppcms::http::request & req, cppcms::http::response & r /** * @brief handles the creation of a new user entry - * + * * @param req a request * @param resp a response */ @@ -459,7 +459,7 @@ void UserApp::handleInsert (cppcms::http::request & req, cppcms::http::response /** * @brief handles the update of a user entry. - * + * * @param req a request * @param resp a response * @param username the username of the user who shall be updated @@ -565,7 +565,7 @@ void UserApp::handleUpdate (cppcms::http::request & req, cppcms::http::response /** * @brief handles a delete request for a user resource. - * + * * @param resp a response * @param username the username of the user who shall be deleted */ @@ -588,7 +588,7 @@ void UserApp::handleDelete (cppcms::http::response & resp, const std::string use /** * @brief extracts the max number of rows to print from a request. - * + * * @param req a request * @return the max number of rows to print or the default value if not set */ @@ -617,7 +617,7 @@ inline int UserApp::getMaxrows (cppcms::http::request & req) const /** * @brief extracts the offset parameter from a request. - * + * * @param req a request * @return the offset extracted from the request parameter, if not set 0 */ @@ -642,7 +642,7 @@ inline int UserApp::getOffset (cppcms::http::request & req) const /** * @brief filters a vector of user entries based on parameters of a request. - * + * * @param req a request * @param users the user vector to filter */ @@ -667,7 +667,7 @@ inline void UserApp::processFiltering (cppcms::http::request & req, std::vector< /** * @brief sorts a vector of user entries based on parameters of a request. - * + * * @param req a request * @param users the user vector to sort */ @@ -704,13 +704,13 @@ inline void UserApp::processSorting (cppcms::http::request & req, std::vector +#include + +static void setKeyValue (const char * parentKeyName, const char * type, const char * name, const char * value) +{ + // Open + KeySet * config = ksNew (0, KS_END); + Key * parentKey = keyNew (parentKeyName, KEY_END); + KDB * handle = kdbOpen (parentKey); + kdbGet (handle, config, parentKey); + + // Set + Key * key = keyNew (parentKeyName, KEY_END); + keyAddName (key, name); + keySetMeta (key, "type", type); + keySetString (key, value); + ksAppendKey (config, key); + + // Save + kdbSet (handle, config, parentKey); + + // Close + kdbClose (handle, parentKey); + keyDel (parentKey); +} + +static void test_primitiveGetters () +{ + const char * parentKey = "user/test/sw/elektra/kdb/#0/current"; + + setKeyValue (parentKey, "string", "stringkey", "A string"); + setKeyValue (parentKey, "boolean", "booleankey", "1"); + setKeyValue (parentKey, "char", "charkey", "c"); + setKeyValue (parentKey, "octet", "octetkey", "1"); + setKeyValue (parentKey, "short", "shortkey", "1"); + setKeyValue (parentKey, "unsigned_short", "unsignedshortkey", "1"); + setKeyValue (parentKey, "long", "longkey", "1"); + setKeyValue (parentKey, "unsigned_long", "unsignedlongkey", "1"); + setKeyValue (parentKey, "long_long", "longlongkey", "1"); + setKeyValue (parentKey, "unsigned_long_long", "unsignedlonglongkey", "1"); + setKeyValue (parentKey, "float", "floatkey", "1.1"); + setKeyValue (parentKey, "double", "doublekey", "1.1"); + setKeyValue (parentKey, "long_double", "longdoublekey", "1.1"); + + ElektraError * error = NULL; + Elektra * elektra = elektraOpen (parentKey, NULL, &error); + + if (error) + { + yield_error ("elektraOpen failed"); + printf ("ElektraError: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + } + + succeed_if (!elektraStrCmp (elektraGetString (elektra, "stringkey"), "A string"), "Wrong key value."); + succeed_if (elektraGetBoolean (elektra, "booleankey"), "Wrong key value."); + succeed_if (elektraGetChar (elektra, "charkey") == 'c', "Wrong key value."); + succeed_if (elektraGetOctet (elektra, "octetkey") == 1, "Wrong key value."); + succeed_if (elektraGetShort (elektra, "shortkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedShort (elektra, "unsignedshortkey") == 1, "Wrong key value."); + succeed_if (elektraGetLong (elektra, "longkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLong (elektra, "unsignedlongkey") == 1, "Wrong key value."); + succeed_if (elektraGetLongLong (elektra, "longlongkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLongLong (elektra, "unsignedlonglongkey") == 1, "Wrong key value."); + + ELEKTRA_DIAG_STORE + ELEKTRA_DIAG_OFF (-Wfloat - equal) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + + succeed_if (elektraGetFloat (elektra, "floatkey") == 1.1f, "Wrong key value."); + succeed_if (elektraGetDouble (elektra, "doublekey") == 1.1, "Wrong key value."); + succeed_if (elektraGetLongDouble (elektra, "longdoublekey") == 1.1L, "Wrong key value."); +#pragma clang diagnostic pop + ELEKTRA_DIAG_RESTORE + + elektraClose (elektra); +} + +static void test_arrayGetters () +{ + const char * parentKey = "user/test/sw/elektra/kdb/#0/current"; + + setKeyValue (parentKey, "string", "stringarraykey/#0", "String 1"); + setKeyValue (parentKey, "string", "stringarraykey/#1", "String 2"); + + setKeyValue (parentKey, "boolean", "booleanarraykey/#0", "0"); + setKeyValue (parentKey, "boolean", "booleanarraykey/#1", "1"); + + setKeyValue (parentKey, "char", "chararraykey/#0", "c"); + setKeyValue (parentKey, "char", "chararraykey/#1", "d"); + + setKeyValue (parentKey, "octet", "octetarraykey/#0", "1"); + setKeyValue (parentKey, "octet", "octetarraykey/#1", "2"); + + setKeyValue (parentKey, "short", "shortarraykey/#0", "1"); + setKeyValue (parentKey, "short", "shortarraykey/#1", "2"); + + setKeyValue (parentKey, "unsigned_short", "unsignedshortarraykey/#0", "1"); + setKeyValue (parentKey, "unsigned_short", "unsignedshortarraykey/#1", "2"); + + setKeyValue (parentKey, "long", "longarraykey/#0", "1"); + setKeyValue (parentKey, "long", "longarraykey/#1", "2"); + + setKeyValue (parentKey, "unsigned_long", "unsignedLongarraykey/#0", "1"); + setKeyValue (parentKey, "unsigned_long", "unsignedLongarraykey/#1", "2"); + + setKeyValue (parentKey, "long_long", "longlongarraykey/#0", "1"); + setKeyValue (parentKey, "long_long", "longlongarraykey/#1", "2"); + + setKeyValue (parentKey, "unsigned_long_long", "unsignedlonglongarraykey/#0", "1"); + setKeyValue (parentKey, "unsigned_long_long", "unsignedlonglongarraykey/#1", "2"); + + setKeyValue (parentKey, "float", "floatarraykey/#0", "1.1"); + setKeyValue (parentKey, "float", "floatarraykey/#1", "2.1"); + + setKeyValue (parentKey, "double", "doublearraykey/#0", "1.1"); + setKeyValue (parentKey, "double", "doublearraykey/#1", "2.1"); + + setKeyValue (parentKey, "long_double", "longdoublearraykey/#0", "1.1"); + setKeyValue (parentKey, "long_double", "longdoublearraykey/#1", "2.1"); + + ElektraError * error = NULL; + Elektra * elektra = elektraOpen (parentKey, NULL, &error); + + if (error) + { + yield_error ("elektraOpen failed"); + printf ("ElektraError: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + } + + succeed_if (elektraArraySize (elektra, "stringarraykey") == 2, "Wrong array size"); + succeed_if (!elektraStrCmp (elektraGetStringArrayElement (elektra, "stringarraykey", 0), "String 1"), "Wrong key value."); + succeed_if (!elektraStrCmp (elektraGetStringArrayElement (elektra, "stringarraykey", 1), "String 2"), "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "booleanarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetBooleanArrayElement (elektra, "booleanarraykey", 0) == 0, "Wrong key value."); + succeed_if (elektraGetBooleanArrayElement (elektra, "booleanarraykey", 1), "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "chararraykey") == 2, "Wrong array size"); + succeed_if (elektraGetCharArrayElement (elektra, "chararraykey", 0) == 'c', "Wrong key value."); + succeed_if (elektraGetCharArrayElement (elektra, "chararraykey", 1) == 'd', "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "octetarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetOctetArrayElement (elektra, "octetarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetOctetArrayElement (elektra, "octetarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "shortarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetShortArrayElement (elektra, "shortarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetShortArrayElement (elektra, "shortarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "unsignedshortarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetUnsignedShortArrayElement (elektra, "unsignedshortarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedShortArrayElement (elektra, "unsignedshortarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "longlongarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetLongLongArrayElement (elektra, "longlongarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetLongLongArrayElement (elektra, "longlongarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "unsignedlonglongarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetUnsignedLongLongArrayElement (elektra, "unsignedlonglongarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLongLongArrayElement (elektra, "unsignedlonglongarraykey", 1) == 2, "Wrong key value."); + + ELEKTRA_DIAG_STORE + ELEKTRA_DIAG_OFF (-Wfloat - equal) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + + succeed_if (elektraArraySize (elektra, "floatarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetFloatArrayElement (elektra, "floatarraykey", 0) == 1.1f, "Wrong key value."); + succeed_if (elektraGetFloatArrayElement (elektra, "floatarraykey", 1) == 2.1f, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "doublearraykey") == 2, "Wrong array size"); + succeed_if (elektraGetDoubleArrayElement (elektra, "doublearraykey", 0) == 1.1, "Wrong key value."); + succeed_if (elektraGetDoubleArrayElement (elektra, "doublearraykey", 1) == 2.1, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "longdoublearraykey") == 2, "Wrong array size"); + succeed_if (elektraGetLongDoubleArrayElement (elektra, "longdoublearraykey", 0) == 1.1L, "Wrong key value."); + succeed_if (elektraGetLongDoubleArrayElement (elektra, "longdoublearraykey", 1) == 2.1L, "Wrong key value."); + +#pragma clang diagnostic pop + ELEKTRA_DIAG_RESTORE + + elektraClose (elektra); +} + +static void test_primitiveSetters () +{ + const char * parentKey = "user/test/sw/elektra/kdb/#0/current"; + + setKeyValue (parentKey, "string", "stringkey", ""); + setKeyValue (parentKey, "boolean", "booleankey", ""); + setKeyValue (parentKey, "char", "charkey", ""); + setKeyValue (parentKey, "octet", "octetkey", ""); + setKeyValue (parentKey, "short", "shortkey", "1"); + setKeyValue (parentKey, "unsigned_short", "unsignedshortkey", "1"); + setKeyValue (parentKey, "long", "longkey", "1"); + setKeyValue (parentKey, "unsigned_long", "unsignedlongkey", "1"); + setKeyValue (parentKey, "long_long", "longlongkey", "1"); + setKeyValue (parentKey, "unsigned_long_long", "unsignedlonglongkey", "1"); + setKeyValue (parentKey, "float", "floatkey", "1.1"); + setKeyValue (parentKey, "double", "doublekey", "1.1"); + setKeyValue (parentKey, "long_double", "longdoublekey", "1.1"); + + ElektraError * error = NULL; + Elektra * elektra = elektraOpen (parentKey, NULL, &error); + + if (error) + { + yield_error ("elektraOpen failed"); + printf ("ElektraError: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + } + + // Overwrite existing values. + elektraSetString (elektra, "stringkey", "A string", &error); + elektraSetBoolean (elektra, "booleankey", 1, &error); + elektraSetChar (elektra, "charkey", 'c', &error); + elektraSetOctet (elektra, "octetkey", 1, &error); + elektraSetShort (elektra, "shortkey", 1, &error); + elektraSetUnsignedShort (elektra, "unsignedshortkey", 1, &error); + elektraSetLong (elektra, "longkey", 1, &error); + elektraSetUnsignedLong (elektra, "unsignedlongkey", 1, &error); + elektraSetLongLong (elektra, "longlongkey", 1, &error); + elektraSetUnsignedLongLong (elektra, "unsignedlonglongkey", 1, &error); + elektraSetFloat (elektra, "floatkey", 1.1, &error); + elektraSetDouble (elektra, "doublekey", 1.1, &error); + elektraSetLongDouble (elektra, "longdoublekey", 1.1L, &error); + + // Add new keys. + elektraSetString (elektra, "newstringkey", "A string", &error); + elektraSetBoolean (elektra, "newbooleankey", 1, &error); + elektraSetChar (elektra, "newcharkey", 'c', &error); + elektraSetOctet (elektra, "newoctetkey", 1, &error); + elektraSetShort (elektra, "newshortkey", 1, &error); + elektraSetUnsignedShort (elektra, "newunsignedshortkey", 1, &error); + elektraSetLong (elektra, "newlongkey", 1, &error); + elektraSetUnsignedLong (elektra, "newunsignedlongkey", 1, &error); + elektraSetLongLong (elektra, "newlonglongkey", 1, &error); + elektraSetUnsignedLongLong (elektra, "newunsignedlonglongkey", 1, &error); + elektraSetFloat (elektra, "newfloatkey", 1.1, &error); + elektraSetDouble (elektra, "newdoublekey", 1.1, &error); + elektraSetLongDouble (elektra, "newlongdoublekey", 1.1L, &error); + + if (error) + { + yield_error ("A setter failed"); + printf ("ElektraError: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + } + + // Check overwritten values. + succeed_if (!elektraStrCmp (elektraGetString (elektra, "stringkey"), "A string"), "Wrong key value."); + succeed_if (elektraGetBoolean (elektra, "booleankey"), "Wrong key value."); + succeed_if (elektraGetChar (elektra, "charkey") == 'c', "Wrong key value."); + succeed_if (elektraGetOctet (elektra, "octetkey") == 1, "Wrong key value."); + succeed_if (elektraGetShort (elektra, "shortkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedShort (elektra, "unsignedshortkey") == 1, "Wrong key value."); + succeed_if (elektraGetLong (elektra, "longkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLong (elektra, "unsignedlongkey") == 1, "Wrong key value."); + succeed_if (elektraGetLongLong (elektra, "longlongkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLongLong (elektra, "unsignedlonglongkey") == 1, "Wrong key value."); + ELEKTRA_DIAG_STORE + ELEKTRA_DIAG_OFF (-Wfloat - equal) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + succeed_if (elektraGetFloat (elektra, "floatkey") == 1.1f, "Wrong key value."); + succeed_if (elektraGetDouble (elektra, "doublekey") == 1.1, "Wrong key value."); + succeed_if (elektraGetLongDouble (elektra, "longdoublekey") == 1.1L, "Wrong key value."); +#pragma clang diagnostic pop + ELEKTRA_DIAG_RESTORE + + // Check new keys. + succeed_if (!elektraStrCmp (elektraGetString (elektra, "newstringkey"), "A string"), "Wrong key value."); + succeed_if (elektraGetBoolean (elektra, "newbooleankey"), "Wrong key value."); + succeed_if (elektraGetChar (elektra, "newcharkey") == 'c', "Wrong key value."); + succeed_if (elektraGetOctet (elektra, "newoctetkey") == 1, "Wrong key value."); + succeed_if (elektraGetShort (elektra, "newshortkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedShort (elektra, "newunsignedshortkey") == 1, "Wrong key value."); + succeed_if (elektraGetLong (elektra, "newlongkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLong (elektra, "newunsignedlongkey") == 1, "Wrong key value."); + succeed_if (elektraGetLongLong (elektra, "newlonglongkey") == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLongLong (elektra, "newunsignedlonglongkey") == 1, "Wrong key value."); + ELEKTRA_DIAG_STORE + ELEKTRA_DIAG_OFF (-Wfloat - equal) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + succeed_if (elektraGetFloat (elektra, "newfloatkey") == 1.1f, "Wrong key value."); + succeed_if (elektraGetDouble (elektra, "newdoublekey") == 1.1, "Wrong key value."); + succeed_if (elektraGetLongDouble (elektra, "newlongdoublekey") == 1.1L, "Wrong key value."); +#pragma clang diagnostic pop + ELEKTRA_DIAG_RESTORE + + elektraClose (elektra); +} + +static void test_arraySetters () +{ + const char * parentKey = "user/test/sw/elektra/kdb/#0/current"; + + setKeyValue (parentKey, "string", "stringarraykey/#0", ""); + setKeyValue (parentKey, "string", "stringarraykey/#1", ""); + + setKeyValue (parentKey, "boolean", "booleanarraykey/#0", ""); + setKeyValue (parentKey, "boolean", "booleanarraykey/#1", ""); + + setKeyValue (parentKey, "char", "chararraykey/#0", ""); + setKeyValue (parentKey, "char", "chararraykey/#1", ""); + + setKeyValue (parentKey, "octet", "octetarraykey/#0", ""); + setKeyValue (parentKey, "octet", "octetarraykey/#1", ""); + + setKeyValue (parentKey, "short", "shortarraykey/#0", ""); + setKeyValue (parentKey, "short", "shortarraykey/#1", ""); + + setKeyValue (parentKey, "unsigned_short", "unsignedshortarraykey/#0", ""); + setKeyValue (parentKey, "unsigned_short", "unsignedshortarraykey/#1", ""); + + setKeyValue (parentKey, "long", "longarraykey/#0", ""); + setKeyValue (parentKey, "long", "longarraykey/#1", ""); + + setKeyValue (parentKey, "unsigned_long", "unsignedLongarraykey/#0", ""); + setKeyValue (parentKey, "unsigned_long", "unsignedLongarraykey/#1", ""); + + setKeyValue (parentKey, "long_long", "longlongarraykey/#0", ""); + setKeyValue (parentKey, "long_long", "longlongarraykey/#1", ""); + + setKeyValue (parentKey, "unsigned_long_long", "unsignedlonglongarraykey/#0", ""); + setKeyValue (parentKey, "unsigned_long_long", "unsignedlonglongarraykey/#1", ""); + + setKeyValue (parentKey, "float", "floatarraykey/#0", ""); + setKeyValue (parentKey, "float", "floatarraykey/#1", ""); + + setKeyValue (parentKey, "double", "doublearraykey/#0", ""); + setKeyValue (parentKey, "double", "doublearraykey/#1", ""); + + setKeyValue (parentKey, "long_double", "longdoublearraykey/#0", ""); + setKeyValue (parentKey, "long_double", "longdoublearraykey/#1", ""); + + ElektraError * error = NULL; + Elektra * elektra = elektraOpen (parentKey, NULL, &error); + + if (error) + { + yield_error ("elektraOpen failed"); + printf ("ElektraError: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + } + + // Overwrite existing values. + + elektraSetStringArrayElement (elektra, "stringarraykey", 0, "String 1", &error); + elektraSetStringArrayElement (elektra, "stringarraykey", 1, "String 2", &error); + + elektraSetBooleanArrayElement (elektra, "booleanarraykey", 0, 0, &error); + elektraSetBooleanArrayElement (elektra, "booleanarraykey", 1, 1, &error); + + elektraSetCharArrayElement (elektra, "chararraykey", 0, 'c', &error); + elektraSetCharArrayElement (elektra, "chararraykey", 1, 'd', &error); + + elektraSetOctetArrayElement (elektra, "octetarraykey", 0, 1, &error); + elektraSetOctetArrayElement (elektra, "octetarraykey", 1, 2, &error); + + elektraSetShortArrayElement (elektra, "shortarraykey", 0, 1, &error); + elektraSetShortArrayElement (elektra, "shortarraykey", 1, 2, &error); + + elektraSetUnsignedShortArrayElement (elektra, "unsignedshortarraykey", 0, 1, &error); + elektraSetUnsignedShortArrayElement (elektra, "unsignedshortarraykey", 1, 2, &error); + + elektraSetLongArrayElement (elektra, "longarraykey", 0, 1, &error); + elektraSetLongArrayElement (elektra, "longarraykey", 1, 2, &error); + + elektraSetUnsignedLongArrayElement (elektra, "unsignedLongarraykey", 0, 1, &error); + elektraSetUnsignedLongArrayElement (elektra, "unsignedLongarraykey", 1, 2, &error); + + elektraSetLongArrayElement (elektra, "longarraykey", 0, 1, &error); + elektraSetLongArrayElement (elektra, "longarraykey", 1, 2, &error); + + elektraSetUnsignedLongArrayElement (elektra, "unsignedlongarraykey", 0, 1, &error); + elektraSetUnsignedLongArrayElement (elektra, "unsignedlongarraykey", 1, 2, &error); + + elektraSetLongLongArrayElement (elektra, "longlongarraykey", 0, 1, &error); + elektraSetLongLongArrayElement (elektra, "longlongarraykey", 1, 2, &error); + + elektraSetUnsignedLongLongArrayElement (elektra, "unsignedlonglongarraykey", 0, 1, &error); + elektraSetUnsignedLongLongArrayElement (elektra, "unsignedlonglongarraykey", 1, 2, &error); + + elektraSetFloatArrayElement (elektra, "floatarraykey", 0, 1.1, &error); + elektraSetFloatArrayElement (elektra, "floatarraykey", 1, 2.1, &error); + + elektraSetDoubleArrayElement (elektra, "doublearraykey", 0, 1.1, &error); + elektraSetDoubleArrayElement (elektra, "doublearraykey", 1, 2.1, &error); + + elektraSetLongDoubleArrayElement (elektra, "longdoublearraykey", 0, 1.1L, &error); + elektraSetLongDoubleArrayElement (elektra, "longdoublearraykey", 1, 2.1L, &error); + + // Add new keys. + + elektraSetStringArrayElement (elektra, "newstringarraykey", 0, "String 1", &error); + elektraSetStringArrayElement (elektra, "newstringarraykey", 1, "String 2", &error); + + elektraSetBooleanArrayElement (elektra, "newbooleanarraykey", 0, 0, &error); + elektraSetBooleanArrayElement (elektra, "newbooleanarraykey", 1, 1, &error); + + elektraSetCharArrayElement (elektra, "newchararraykey", 0, 'c', &error); + elektraSetCharArrayElement (elektra, "newchararraykey", 1, 'd', &error); + + elektraSetOctetArrayElement (elektra, "newoctetarraykey", 0, 1, &error); + elektraSetOctetArrayElement (elektra, "newoctetarraykey", 1, 2, &error); + + elektraSetShortArrayElement (elektra, "newshortarraykey", 0, 1, &error); + elektraSetShortArrayElement (elektra, "newshortarraykey", 1, 2, &error); + + elektraSetUnsignedShortArrayElement (elektra, "newunsignedshortarraykey", 0, 1, &error); + elektraSetUnsignedShortArrayElement (elektra, "newunsignedshortarraykey", 1, 2, &error); + + elektraSetLongArrayElement (elektra, "newlongarraykey", 0, 1, &error); + elektraSetLongArrayElement (elektra, "newlongarraykey", 1, 2, &error); + + elektraSetUnsignedLongArrayElement (elektra, "newunsignedLongarraykey", 0, 1, &error); + elektraSetUnsignedLongArrayElement (elektra, "newunsignedLongarraykey", 1, 2, &error); + + elektraSetLongArrayElement (elektra, "newlongarraykey", 0, 1, &error); + elektraSetLongArrayElement (elektra, "newlongarraykey", 1, 2, &error); + + elektraSetUnsignedLongArrayElement (elektra, "newunsignedlongarraykey", 0, 1, &error); + elektraSetUnsignedLongArrayElement (elektra, "newunsignedlongarraykey", 1, 2, &error); + + elektraSetLongLongArrayElement (elektra, "newlonglongarraykey", 0, 1, &error); + elektraSetLongLongArrayElement (elektra, "newlonglongarraykey", 1, 2, &error); + + elektraSetUnsignedLongLongArrayElement (elektra, "newunsignedlonglongarraykey", 0, 1, &error); + elektraSetUnsignedLongLongArrayElement (elektra, "newunsignedlonglongarraykey", 1, 2, &error); + + elektraSetFloatArrayElement (elektra, "newfloatarraykey", 0, 1.1, &error); + elektraSetFloatArrayElement (elektra, "newfloatarraykey", 1, 2.1, &error); + + elektraSetDoubleArrayElement (elektra, "newdoublearraykey", 0, 1.1, &error); + elektraSetDoubleArrayElement (elektra, "newdoublearraykey", 1, 2.1, &error); + + elektraSetLongDoubleArrayElement (elektra, "newlongdoublearraykey", 0, 1.1L, &error); + elektraSetLongDoubleArrayElement (elektra, "newlongdoublearraykey", 1, 2.1L, &error); + + if (error) + { + yield_error ("A setter failed"); + printf ("ElektraError: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + } + + // Check overwritten values. + + succeed_if (elektraArraySize (elektra, "stringarraykey") == 2, "Wrong array size"); + succeed_if (!elektraStrCmp (elektraGetStringArrayElement (elektra, "stringarraykey", 0), "String 1"), "Wrong key value."); + succeed_if (!elektraStrCmp (elektraGetStringArrayElement (elektra, "stringarraykey", 1), "String 2"), "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "booleanarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetBooleanArrayElement (elektra, "booleanarraykey", 0) == 0, "Wrong key value."); + succeed_if (elektraGetBooleanArrayElement (elektra, "booleanarraykey", 1), "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "chararraykey") == 2, "Wrong array size"); + succeed_if (elektraGetCharArrayElement (elektra, "chararraykey", 0) == 'c', "Wrong key value."); + succeed_if (elektraGetCharArrayElement (elektra, "chararraykey", 1) == 'd', "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "octetarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetOctetArrayElement (elektra, "octetarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetOctetArrayElement (elektra, "octetarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "shortarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetShortArrayElement (elektra, "shortarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetShortArrayElement (elektra, "shortarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "unsignedshortarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetUnsignedShortArrayElement (elektra, "unsignedshortarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedShortArrayElement (elektra, "unsignedshortarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "longarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetLongArrayElement (elektra, "longarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetLongArrayElement (elektra, "longarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "unsignedlongarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetUnsignedLongArrayElement (elektra, "unsignedlongarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLongArrayElement (elektra, "unsignedlongarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "longlongarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetLongLongArrayElement (elektra, "longlongarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetLongLongArrayElement (elektra, "longlongarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "unsignedlonglongarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetUnsignedLongLongArrayElement (elektra, "unsignedlonglongarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLongLongArrayElement (elektra, "unsignedlonglongarraykey", 1) == 2, "Wrong key value."); + + ELEKTRA_DIAG_STORE + ELEKTRA_DIAG_OFF (-Wfloat - equal) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + + succeed_if (elektraArraySize (elektra, "floatarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetFloatArrayElement (elektra, "floatarraykey", 0) == 1.1f, "Wrong key value."); + succeed_if (elektraGetFloatArrayElement (elektra, "floatarraykey", 1) == 2.1f, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "doublearraykey") == 2, "Wrong array size"); + succeed_if (elektraGetDoubleArrayElement (elektra, "doublearraykey", 0) == 1.1, "Wrong key value."); + succeed_if (elektraGetDoubleArrayElement (elektra, "doublearraykey", 1) == 2.1, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "longdoublearraykey") == 2, "Wrong array size"); + succeed_if (elektraGetLongDoubleArrayElement (elektra, "longdoublearraykey", 0) == 1.1L, "Wrong key value."); + succeed_if (elektraGetLongDoubleArrayElement (elektra, "longdoublearraykey", 1) == 2.1L, "Wrong key value."); + +#pragma clang diagnostic pop + ELEKTRA_DIAG_RESTORE + + // Check new keys. + + succeed_if (elektraArraySize (elektra, "newstringarraykey") == 2, "Wrong array size"); + succeed_if (!elektraStrCmp (elektraGetStringArrayElement (elektra, "newstringarraykey", 0), "String 1"), "Wrong key value."); + succeed_if (!elektraStrCmp (elektraGetStringArrayElement (elektra, "newstringarraykey", 1), "String 2"), "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newbooleanarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetBooleanArrayElement (elektra, "newbooleanarraykey", 0) == 0, "Wrong key value."); + succeed_if (elektraGetBooleanArrayElement (elektra, "newbooleanarraykey", 1), "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newchararraykey") == 2, "Wrong array size"); + succeed_if (elektraGetCharArrayElement (elektra, "newchararraykey", 0) == 'c', "Wrong key value."); + succeed_if (elektraGetCharArrayElement (elektra, "newchararraykey", 1) == 'd', "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newoctetarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetOctetArrayElement (elektra, "newoctetarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetOctetArrayElement (elektra, "newoctetarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newshortarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetShortArrayElement (elektra, "newshortarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetShortArrayElement (elektra, "newshortarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newunsignedshortarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetUnsignedShortArrayElement (elektra, "newunsignedshortarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedShortArrayElement (elektra, "newunsignedshortarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newlonglongarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetLongLongArrayElement (elektra, "newlonglongarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetLongLongArrayElement (elektra, "newlonglongarraykey", 1) == 2, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newunsignedlonglongarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetUnsignedLongLongArrayElement (elektra, "newunsignedlonglongarraykey", 0) == 1, "Wrong key value."); + succeed_if (elektraGetUnsignedLongLongArrayElement (elektra, "newunsignedlonglongarraykey", 1) == 2, "Wrong key value."); + + ELEKTRA_DIAG_STORE + ELEKTRA_DIAG_OFF (-Wfloat - equal) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + + succeed_if (elektraArraySize (elektra, "newfloatarraykey") == 2, "Wrong array size"); + succeed_if (elektraGetFloatArrayElement (elektra, "newfloatarraykey", 0) == 1.1f, "Wrong key value."); + succeed_if (elektraGetFloatArrayElement (elektra, "newfloatarraykey", 1) == 2.1f, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newdoublearraykey") == 2, "Wrong array size"); + succeed_if (elektraGetDoubleArrayElement (elektra, "newdoublearraykey", 0) == 1.1, "Wrong key value."); + succeed_if (elektraGetDoubleArrayElement (elektra, "newdoublearraykey", 1) == 2.1, "Wrong key value."); + + succeed_if (elektraArraySize (elektra, "newlongdoublearraykey") == 2, "Wrong array size"); + succeed_if (elektraGetLongDoubleArrayElement (elektra, "newlongdoublearraykey", 0) == 1.1L, "Wrong key value."); + succeed_if (elektraGetLongDoubleArrayElement (elektra, "newlongdoublearraykey", 1) == 2.1L, "Wrong key value."); + +#pragma clang diagnostic pop + ELEKTRA_DIAG_RESTORE + + elektraClose (elektra); +} + +void test_defaultValues () +{ + KeySet * defaults = ksNew ( + 0, keyNew ("user/test/sw/elektra/kdb/#0/current/stringkey", KEY_VALUE, "A string", KEY_META, "type", "string", KEY_END), + KS_END); + + ElektraError * error = NULL; + Elektra * elektra = elektraOpen ("user/test/sw/elektra/kdb/#0/current", defaults, &error); + + if (error) + { + yield_error ("elektraOpen failed"); + printf ("ElektraError: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + } + + succeed_if (!elektraStrCmp (elektraGetString (elektra, "stringkey"), "A string"), "Wrong key value."); + + elektraClose (elektra); +} + +void test_generic () +{ + const char * parentKey = "user/test/sw/elektra/kdb/#0/current"; + + setKeyValue (parentKey, "string", "stringkey", "A string"); + + ElektraError * error = NULL; + Elektra * elektra = elektraOpen (parentKey, NULL, &error); + + if (error) + { + yield_error ("elektraOpen failed"); + printf ("ElektraError: %s\n", elektraErrorDescription (error)); + elektraErrorReset (&error); + } + + ElektraStringTag stringTag = { "stringkey" }; + ElektraBooleanTag booleanTag = { "booleankey" }; + ElektraCharTag charTag = { "charkey" }; + ElektraOctetTag octetTag = { "octetkey" }; + ElektraShortTag shortTag = { "shortkey" }; + ElektraUnsignedShortTag unsignedShortTag = { "unsignedshortkey" }; + ElektraLongTag longTag = { "longkey" }; + ElektraUnsignedLongTag unsignedLongTag = { "unsignedlongkey" }; + ElektraLongLongTag longLongTag = { "longlongkey" }; + ElektraUnsignedLongLongTag unsignedLongLongTag = { "unsignedlonglongkey" }; + ElektraFloatTag floatTag = { "floatkey" }; + ElektraDoubleTag doubleTag = { "doublekey" }; + ElektraLongDoubleTag longDoubleTag = { "longdoublekey" }; + + elektraSet (elektra, stringTag, "A string", &error); + elektraSet (elektra, booleanTag, 1, &error); + elektraSet (elektra, charTag, 'c', &error); + elektraSet (elektra, octetTag, 1, &error); + elektraSet (elektra, shortTag, 1, &error); + elektraSet (elektra, unsignedShortTag, 1, &error); + elektraSet (elektra, longTag, 1, &error); + elektraSet (elektra, unsignedLongTag, 1, &error); + elektraSet (elektra, longLongTag, 1, &error); + elektraSet (elektra, unsignedLongLongTag, 1, &error); + elektraSet (elektra, floatTag, 1.1, &error); + elektraSet (elektra, doubleTag, 1.1, &error); + elektraSet (elektra, longDoubleTag, 1.1, &error); + + // Check values. + succeed_if (!elektraStrCmp (elektraGet (elektra, stringTag), "A string"), "Wrong key value."); + succeed_if (elektraGet (elektra, booleanTag), "Wrong key value."); + succeed_if (elektraGet (elektra, charTag) == 'c', "Wrong key value."); + succeed_if (elektraGet (elektra, octetTag) == 1, "Wrong key value."); + succeed_if (elektraGet (elektra, shortTag) == 1, "Wrong key value."); + succeed_if (elektraGet (elektra, unsignedShortTag) == 1, "Wrong key value."); + succeed_if (elektraGet (elektra, longTag) == 1, "Wrong key value."); + succeed_if (elektraGet (elektra, unsignedLongTag) == 1, "Wrong key value."); + succeed_if (elektraGet (elektra, longLongTag) == 1, "Wrong key value."); + succeed_if (elektraGet (elektra, unsignedLongLongTag) == 1, "Wrong key value."); + ELEKTRA_DIAG_STORE + ELEKTRA_DIAG_OFF (-Wfloat - equal) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + succeed_if (elektraGet (elektra, floatTag) == 1.1f, "Wrong key value."); + succeed_if (elektraGet (elektra, doubleTag) == 1.1, "Wrong key value."); + succeed_if (elektraGet (elektra, longDoubleTag) == 1.1L, "Wrong key value."); +#pragma clang diagnostic pop + ELEKTRA_DIAG_RESTORE +} + +int main (int argc, char ** argv) +{ + init (argc, argv); + + test_primitiveGetters (); + test_arrayGetters (); + + test_primitiveSetters (); + test_arraySetters (); + + test_defaultValues (); + + test_generic (); + + printf ("\ntest_highlevel RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError); + + return nbError; +}