Hello community, here is the log from the commit of package libeconf for openSUSE:Factory checked in at 2019-09-07 11:53:52 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libeconf (Old) and /work/SRC/openSUSE:Factory/.libeconf.new.7948 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libeconf" Sat Sep 7 11:53:52 2019 rev:2 rq:728808 version:0.3.0+git20190905.0ca8fe2 Changes: -------- --- /work/SRC/openSUSE:Factory/libeconf/libeconf.changes 2019-09-04 09:12:56.106958223 +0200 +++ /work/SRC/openSUSE:Factory/.libeconf.new.7948/libeconf.changes 2019-09-07 11:54:02.186268981 +0200 @@ -1,0 +2,41 @@ +Thu Sep 05 08:54:20 UTC 2019 - [email protected] + +- Update to version 0.3.0+git20190905.0ca8fe2: + * Merge doc changes from parlt91 (pull rq#73) + * Implement econf_get*ValueDef functions: if key is not found, a provided default is returned. + * Differentiate between no value provided and empty value provided + * Remove obsolete check for comments + * Enhance and adjust test cases + * Remove obsolete check for comments + +------------------------------------------------------------------- +Wed Sep 04 11:13:09 UTC 2019 - [email protected] + +- Update to version 0.2.0+git20190904.03fa5b4: + * Enhance and adjust test cases + * Update ccpp.yml + * Update ccpp.yml + * Update ccpp.yml + +------------------------------------------------------------------- +Wed Sep 04 10:17:25 UTC 2019 - [email protected] + +- Update to version 0.2.0+git20190904.989df9f: + * Remove debug printf + +------------------------------------------------------------------- +Wed Sep 04 09:58:12 UTC 2019 - [email protected] + +- Update to version 0.2.0+git20190904.c9c1820: + * Implement alternate file parser solving the problems with group entry detection. + * Add new parse error error code + * Bool values read from a config file are not sanitzied, so we need to do that in the getBoolValueNum function, too. + * Only use <file>.<suffix>.d directories + * Release version 0.2.0 + * Add an explanation about this project. + * Check for NULL pointer arguments + * Fix error return value + * Fix typo in comment + * Add test case for reading login.defs with data from util-linux test suite + +------------------------------------------------------------------- Old: ---- libeconf-0.0.0+git20190902.dd17c11.tar.xz New: ---- libeconf-0.3.0+git20190905.0ca8fe2.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libeconf.spec ++++++ --- /var/tmp/diff_new_pack.rWMxF6/_old 2019-09-07 11:54:02.686268910 +0200 +++ /var/tmp/diff_new_pack.rWMxF6/_new 2019-09-07 11:54:02.690268910 +0200 @@ -18,7 +18,7 @@ %define lname libeconf0 Name: libeconf -Version: 0.0.0+git20190902.dd17c11 +Version: 0.3.0+git20190905.0ca8fe2 Release: 0 Summary: Enhanced config file parser ala systemd License: LGPL-2.1-or-later ++++++ _service ++++++ --- /var/tmp/diff_new_pack.rWMxF6/_old 2019-09-07 11:54:02.710268907 +0200 +++ /var/tmp/diff_new_pack.rWMxF6/_new 2019-09-07 11:54:02.710268907 +0200 @@ -1,7 +1,7 @@ <services> <service name="tar_scm" mode="disabled"> - <param name="version">0.0.0</param> - <param name="versionformat">0.0.0+git%cd.%h</param> + <param name="version">0.3.0</param> + <param name="versionformat">0.3.0+git%cd.%h</param> <param name="url">git://github.com/openSUSE/libeconf.git</param> <param name="scm">git</param> <param name="changesgenerate">enable</param> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.rWMxF6/_old 2019-09-07 11:54:02.734268903 +0200 +++ /var/tmp/diff_new_pack.rWMxF6/_new 2019-09-07 11:54:02.734268903 +0200 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">git://github.com/openSUSE/libeconf.git</param> - <param name="changesrevision">51b65e3ce43682322a215097e45b6cd03b6c0abb</param> + <param name="changesrevision">af0058a82a453b558c2c7614979d2377a2091ee8</param> </service> </servicedata> \ No newline at end of file ++++++ libeconf-0.0.0+git20190902.dd17c11.tar.xz -> libeconf-0.3.0+git20190905.0ca8fe2.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/.github/workflows/ccpp.yml new/libeconf-0.3.0+git20190905.0ca8fe2/.github/workflows/ccpp.yml --- old/libeconf-0.0.0+git20190902.dd17c11/.github/workflows/ccpp.yml 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/.github/workflows/ccpp.yml 2019-09-05 10:05:36.000000000 +0200 @@ -1,6 +1,6 @@ name: C/C++ CI -on: [push] +on: [push, pull_request] jobs: build: @@ -17,5 +17,8 @@ run: make - name: make check run: make check + - name: check_failure + if: failure() + run: cat tests/test-suite.log - name: make distcheck run: make distcheck diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/NEWS new/libeconf-0.3.0+git20190905.0ca8fe2/NEWS --- old/libeconf-0.0.0+git20190902.dd17c11/NEWS 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/NEWS 2019-09-05 10:05:36.000000000 +0200 @@ -1,2 +1,5 @@ +Version 0.2.0 +* Reading of files is stable now + Version 0.1.0 * Initial release diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/README.md new/libeconf-0.3.0+git20190905.0ca8fe2/README.md --- old/libeconf-0.0.0+git20190902.dd17c11/README.md 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/README.md 2019-09-05 10:05:36.000000000 +0200 @@ -1,2 +1,40 @@ # libeconf -***TODO + +**libeconf** is a highly flexible and configureable library to parse and +manage key=value configuration files. +It reads configuration file snippets from different directories and builds +the final configuration file for the application from it. + +The first file is the vendor provided configuration file. There are +two methods of overriding this vendor settings: copy the file from +/usr/_vendordir_ to /etc and modify the settings. Alternatively, a +directory named _file_._suffix_.d/ within /etc can be created, with +drop-in files in the form _name_._suffix_. This files contain only the +changes of the specific settings the user is interested in. There can +be serveral such drop-in files, they are processed in lexicographic order +of their filename. + + +The first method is useful to override the complete configuration file with an +own one, the vendor supplied configuration is ignored. + +So, if /etc/_example_._suffix_ exists, /usr/_vendor_/_example_._suffix_ will +not be read. The disadvantage is, that changes of the vendor configuration +file are ignored and the user has to manually merge them. + +The other method will continue to use /usr/_vendor_/_example_._suffix_ as base +configuration file and merge all changes from +/etc/_example_._suffix_/*._suffix_. So the user will automatically get +improvements of the vendor, with the drawback, that they could be incompatible +with the user made changes. + +The list of files and directories read if no /etc/_example_._suffix_ file +exists: + +* /usr/_vendor_/_example_._suffix_ +* /usr/_vendor_/_example_._suffix_.d/*._suffix_ +* /etc/_example_._suffix_.d/*._suffix_ + +If a /etc/_example_._suffix_ files exists: +* /etc/_example_._suffix_ +* /etc/_example_._suffix_.d/*._suffix_ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/TODO.md new/libeconf-0.3.0+git20190905.0ca8fe2/TODO.md --- old/libeconf-0.0.0+git20190902.dd17c11/TODO.md 1970-01-01 01:00:00.000000000 +0100 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/TODO.md 2019-09-05 10:05:36.000000000 +0200 @@ -0,0 +1,17 @@ +# libeconf TODO + +* Implement/Fix parts marked with TODO or XXX +* Reformat the code (should have uniform coding style) +* Complete NULL value and error checking +* Rework internal data structure for better group and key handling: + * adding new groups and keys + * faster searching + * deletion of groups and keys +* Rework function to write the configuration to a file +* Implement a function to write the changes back into the source file +* Support for comments: comments should be preserved when rewriting a file +* Support writing files into a '.d' directory. +* Implement econf_setOpt function to modify behavior of loading a + configuration file for special cases +* Add more to the list ... + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/configure.ac new/libeconf-0.3.0+git20190905.0ca8fe2/configure.ac --- old/libeconf-0.0.0+git20190902.dd17c11/configure.ac 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/configure.ac 2019-09-05 10:05:36.000000000 +0200 @@ -1,4 +1,4 @@ -AC_INIT([libeconf], [0.1.0]) +AC_INIT([libeconf], [0.2.0]) AC_SUBST(PACKAGE) AC_SUBST(VERSION) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/include/defines.h new/libeconf-0.3.0+git20190905.0ca8fe2/include/defines.h --- old/libeconf-0.0.0+git20190902.dd17c11/include/defines.h 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/include/defines.h 2019-09-05 10:05:36.000000000 +0200 @@ -23,16 +23,20 @@ #pragma once +/* --- defines.h --- */ + #include "../include/helpers.h" -// Default econf_file length on creation +/* Defines default values used in the library */ + +/* Default econf_file length on creation */ #define KEY_FILE_DEFAULT_LENGTH 8 -// NULL value +/* NULL value */ #define KEY_FILE_NULL_VALUE "_none_" #define KEY_FILE_NULL_VALUE_HASH hashstring(KEY_FILE_NULL_VALUE) -// Bool values +/* Bool values */ #define YES hashstring("yes") #define NO hashstring("no") #define TRUE hashstring("true") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/include/getfilecontents.h new/libeconf-0.3.0+git20190905.0ca8fe2/include/getfilecontents.h --- old/libeconf-0.0.0+git20190902.dd17c11/include/getfilecontents.h 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/include/getfilecontents.h 2019-09-05 10:05:36.000000000 +0200 @@ -28,12 +28,5 @@ #include "libeconf.h" #include "keyfile.h" -// Fill the Key File struct with values from the given file handle -extern econf_err fill_key_file(econf_file *read_file, FILE *kf, const char *delim); - -// Write the group/value entry to the given file_entry -extern void end_of_line(struct file_entry **fe, size_t *len, size_t *lnum, size_t vlen, - char *buffer); - -// Check whether the key file has enough memory allocated, if not realloc -extern void new_kf_line(struct file_entry **fe, size_t *file_length, size_t *lnum); +/* Fill the econf_file struct with values from the given file handle */ +extern econf_err fill_key_file(econf_file *read_file, FILE *kf, const char *delim, const char *comment); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/include/helpers.h new/libeconf-0.3.0+git20190905.0ca8fe2/include/helpers.h --- old/libeconf-0.0.0+git20190902.dd17c11/include/helpers.h 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/include/helpers.h 2019-09-05 10:05:36.000000000 +0200 @@ -23,41 +23,52 @@ #pragma once +/* -- helpers.h --- */ + #include "keyfile.h" -// Combine file path and file name +/* This file contains the declaration of functions used by other functions to + perform certain basic tasks on multiple instances. */ + + +/* Combine the two given strings with the given delimiter and return the + resulting string. */ char *combine_strings(const char *string_one, const char *string_two, const char delimiter); -// Remove whitespace from beginning and end, append string terminator +/* Remove whitespace from beginning and end, append string terminator */ char *clearblank(size_t *vlen, char *string); -// Returns the absolute path of a given path +/* Returns the absolute path of a given path */ char *get_absolute_path(const char *path, econf_err *error); -// Remove '[' and ']' from beginning and end +/* Remove '[' and ']' from beginning and end */ +/* TODO: Function is currently not in use. But needs to be used to strip + the brackets from group elements before returning them to the user */ char *stripbrackets(char *string); -// Add '[' and ']' to the given string +/* Add '[' and ']' to the given string */ char *addbrackets(const char *string); -// Set default value defined in include/defines.h +/* Set default value defined in include/defines.h */ void initialize(econf_file *key_file, size_t num); -// Return the lower case version of a string +/* Return the lower case version of a string */ char *toLowerCase(char *str); -// Turn given string into a hash value +/* Turn given string into a hash value */ size_t hashstring(const char *str); -// Look for matching key +/* Look for a matching key in the given econf_file. + If the key is found num will point to the number of the array which contains + the key, if not it will point to -1. */ econf_err find_key(econf_file key_file, const char *group, const char *key, size_t *num); -// Set value for the given group, key combination. If the combination -// does not exist it is created. +/* Set value for the given group, key combination. If the combination + does not exist it is created. */ econf_err setKeyValue(econf_err (*function) (econf_file*, size_t, const void*), econf_file *kf, const char *group, const char *key, const void *value); -// Copy the contents of a file_entry struct +/* Copy the contents of a file_entry struct */ struct file_entry cpy_file_entry(struct file_entry fe); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/include/keyfile.h new/libeconf-0.3.0+git20190905.0ca8fe2/include/keyfile.h --- old/libeconf-0.0.0+git20190902.dd17c11/include/keyfile.h 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/include/keyfile.h 2019-09-05 10:05:36.000000000 +0200 @@ -23,22 +23,52 @@ #pragma once +/* --- keyfile.h --- */ + #include <stdint.h> #include <stdbool.h> #include <stdlib.h> +/* This file contains the definition of the econf_file struct declared in + libeconf.h as well as the functions to get and set a specified element + of the struct. All functions return an error code != 0 on error defined + in libeconf.h. */ + + +/* Definition of the econf_file struct and its inner file_entry struct. */ typedef struct econf_file { + /* The file_entry struct contains the group, key and value of every + key/value entry found in a config file or set via the set functions. If no + group is found or provided the group is set to KEY_FILE_NULL_VALUE. */ struct file_entry { char *group, *key, *value; } * file_entry; + /* length represents the current amount of key/value entries in econf_file and + alloc_length the the amount of currently allocated file_entry elements + within the struct. If length would exceed alloc_length it's increased. */ size_t length, alloc_length; + /* delimiter: char used to assign a value to a key + comment: Used to specify which char to regard as comment indicator. */ + /* TODO: Should eventually be of type *char to allow multiple character + delimiters and comment indicators. + Alternatively they could be removed from the struct and be passed + as parameters to the read/write functions for config files */ char delimiter, comment; + /* Binary variable to determine whether econf_file should be freed after + being merged with another econf_file. */ bool on_merge_delete; } econf_file; +/* Increases both length and alloc_length of key_file by one and initializes + new elements of struct file_entry. */ econf_err key_file_append(econf_file *key_file); /* GETTERS */ + +/* Functions used to get a set value from key_file depending on num. + Expects a pointer of fitting type and writes the result into the pointer. + num corresponds to the respective instance of the file_entry array. + TODO: Error checking and defining return value on error needs to done. */ econf_err getIntValueNum(econf_file key_file, size_t num, int32_t *result); econf_err getInt64ValueNum(econf_file key_file, size_t num, int64_t *result); econf_err getUIntValueNum(econf_file key_file, size_t num, uint32_t *result); @@ -49,8 +79,16 @@ econf_err getBoolValueNum(econf_file key_file, size_t num, bool *result); /* SETTERS */ + +/* Set the group of the file_entry element number num */ econf_err setGroup(econf_file *key_file, size_t num, const char *value); +/* Set the key of the file_entry element number num */ econf_err setKey(econf_file *key_file, size_t num, const char *value); + +/* Functions used to set a value from key_file depending on num. + Expects a void pointer to the value which is cast to the corresponding + type inside the function. num corresponds to the respective instance of the + file_entry array. */ econf_err setIntValueNum(econf_file *key_file, size_t num, const void *value); econf_err setInt64ValueNum(econf_file *key_file, size_t num, const void *value); econf_err setUIntValueNum(econf_file *key_file, size_t num, const void *value); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/include/libeconf.h new/libeconf-0.3.0+git20190905.0ca8fe2/include/libeconf.h --- old/libeconf-0.0.0+git20190902.dd17c11/include/libeconf.h 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/include/libeconf.h 2019-09-05 10:05:36.000000000 +0200 @@ -19,15 +19,19 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ #pragma once +/* libeconf.h */ + #include <stdbool.h> #include <stdint.h> #include <stdlib.h> +/* Public API for the econf library */ + + /* libeconf error codes */ enum econf_err { ECONF_SUCCESS = 0, /* General purpose success code */ @@ -36,20 +40,22 @@ ECONF_NOFILE = 3, /* Config file not found */ ECONF_NOGROUP = 4, /* Group not found */ ECONF_NOKEY = 5, /* Key not found */ - ECONF_EMPTYKEY = 6, /* Key has empty vaue */ - ECONF_WRITEERROR = 7 /* Error creating or writing to a file */ + ECONF_EMPTYKEY = 6, /* Key has empty value */ + ECONF_WRITEERROR = 7, /* Error creating or writing to a file */ + ECONF_PARSE_ERROR = 8 /* Syntax error in input file */ }; + typedef enum econf_err econf_err; -// Generic macro calls setter function depending on value type -// Use: econf_setValue(econf_file *key_file, char *group, char *key, -// _generic_ value); -// Replace _generic_ with one of the supported value types. -// Supported Types: int, long, unsigned int, unsigned long, float, double, -// string (as *char). -// Note: Does not detect "yes", "no", 1 and 0 as boolean type. If you want to -// set a bool value use "true" or "false" or use setBoolValue() directly. -#define econf_setValue(kf, group, key, value) (( \ +/* Generic macro calls setter function depending on value type + Use: econf_setValue(econf_file *key_file, char *group, char *key, + _generic_ value); + Replace _generic_ with one of the supported value types. + Supported Types: int, long, unsigned int, unsigned long, float, double, + string (as *char). + Note: Does not detect "yes", "no", 1 and 0 as boolean type. If you want to + set a bool value use "true" or "false" or use setBoolValue() directly. */ +#define econf_setValue(kf, group, key, value) (( \ _Generic((value), \ int: econf_setIntValue, \ long: econf_setInt64Value, \ @@ -60,10 +66,10 @@ char*: econf_setStringValue, void*: econf_setStringValue)) \ (kf, group, key, value)) -// Generic macro to free memory allocated by econf_ functions -// Use: econf_free(_generic_ value); -// Replace _generic_ with one of the supported value types. -// Supported Types: char** and econf_file* +/* Generic macro to free memory allocated by econf_ functions + Use: econf_free(_generic_ value); + Replace _generic_ with one of the supported value types. + Supported Types: char** and econf_file*. */ #define econf_free(value) (( \ _Generic((value), \ econf_file*: econf_freeFile , \ @@ -90,10 +96,12 @@ /* The API/ABI of the following three functions (econf_newKeyFile, econf_newIniFile and econf_writeFile) are not stable and will change */ + +/* Create a new econf_file object */ extern econf_err econf_newKeyFile(econf_file **result, char delimiter, char comment); extern econf_err econf_newIniFile(econf_file **result); -// Write content of a econf_file struct to specified location +/* Write content of a econf_file struct to specified location */ extern econf_err econf_writeFile(econf_file *key_file, const char *save_to_dir, const char *file_name); @@ -111,6 +119,17 @@ extern econf_err econf_getStringValue(econf_file *kf, const char *group, const char *key, char **result); extern econf_err econf_getBoolValue(econf_file *kf, const char *group, const char *key, bool *result); +/* If key is not found, the default value is returned and error is ECONF_NOKEY */ +extern econf_err econf_getIntValueDef(econf_file *kf, const char *group, const char *key, int32_t *result, int32_t def); +extern econf_err econf_getInt64ValueDef(econf_file *kf, const char *group, const char *key, int64_t *result, int64_t def); +extern econf_err econf_getUIntValueDef(econf_file *kf, const char *group, const char *key, uint32_t *result, uint32_t def); +extern econf_err econf_getUInt64ValueDef(econf_file *kf, const char *group, const char *key, uint64_t *result, uint64_t def); +extern econf_err econf_getFloatValueDef(econf_file *kf, const char *group, const char *key, float *result, float def); +extern econf_err econf_getDoubleValueDef(econf_file *kf, const char *group, const char *key, double *result, double def); +/* Returns a newly allocated string, even if "default" is returned. */ +extern econf_err econf_getStringValueDef(econf_file *kf, const char *group, const char *key, char **result, char *def); +extern econf_err econf_getBoolValueDef(econf_file *kf, const char *group, const char *key, bool *result, bool def); + /* --- SETTERS --- */ extern econf_err econf_setIntValue(econf_file *kf, const char *group, const char *key, int32_t value); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/include/mergefiles.h new/libeconf-0.3.0+git20190905.0ca8fe2/include/mergefiles.h --- old/libeconf-0.0.0+git20190902.dd17c11/include/mergefiles.h 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/include/mergefiles.h 2019-09-05 10:05:36.000000000 +0200 @@ -27,28 +27,30 @@ #include <stddef.h> -// Insert the content of "etc_file.file_entry" into "fe" if there is no -// group specified -// "[]", ef: etc_file +/* This file contains the declaration of the functions used by econf_mergeFiles + to merge the contents of two econf_files. */ + + +/* Insert the content of "etc_file.file_entry" into "fe" if there is no + group specified. */ size_t insert_nogroup(struct file_entry **fe, econf_file *ef); -// Merge contents from existing usr_file groups -// uf: usr_file, ef: etc_file +/* Merge contents from existing usr_file groups */ size_t merge_existing_groups(struct file_entry **fe, econf_file *uf, econf_file *ef, const size_t etc_start); -// Add entries from etc_file exclusive groups +/* Add entries from etc_file exclusive groups */ size_t add_new_groups(struct file_entry **fe, econf_file *uf, econf_file *ef, const size_t merge_length); -// Returns the default dirs to iterate through when merging +/* Returns the default dirs to iterate through when merging */ char **get_default_dirs(const char *usr_conf_dir, const char *etc_conf_dir); -// Receives a list of config directories to look for and calls 'check_conf_dir' +/* Receives a list of config directories to look for and calls 'check_conf_dir' */ econf_file **traverse_conf_dirs(econf_file **key_files, const char *conf_dirs[], size_t *size, const char *path, - const char *config_suffix, + const char *config_suffix, const char *delim, const char *comment); -// Merge an array of given econf_files into one +/* Merge an array of given econf_files into one */ econf_err merge_econf_files(econf_file **key_files, econf_file **merged_files); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/lib/Makefile.am new/libeconf-0.3.0+git20190905.0ca8fe2/lib/Makefile.am --- old/libeconf-0.0.0+git20190902.dd17c11/lib/Makefile.am 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/lib/Makefile.am 2019-09-05 10:05:36.000000000 +0200 @@ -1,5 +1,5 @@ lib_LTLIBRARIES = libeconf.la -libeconf_la_SOURCES = ../src/libeconf.c ../src/getfilecontents.c ../src/mergefiles.c ../src/helpers.c ../src/keyfile.c ../src/econf_errString.c +libeconf_la_SOURCES = ../src/libeconf.c ../src/getfilecontents.c ../src/mergefiles.c ../src/helpers.c ../src/keyfile.c ../src/econf_errString.c ../src/get_value_def.c libeconf_la_CFLAGS = -D_REENTRANT=1 @CFLAGS_CHECKS@ @CFLAGS_WARNINGS@ libeconf_la_CPPFLAGS = -I$(top_srcdir)/include libeconf_la_LDFLAGS = @LDFLAGS_CHECKS@ @CFLAGS_WARNINGS@ \ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/lib/libeconf.map new/libeconf-0.3.0+git20190905.0ca8fe2/lib/libeconf.map --- old/libeconf-0.0.0+git20190902.dd17c11/lib/libeconf.map 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/lib/libeconf.map 2019-09-05 10:05:36.000000000 +0200 @@ -33,3 +33,16 @@ econf_newKeyFile; econf_writeFile; } LIBECONF_0.2; +LIBECONF_0.3 { + global: + econf_getBoolValueDef; + econf_getDoubleValueDef; + econf_getFloatValueDef; + econf_getGroupsDef; + econf_getInt64ValueDef; + econf_getIntValueDef; + econf_getKeysDef; + econf_getStringValueDef; + econf_getUInt64ValueDef; + econf_getUIntValueDef; +} LIBECONF_0.2; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/src/econf_errString.c new/libeconf-0.3.0+git20190905.0ca8fe2/src/econf_errString.c --- old/libeconf-0.0.0+git20190902.dd17c11/src/econf_errString.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/src/econf_errString.c 2019-09-05 10:05:36.000000000 +0200 @@ -36,7 +36,8 @@ "Group not found", /* ECONF_NOGROUP */ "Key not found", /* ECONF_NOKEY */ "Key has empty value", /* ECONF_EMPTYKEY */ - "Error creating or writing to a file" /* ECONF_WRITEERROR */ + "Error creating or writing to a file", /* ECONF_WRITEERROR */ + "Parse error" /* ECONF_PARSE_ERROR */ }; const char * diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/src/get_value_def.c new/libeconf-0.3.0+git20190905.0ca8fe2/src/get_value_def.c --- old/libeconf-0.0.0+git20190902.dd17c11/src/get_value_def.c 1970-01-01 01:00:00.000000000 +0100 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/src/get_value_def.c 2019-09-05 10:05:36.000000000 +0200 @@ -0,0 +1,51 @@ +/* + Copyright (C) 2019 SUSE LLC + Author: Thorsten Kukuk <[email protected]> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> +#include "libeconf.h" + +#define econf_getValueDef(FCT_TYPE, TYPE, STRDUP) \ +econf_err econf_get ## FCT_TYPE ## ValueDef(econf_file *ef, const char *group, \ + const char *key, TYPE *result, TYPE def) { \ + if (!ef) \ + return ECONF_ERROR; \ +\ + econf_err error = econf_get ## FCT_TYPE ## Value(ef, group, key, result); \ + if (error == ECONF_NOKEY) \ + *result = STRDUP(def); \ + return error; \ +} + + +econf_getValueDef(Int, int32_t, ) +econf_getValueDef(Int64, int64_t, ) +econf_getValueDef(UInt, uint32_t, ) +econf_getValueDef(UInt64, uint64_t, ) +econf_getValueDef(Float, float, ) +econf_getValueDef(Double, double, ) +econf_getValueDef(String, char *, strdup) +econf_getValueDef(Bool, bool, ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/src/getfilecontents.c new/libeconf-0.3.0+git20190905.0ca8fe2/src/getfilecontents.c --- old/libeconf-0.0.0+git20190902.dd17c11/src/getfilecontents.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/src/getfilecontents.c 2019-09-05 10:05:36.000000000 +0200 @@ -30,10 +30,47 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <ctype.h> + +#if 0 + +// Check whether the key file has enough memory allocated, if not realloc +static void new_kf_line(struct file_entry **fe, size_t *file_length, size_t *lnum) { + if (++(*file_length) >= *lnum) { + *fe = realloc(*fe, *lnum * 2 * sizeof(struct file_entry)); /* XXX ENOMEM check missing */ + (*lnum) *= 2; + } + (*fe)[*file_length].group = KEY_FILE_NULL_VALUE; + (*fe)[*file_length].key = KEY_FILE_NULL_VALUE; +} + +// Write the group/value entry to the given file_entry +static void end_of_line(struct file_entry **fe, size_t *len, size_t *lnum, size_t vlen, + char *buffer) { + // Remove potential whitespaces from beginning and end + buffer = clearblank(&vlen, buffer); + // If a newline char is encountered and the line had no delimiter + // the line is expected to be a group + // In this case key is not set + if (!strcmp((*fe)[*len].key, KEY_FILE_NULL_VALUE)) { + if(!*len) { free((*fe)->group); } + (*fe)[*len].group = strndup(buffer, vlen); /* XXX ENOMEM check missing */ + } else { + // If the line is no new group copy the group from the previous line + if (*len && !strcmp((*fe)[*len].group, KEY_FILE_NULL_VALUE)) { + (*fe)[*len].group = strdup((*fe)[*len - 1].group); /* XXX ENOMEM check missing */ + } + // If the line had a delimiter everything after the delimiter is + // considered to be a value + (*fe)[*len].value = strndup(buffer, vlen); /* XXX ENOMEM check missing */ + // Perform memory check and increase len by one + new_kf_line(fe, len, lnum); + } +} // Fill the Key File struct with values from the given file handle econf_err -fill_key_file(econf_file *read_file, FILE *kf, const char *delim) { +fill_key_file(econf_file *read_file, FILE *kf, const char *delim, const char *comments) { // KEY_FILE_DEFAULT_LENGTH: Default number of key-value pairs to be // allocated in key_file // LLEN: Base number of chars in a key, value or group name @@ -85,7 +122,8 @@ // be a key. else if (strchr(delim, ch) != NULL && !strcmp(fe[file_length].key, KEY_FILE_NULL_VALUE)) { - if(!file_length) { read_file->delimiter = ch; } + if(!file_length) + read_file->delimiter = ch; buffer = clearblank(&vlen, buffer); fe[file_length].key = strndup(buffer, vlen); if (fe[file_length].key == NULL) @@ -93,7 +131,7 @@ } // If the line contains the given comment char ignore the rest // of the line and proceed with the next - else if (ch == read_file->comment) { + else if (ch == comments[0]) { if (vlen != 0) { end_of_line(&fe, &file_length, &lnum, vlen, buffer); } vlen = getline(&buffer, &llen, kf); } @@ -127,36 +165,131 @@ return ECONF_SUCCESS; } -// Write the group/value entry to the given file_entry -void end_of_line(struct file_entry **fe, size_t *len, size_t *lnum, size_t vlen, - char *buffer) { - // Remove potential whitespaces from beginning and end - buffer = clearblank(&vlen, buffer); - // If a newline char is encountered and the line had no delimiter - // the line is expected to be a group - // In this case key is not set - if (!strcmp((*fe)[*len].key, KEY_FILE_NULL_VALUE)) { - if(!*len) { free((*fe)->group); } - (*fe)[*len].group = strndup(buffer, vlen); /* XXX ENOMEM check missing */ - } else { - // If the line is no new group copy the group from the previous line - if (*len && !strcmp((*fe)[*len].group, KEY_FILE_NULL_VALUE)) { - (*fe)[*len].group = strdup((*fe)[*len - 1].group); /* XXX ENOMEM check missing */ - } - // If the line had a delimiter everything after the delimiter is - // considered to be a value - (*fe)[*len].value = strndup(buffer, vlen); /* XXX ENOMEM check missing */ - // Perform memory check and increase len by one - new_kf_line(fe, len, lnum); +#else + +static econf_err +store (econf_file *file, const char *group, const char *key, const char *value) +{ + if (file->alloc_length == file->length) { + struct file_entry *tmp; + + tmp = realloc(file->file_entry, (file->length + 1) * sizeof(struct file_entry)); + if (!tmp) + return ECONF_NOMEM; + file->file_entry = tmp; + file->length++; + file->alloc_length = file->length; } + + if (group) + file->file_entry[file->length-1].group = strdup(group); + else + file->file_entry[file->length-1].group = strdup(KEY_FILE_NULL_VALUE); + + if (key) + file->file_entry[file->length-1].key = strdup(key); + else + file->file_entry[file->length-1].key = strdup(KEY_FILE_NULL_VALUE); + + if (value) + file->file_entry[file->length-1].value = strdup(value); + else + file->file_entry[file->length-1].value = NULL; + + return ECONF_SUCCESS; } -// Check whether the key file has enough memory allocated, if not realloc -void new_kf_line(struct file_entry **fe, size_t *file_length, size_t *lnum) { - if (++(*file_length) >= *lnum) { - *fe = realloc(*fe, *lnum * 2 * sizeof(struct file_entry)); /* XXX ENOMEM check missing */ - (*lnum) *= 2; +// Fill the Key File struct with values from the given file handle +econf_err +fill_key_file(econf_file *read_file, FILE *kf, const char *delim, const char *comment) +{ + char buf[BUFSIZ]; + char *current_group = NULL; + econf_err retval = ECONF_SUCCESS; + + while (fgets(buf, sizeof(buf), kf)) { + char *p, *name, *data = NULL; + + if (*buf == '\n') + continue; /* ignore empty lines */ + + /* go throug all comment characters and check, if one of could be found */ + for (size_t i = 0; i < strlen(comment); i++) { + p = strchr(buf, comment[i]); + if (p) + *p = '\0'; + } + + /* Remove trailing newline character */ + size_t n = strlen(buf); + if (n && *(buf + n - 1) == '\n') + *(buf + n - 1) = '\0'; + + if (!*buf) + continue; /* empty line */ + + /* ignore space at begin of the line */ + name = buf; + while (*name && isspace((unsigned)*name)) + name++; + + /* check for groups */ + if (name[0] == '[') { + p = name + strlen(name) - 1; + /* XXX Remove [] around group name */ + while (isspace (*p)) p--; + if (*p != ']') { + retval = ECONF_PARSE_ERROR; + goto out; + } + p++; + *p = '\0'; + if (current_group) + free (current_group); + current_group = strdup (name); + continue; + } + + /* go to the end of the name */ + data = name; + while (*data && !(isspace((unsigned)*data) || + strchr(delim, *data) != NULL)) + data++; + if (data > name && *data) + *data++ = '\0'; + + if (!*name || data == name) + continue; + + if (*data == '\0') + /* No seperator -> return NULL pointer, there is no value, + not even an empty key */ + data = NULL; + else { + /* go to the begin of the value */ + while (*data + && (isspace((unsigned)*data) || strchr(delim, *data) != NULL + || *data == '"')) + data++; + + /* remove space at the end of the value */ + p = data + strlen(data); + if (p > data) + p--; + while (p > data && (isspace((unsigned)*p) || *p == '"')) + *p-- = '\0'; + } + + retval = store(read_file, current_group, name, data); + if (retval) + goto out; } - (*fe)[*file_length].group = KEY_FILE_NULL_VALUE; - (*fe)[*file_length].key = KEY_FILE_NULL_VALUE; + + out: + if (current_group) + free (current_group); + + return retval; } + +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/src/keyfile.c new/libeconf-0.3.0+git20190905.0ca8fe2/src/keyfile.c --- old/libeconf-0.0.0+git20190902.dd17c11/src/keyfile.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/src/keyfile.c 2019-09-05 10:05:36.000000000 +0200 @@ -78,17 +78,28 @@ } econf_err getStringValueNum(econf_file key_file, size_t num, char **result) { - *result = strdup(key_file.file_entry[num].value); + if (key_file.file_entry[num].value) + *result = strdup(key_file.file_entry[num].value); + else + *result = NULL; + return ECONF_SUCCESS; } econf_err getBoolValueNum(econf_file key_file, size_t num, bool *result) { - size_t hash = hashstring(key_file.file_entry[num].value); - if (hash == TRUE) { + char *value, *tmp; + tmp = strdupa(key_file.file_entry[num].value); + value = toLowerCase(tmp); + size_t hash = hashstring(toLowerCase(key_file.file_entry[num].value)); + + if ((*value == '1' && strlen(tmp) == 1) || hash == YES || hash == TRUE) *result = true; - } else if (hash == FALSE) { + else if ((*value == '0' && strlen(tmp) == 1) || !*value || + hash == NO || hash == FALSE) *result = false; - } + else + return ECONF_PARSE_ERROR; + return ECONF_SUCCESS; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/src/libeconf.c new/libeconf-0.3.0+git20190905.0ca8fe2/src/libeconf.c --- old/libeconf-0.0.0+git20190902.dd17c11/src/libeconf.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/src/libeconf.c 2019-09-05 10:05:36.000000000 +0200 @@ -88,7 +88,7 @@ if (kf == NULL) return ECONF_NOFILE; - *key_file = malloc(sizeof(econf_file)); + *key_file = calloc(1, sizeof(econf_file)); if (*key_file == NULL) { fclose (kf); return ECONF_NOMEM; @@ -98,11 +98,8 @@ (*key_file)->comment = comment[0]; else (*key_file)->comment = '#'; - (*key_file)->length = 0; - (*key_file)->alloc_length = 0; - t_err = fill_key_file(*key_file, kf, delim); - (*key_file)->on_merge_delete = 0; + t_err = fill_key_file(*key_file, kf, delim, comment); fclose(kf); if(t_err) { @@ -164,7 +161,8 @@ econf_err error; /* config_suffix must be provided and should not be "" */ - if (config_suffix == NULL || strlen (config_suffix) == 0 || delim == NULL) + if (config_suffix == NULL || strlen (config_suffix) == 0 || + project_name == NULL || strlen (project_name) == 0 || delim == NULL) return ECONF_ERROR; // Prepend a . to the config suffix if not provided @@ -179,37 +177,54 @@ } /* create file names for etc and distribution config */ - distfile = alloca(strlen (dist_conf_dir) + strlen (project_name) + - strlen (suffix) + 2); - etcfile = alloca(strlen (etc_conf_dir) + strlen (project_name) + - strlen (suffix) + 2); - - cp = stpcpy (distfile, dist_conf_dir); - *cp++ = '/'; - cp = stpcpy (cp, project_name); - stpcpy (cp, suffix); - - cp = stpcpy (etcfile, etc_conf_dir); - *cp++ = '/'; - cp = stpcpy (cp, project_name); - stpcpy (cp, suffix); - - error = econf_readFile(&key_file, etcfile, delim, comment); - if (error && error != ECONF_NOFILE) - return error; + if (dist_conf_dir != NULL) + { + distfile = alloca(strlen (dist_conf_dir) + strlen (project_name) + + strlen (suffix) + 2); + + cp = stpcpy (distfile, dist_conf_dir); + *cp++ = '/'; + cp = stpcpy (cp, project_name); + stpcpy (cp, suffix); + } + else + distfile = NULL; + + if (etc_conf_dir != NULL) + { + etcfile = alloca(strlen (etc_conf_dir) + strlen (project_name) + + strlen (suffix) + 2); + + cp = stpcpy (etcfile, etc_conf_dir); + *cp++ = '/'; + cp = stpcpy (cp, project_name); + stpcpy (cp, suffix); + } + else + etcfile = NULL; - if (!error) { + if (etcfile) + { + error = econf_readFile(&key_file, etcfile, delim, comment); + if (error && error != ECONF_NOFILE) + return error; + } + + if (etcfile && !error) { /* /etc/<project_name>.<suffix> does exist, ignore /usr */ default_dirs[0] = etc_conf_dir; size = 1; } else { /* /etc/<project_name>.<suffix> does not exist, so read /usr/etc and merge all *.d files. */ - error = econf_readFile(&key_file, distfile, delim, comment); - if (error && error != ECONF_NOFILE) - return error; + if (distfile) + { + error = econf_readFile(&key_file, distfile, delim, comment); + if (error && error != ECONF_NOFILE) + return error; + } - if (!error) /* /usr/etc/<project_name>.<suffix> does exist */ + if (distfile && !error) /* /usr/etc/<project_name>.<suffix> does exist */ size = 1; default_dirs[0] = dist_conf_dir; @@ -235,11 +250,13 @@ /* Indicate which directories to look for. The order is: "default_dirs/project_name.suffix.d/" + + XXX make this configureable: "default_dirs/project_name/conf.d/" "default_dirs/project_name.d/" "default_dirs/project_name/" */ - const char *conf_dirs[] = { NULL, "/conf.d/", ".d/", "/", NULL}; + const char *conf_dirs[] = { NULL, /* "/conf.d/", ".d/", "/", */ NULL}; char *project_path = combine_strings(default_dirs[i], project_name, '/'); char *suffix_d = malloc (strlen(suffix) + 4); /* + strlen(".d/") */ /* XXX ENOMEM/NULL pointer check */ @@ -259,7 +276,10 @@ error = merge_econf_files(key_files, result); free(key_files); - return error; + if (size == 1) + return ECONF_NOFILE; + else + return error; } // Write content of a econf_file struct to specified location @@ -378,7 +398,7 @@ if (!tmp) { free (uniques); - return ECONF_ERROR; + return ECONF_NOKEY; } *keys = calloc(tmp + 1, sizeof(char*)); if (*keys == NULL) { @@ -453,12 +473,19 @@ // Free memory allocated by key_file void econf_freeFile(econf_file *key_file) { - if (!key_file) { return; } + if (!key_file) + return; + for (size_t i = 0; i < key_file->alloc_length; i++) { - free(key_file->file_entry[i].group); - free(key_file->file_entry[i].key); - free(key_file->file_entry[i].value); + if (key_file->file_entry[i].group) + free(key_file->file_entry[i].group); + if (key_file->file_entry[i].key) + free(key_file->file_entry[i].key); + if (key_file->file_entry[i].value) + free(key_file->file_entry[i].value); } - free(key_file->file_entry); + + if (key_file->file_entry) + free(key_file->file_entry); free(key_file); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/Makefile.am new/libeconf-0.3.0+git20190905.0ca8fe2/tests/Makefile.am --- old/libeconf-0.0.0+git20190902.dd17c11/tests/Makefile.am 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/Makefile.am 2019-09-05 10:05:36.000000000 +0200 @@ -4,12 +4,14 @@ CLEANFILES = *~ -EXTRA_DIST = tst-arguments-data tst-logindefs1-data tst-merge1-data \ - tst-merge2-data tst-getconfdirs1-data tst-getconfdirs3-data \ +EXTRA_DIST = tst-arguments-data tst-logindefs1-data tst-logindefs2-data \ + tst-merge1-data tst-merge2-data \ + tst-getconfdirs1-data tst-getconfdirs3-data \ tst-getconfdirs4-data tst-getconfdirs5-data tst-getconfdirs6-data \ tst-arguments5-data tst-groups3-data tst-parseconfig-data -TESTS = tst-filedoesnotexit1 tst-merge1 tst-merge2 tst-logindefs1 \ +TESTS = tst-filedoesnotexit1 tst-merge1 tst-merge2 \ + tst-logindefs1 tst-logindefs2 \ tst-arguments1 tst-arguments2 tst-arguments3 tst-arguments4 \ tst-arguments5 \ tst-getconfdirs1 tst-getconfdirs2 tst-getconfdirs3 \ @@ -19,7 +21,7 @@ tst-groups1 tst-groups2 tst-groups3 tst-groups4 \ tst-parseconfig1 -XFAIL_TESTS = tst-groups3 tst-parseconfig1 +XFAIL_TESTS = tst-getconfdirs5 check_PROGRAMS = ${TESTS} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments1.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments1.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments1.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments1.c 2019-09-05 10:05:36.000000000 +0200 @@ -15,7 +15,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; char *val; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments2.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments2.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments2.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments2.c 2019-09-05 10:05:36.000000000 +0200 @@ -14,7 +14,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; char *val; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments3.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments3.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments3.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments3.c 2019-09-05 10:05:36.000000000 +0200 @@ -14,7 +14,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; char *val; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments4.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments4.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments4.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments4.c 2019-09-05 10:05:36.000000000 +0200 @@ -14,7 +14,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; char *val; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments5.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments5.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-arguments5.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-arguments5.c 2019-09-05 10:05:36.000000000 +0200 @@ -14,7 +14,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; econf_err error; if ((error = econf_readFile (&key_file, TESTSDIR"tst-arguments5-data/etc/arguments5.conf", NULL, NULL))) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs1.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs1.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs1.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs1.c 2019-09-05 10:05:36.000000000 +0200 @@ -49,7 +49,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; int retval = 0; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs3.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs3.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs3.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs3.c 2019-09-05 10:05:36.000000000 +0200 @@ -48,7 +48,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; int retval = 0; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs4.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs4.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs4.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs4.c 2019-09-05 10:05:36.000000000 +0200 @@ -48,7 +48,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; int retval = 0; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs5.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs5.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs5.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs5.c 2019-09-05 10:05:36.000000000 +0200 @@ -46,7 +46,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; int retval = 0; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs6.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs6.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-getconfdirs6.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-getconfdirs6.c 2019-09-05 10:05:36.000000000 +0200 @@ -49,7 +49,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; int retval = 0; econf_err error; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-groups1.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-groups1.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-groups1.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-groups1.c 2019-09-05 10:05:36.000000000 +0200 @@ -64,7 +64,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; econf_err error; int retval = 0; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-groups2.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-groups2.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-groups2.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-groups2.c 2019-09-05 10:05:36.000000000 +0200 @@ -15,7 +15,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; char **groups; size_t group_number; const char *group = "towel"; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-groups3.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-groups3.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-groups3.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-groups3.c 2019-09-05 10:05:36.000000000 +0200 @@ -14,7 +14,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; char **groups; size_t group_number; char *val; @@ -30,16 +30,18 @@ if ((error = econf_getGroups(key_file, &group_number, &groups))) { fprintf (stderr, "Error getting all groups: %s\n", econf_errString(error)); + econf_free (key_file); return 1; } if (group_number == 0) { fprintf (stderr, "No groups found?\n"); + econf_free (key_file); return 1; } - if (group_number != 6) + if (group_number != 5) { - fprintf (stderr, "Wrong number of groups found, got %lu, expected 6\n", + fprintf (stderr, "Wrong number of groups found, got %lu, expected 5\n", group_number); retval = 1; } @@ -56,8 +58,11 @@ groups[i], econf_errString(error)); retval = 1; } - printf ("%lu: Group: %s, Value: %s\n", i, groups[i], val); - free (val); + else + { + printf ("%lu: Group: %s, Value: %s\n", i, groups[i], val); + free (val); + } } econf_free (groups); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-groups4.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-groups4.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-groups4.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-groups4.c 2019-09-05 10:05:36.000000000 +0200 @@ -15,7 +15,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; const char *group = "towel"; const char *key = "42"; const char *val = "The answer, not question"; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-logindefs1.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-logindefs1.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-logindefs1.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-logindefs1.c 2019-09-05 10:05:36.000000000 +0200 @@ -14,7 +14,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; char **keys; size_t key_number; char *val; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-logindefs2-data/logindefs.data new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-logindefs2-data/logindefs.data --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-logindefs2-data/logindefs.data 1970-01-01 01:00:00.000000000 +0100 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-logindefs2-data/logindefs.data 2019-09-05 10:05:36.000000000 +0200 @@ -0,0 +1,16 @@ +# +# this is /etc/login.defs sample +# + +HELLO_WORLD "hello world!" +STRING this_is_string # another comment +NUMBER 123456 +BOOLEAN yEs + +CRAZY1 = "this is crazy format" +CRAZY2=fooBar +CRAZY3 FoooBaaar + +EMPTY + +END "the is end" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-logindefs2.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-logindefs2.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-logindefs2.c 1970-01-01 01:00:00.000000000 +0100 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-logindefs2.c 2019-09-05 10:05:36.000000000 +0200 @@ -0,0 +1,174 @@ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdio.h> +#include <string.h> +#include <inttypes.h> + +#include "libeconf.h" + +/* Test case: + Open default logindefs.data from util-linux and try out if we can read + all entries +*/ + +int +main(void) +{ + econf_file *key_file = NULL; + char **keys; + size_t key_number; + econf_err error; + + if ((error = econf_readFile (&key_file, TESTSDIR"tst-logindefs2-data/logindefs.data", "= \t", "#"))) + { + fprintf (stderr, "ERROR: couldn't read configuration file: %s\n", econf_errString(error)); + return 1; + } + + if ((error = econf_getKeys(key_file, NULL, &key_number, &keys))) + { + fprintf (stderr, "Error getting all keys: %s\n", econf_errString(error)); + econf_free(key_file); + return 1; + } + if (key_number == 0) + { + fprintf (stderr, "No keys found?\n"); + econf_free(key_file); + return 1; + } + for (size_t i = 0; i < key_number; i++) + { + char *value = NULL; + econf_getStringValue(key_file, NULL, keys[i], &value); + printf ("%lu: %s: '%s'\n", i, keys[i], value); + if (value != NULL) + free (value); + } + + int retval = 0; + char *strval = NULL; + econf_getStringValue (key_file, NULL, "STRING", &strval); + if (strval == NULL || strcmp (strval, "this_is_string") != 0) + { + fprintf (stderr, "ERROR: %s, expected: %s, got: '%s'\n", + "STRING", "this_is_string", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + int intval = 0; + econf_getIntValue (key_file, NULL, "NUMBER", &intval); + if (intval == 0 || intval != 123456) + { + fprintf (stderr, "ERROR: %s, expected: %i, got: %i\n", + "NUMBER", 123456, intval); + retval = 1; + } + + bool boolval = false; + econf_getBoolValue (key_file, NULL, "BOOLEAN", &boolval); + if (boolval != true) + { + fprintf (stderr, "ERROR: %s, expected: %i, got: %i\n", + "BOOLEAN", true, boolval); + retval = 1; + } + + strval = NULL; + econf_getStringValue (key_file, NULL, "CRAZY1", &strval); + if (strval == NULL || strcmp (strval, "this is crazy format") != 0) + { + fprintf (stderr, "ERROR: %s, expected: '%s', got: '%s'\n", + "CRAZY1", "this is crazy format", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + strval = NULL; + econf_getStringValue (key_file, NULL, "CRAZY2", &strval); + if (strval == NULL || strcmp (strval, "fooBar") != 0) + { + fprintf (stderr, "ERROR: %s, expected: '%s', got: '%s'\n", + "CRAZY1", "fooBar", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + strval = NULL; + econf_getStringValue (key_file, NULL, "CRAZY3", &strval); + if (strval == NULL || strcmp (strval, "FoooBaaar") != 0) + { + fprintf (stderr, "ERROR: %s, expected: '%s', got: '%s'\n", + "CRAZY3", "FoooBaaar", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + + strval = NULL; + econf_getStringValue (key_file, NULL, "EMPTY", &strval); + if (strval != NULL) + { + fprintf (stderr, "ERROR: %s, expected: 'NULL', got: '%s'\n", + "EMPTY", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + strval = NULL; + econf_getStringValue (key_file, NULL, "END", &strval); + if (strval == NULL || strcmp (strval, "the is end") != 0) + { + fprintf (stderr, "ERROR: %s, expected: '%s', got: '%s'\n", + "END", "the is end", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + strval = NULL; + econf_getStringValue (key_file, NULL, "NOTEXIST", &strval); + if (strval != NULL) + { + fprintf (stderr, "ERROR: %s, expected: '%s', got: '%s'\n", + "NOTEXIST", "NULL", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + strval = NULL; + econf_getStringValue (key_file, NULL, "END", &strval); + if (strval == NULL || strcmp (strval, "the is end") != 0) + { + fprintf (stderr, "ERROR: %s, expected: '%s', got: '%s'\n", + "END", "the is end", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + strval = NULL; + econf_getStringValue (key_file, NULL, "NOTEXIST", &strval); + if (strval != NULL) + { + fprintf (stderr, "ERROR: %s, expected: '%s', got: '%s'\n", + "NOTEXIST", "NULL", strval?strval:"NULL"); + retval = 1; + } + if (strval) + free (strval); + + econf_free (keys); + econf_free (key_file); + + return retval; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-parseconfig1.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-parseconfig1.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-parseconfig1.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-parseconfig1.c 2019-09-05 10:05:36.000000000 +0200 @@ -14,7 +14,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; econf_err error; if ((error = econf_readFile (&key_file, TESTSDIR"tst-parseconfig-data/empty-group.conf", "=", "#"))) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-setgetvalues1.c new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-setgetvalues1.c --- old/libeconf-0.0.0+git20190902.dd17c11/tests/tst-setgetvalues1.c 2019-09-02 15:17:48.000000000 +0200 +++ new/libeconf-0.3.0+git20190905.0ca8fe2/tests/tst-setgetvalues1.c 2019-09-05 10:05:36.000000000 +0200 @@ -105,7 +105,7 @@ int main(void) { - econf_file *key_file; + econf_file *key_file = NULL; econf_err error; int retval = 0;
