Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package libeconf for openSUSE:Factory checked in at 2022-11-27 12:52:45 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libeconf (Old) and /work/SRC/openSUSE:Factory/.libeconf.new.1597 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libeconf" Sun Nov 27 12:52:45 2022 rev:17 rq:1038196 version:0.4.9 Changes: -------- --- /work/SRC/openSUSE:Factory/libeconf/libeconf.changes 2022-11-18 15:42:33.254304054 +0100 +++ /work/SRC/openSUSE:Factory/.libeconf.new.1597/libeconf.changes 2022-11-27 12:52:49.755137350 +0100 @@ -1,0 +2,9 @@ +Wed Nov 23 14:01:34 UTC 2022 - sch...@suse.com + +- Update to version 0.4.9: + * libeconf.h: added missing sys/types.h header (#171) + * new API calls: econf_readFileWithCallback, + econf_readDirsWithCallback, econf_readDirsHistoryWithCallback (#172) + * Checking NULL comment parameter in the parsing functions. + +------------------------------------------------------------------- Old: ---- libeconf-0.4.8+git20221114.7ff7704.tar.xz New: ---- libeconf-0.4.9.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libeconf.spec ++++++ --- /var/tmp/diff_new_pack.G8WziL/_old 2022-11-27 12:52:51.139145380 +0100 +++ /var/tmp/diff_new_pack.G8WziL/_new 2022-11-27 12:52:51.143145403 +0100 @@ -18,7 +18,7 @@ %define lname libeconf0 Name: libeconf -Version: 0.4.8+git20221114.7ff7704 +Version: 0.4.9 Release: 0 Summary: Enhanced config file parser ala systemd License: LGPL-2.1-or-later ++++++ _service ++++++ --- /var/tmp/diff_new_pack.G8WziL/_old 2022-11-27 12:52:51.207145774 +0100 +++ /var/tmp/diff_new_pack.G8WziL/_new 2022-11-27 12:52:51.211145797 +0100 @@ -1,7 +1,8 @@ <services> <service name="tar_scm" mode="disabled"> - <param name="version">0.4.8</param> - <param name="versionformat">0.4.8+git%cd.%h</param> + <param name="version">0.4.9</param> + <param name="versionformat">@PARENT_TAG@</param> + <param name="versionrewrite-pattern">v(\d+\.\d+\.\d+)</param> <param name="url">https://github.com/openSUSE/libeconf.git</param> <param name="scm">git</param> <param name="changesgenerate">enable</param> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.G8WziL/_old 2022-11-27 12:52:51.231145913 +0100 +++ /var/tmp/diff_new_pack.G8WziL/_new 2022-11-27 12:52:51.235145937 +0100 @@ -1,7 +1,7 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/openSUSE/libeconf.git</param> - <param name="changesrevision">7ff77043522a6d9a284118f2bcc59c3c697645f0</param> + <param name="changesrevision">3f363ba03817b337c75bb411a8f561a59751cb56</param> </service> </servicedata> (No newline at EOF) ++++++ libeconf-0.4.8+git20221114.7ff7704.tar.xz -> libeconf-0.4.9.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/CMakeLists.txt new/libeconf-0.4.9/CMakeLists.txt --- old/libeconf-0.4.8+git20221114.7ff7704/CMakeLists.txt 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/CMakeLists.txt 2022-11-23 13:45:05.000000000 +0100 @@ -3,7 +3,7 @@ # Ensure built-in policies from CMake are used, (e.g. improved policies for macOS) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) -project(libeconf VERSION 0.4.8 +project(libeconf VERSION 0.4.9 DESCRIPTION "Enhanced config file parser, which merges config files placed in several locations into one." LANGUAGES C ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/NEWS new/libeconf-0.4.9/NEWS --- old/libeconf-0.4.8+git20221114.7ff7704/NEWS 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/NEWS 2022-11-23 13:45:05.000000000 +0100 @@ -1,3 +1,16 @@ +Version 0.4.9 +* new API calls: + ** econf_readFileWithCallback + Has the same functionality like econf_readFile. The user + can additionally define a callback in order to check the parsed file. + ** econf_readDirsWithCallback + Has the same functionality like econf_readDirs. The user + can additionally define a callback in order e.g. to check all parsed file. + ** econf_readDirsHistoryWithCallback + Has the same functionality like econf_readDirsHistory. + The user can additionally define a callback in order e.g. to check + all parsed file. + Version 0.4.8 * Parsing files which are containing keys only. All delimiters are allowed now : "", " =", " ", "=". diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/doc/man/libeconf.3 new/libeconf-0.4.9/doc/man/libeconf.3 --- old/libeconf-0.4.8+git20221114.7ff7704/doc/man/libeconf.3 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/doc/man/libeconf.3 2022-11-23 13:45:05.000000000 +0100 @@ -103,7 +103,7 @@ .in +1c .ti -1c -.RI "enum \fBeconf_err\fP { \fBECONF_SUCCESS\fP = 0, \fBECONF_ERROR\fP = 1, \fBECONF_NOMEM\fP = 2, \fBECONF_NOFILE\fP = 3, \fBECONF_NOGROUP\fP = 4, \fBECONF_NOKEY\fP = 5, \fBECONF_EMPTYKEY\fP = 6, \fBECONF_WRITEERROR\fP = 7, \fBECONF_PARSE_ERROR\fP = 8, \fBECONF_MISSING_BRACKET\fP = 9, \fBECONF_MISSING_DELIMITER\fP = 10, \fBECONF_EMPTY_SECTION_NAME\fP = 11, \fBECONF_TEXT_AFTER_SECTION\fP = 12, \fBECONF_FILE_LIST_IS_NULL\fP = 13, \fBECONF_WRONG_BOOLEAN_VALUE\fP = 14, \fBECONF_KEY_HAS_NULL_VALUE\fP = 15, \fBECONF_WRONG_OWNER\fP = 16, \fBECONF_WRONG_GROUP\fP = 17, \fBECONF_WRONG_FILE_PERMISSION\fP = 18, \fBECONF_WRONG_DIR_PERMISSION\fP = 19, \fBECONF_ERROR_FILE_IS_SYM_LINK\fP = 20 }" +.RI "enum \fBeconf_err\fP { \fBECONF_SUCCESS\fP = 0, \fBECONF_ERROR\fP = 1, \fBECONF_NOMEM\fP = 2, \fBECONF_NOFILE\fP = 3, \fBECONF_NOGROUP\fP = 4, \fBECONF_NOKEY\fP = 5, \fBECONF_EMPTYKEY\fP = 6, \fBECONF_WRITEERROR\fP = 7, \fBECONF_PARSE_ERROR\fP = 8, \fBECONF_MISSING_BRACKET\fP = 9, \fBECONF_MISSING_DELIMITER\fP = 10, \fBECONF_EMPTY_SECTION_NAME\fP = 11, \fBECONF_TEXT_AFTER_SECTION\fP = 12, \fBECONF_FILE_LIST_IS_NULL\fP = 13, \fBECONF_WRONG_BOOLEAN_VALUE\fP = 14, \fBECONF_KEY_HAS_NULL_VALUE\fP = 15, \fBECONF_WRONG_OWNER\fP = 16, \fBECONF_WRONG_GROUP\fP = 17, \fBECONF_WRONG_FILE_PERMISSION\fP = 18, \fBECONF_WRONG_DIR_PERMISSION\fP = 19, \fBECONF_ERROR_FILE_IS_SYM_LINK\fP = 20, \fBECONF_PARSING_CALLBACK_FAILED\fP = 21 }" .br .RI "libeconf error codes " .in -1c @@ -115,6 +115,10 @@ .br .RI "Process the file of the given file_name and save its contents into key_file object\&. " .ti -1c +.RI "\fBeconf_err\fP \fBeconf_readFileWithCallback\fP (\fBeconf_file\fP **result, const char *file_name, const char *delim, const char *comment, bool (*callback)(const char *filename))" +.br +.RI "Has the same functionality like \fBeconf_readFile\fP. The user can additionally define a callback in order to check the parsed file\&. " +.ti -1c .RI "\fBeconf_err\fP \fBeconf_mergeFiles\fP (\fBeconf_file\fP **merged_file, \fBeconf_file\fP *usr_file, \fBeconf_file\fP *etc_file)" .br .RI "Merge the contents of two key_files objects\&. " @@ -123,10 +127,18 @@ .br .RI "Evaluating key/values of a given configuration by reading and merging all needed/available files in two different directories (normally in /usr/etc and /etc)\&. " .ti -1c +.RI "\fBeconf_err\fP \fBeconf_readDirsWithCallback\fP (\fBeconf_file\fP **key_file, const char *usr_conf_dir, const char *etc_conf_dir, const char *project_name, const char *config_suffix, const char *delim, const char *comment, bool (*callback)(const char *filename))" +.br +.RI "Has the same functionality like \fBeconf_readDirs\fP. The user can additionally define a callback in order e.g. to check all parsed file\&. " +.ti -1c .RI "\fBeconf_err\fP \fBeconf_readDirsHistory\fP (\fBeconf_file\fP ***key_files, size_t *size, const char *usr_conf_dir, const char *etc_conf_dir, const char *project_name, const char *config_suffix, const char *delim, const char *comment)" .br .RI "Evaluating key/values for every given configuration files in two different directories (normally in /usr/etc and /etc)\&. " .ti -1c +.RI "\fBeconf_err\fP \fBeconf_readDirsHistoryWithCallback\fP (\fBeconf_file\fP ***key_files, size_t *size, const char *usr_conf_dir, const char *etc_conf_dir, const char *project_name, const char *config_suffix, const char *delim, const char *comment, bool (*callback)(const char *filename))" +.br +.RI "Has the same functionality like \fBeconf_readDirsHistory\fP. The user can additionally define a callback in order e.g. to check all parsed file\&. " +.ti -1c .RI "\fBeconf_err\fP \fBeconf_newKeyFile\fP (\fBeconf_file\fP **result, char delimiter, char comment)" .br .RI "Create a new econf_file object\&. " @@ -413,13 +425,16 @@ File has wrong group\&. .TP \fB\fIECONF_WRONG_FILE_PERMISSION \fP\fP -File has wrong file permission\&. +File has wrong file permissions\&. .TP \fB\fIECONF_WRONG_DIR_PERMISSION \fP\fP -File has wrong dir permission\&. +File has wrong dir permissions\&. .TP \fB\fIECONF_ERROR_FILE_IS_SYM_LINK \fP\fP File is a sym link which is not permitted\&. +.TP +\fB\fIECONF_PARSING_CALLBACK_FAILED \fP\fP +User defined parsing callback has failed\&. .PP .SH "Function Documentation" @@ -462,35 +477,47 @@ .PP Default behaviour if entries have the same name in one file: The first hit will be returned\&. Further entries will be ignored\&. This can be changed by setting the environment variable ECONF_JOIN_SAME_ENTRIES\&. In that case entries with the same name will be joined to one single entry\&. -.SS "\fBeconf_err\fP econf_readDirsHistory (\fBeconf_file\fP *** key_files, size_t * size, const char * usr_conf_dir, const char * etc_conf_dir, const char * project_name, const char * config_suffix, const char * delim, const char * comment)" +.SS "\fBeconf_err\fP econf_readFileWithCallback (\fBeconf_file\fP ** result, const char * file_name, const char * delim, const char * comment, bool (*callback)(const char *filename))" .PP -Evaluating key/values for every given configuration files in two different directories (normally in /usr/etc and /etc)\&. Returns a list of read configuration files and their values\&. +Process the file of the given file_name and save its contents into key_file object\&. The user defined function will be called in order e.g. to check the correct file permissions\&. .PP \fBParameters:\fP .RS 4 -\fIkey_files\fP list of parsed file(s)\&. Each entry includes all key/value, path, comments,\&.\&.\&. information of the regarding file\&. -.br -\fIsize\fP Size of the evaluated key_files list\&. -.br -\fIusr_conf_dir\fP absolute path of the first directory (normally '/usr/etc') -.br -\fIetc_conf_dir\fP absolute path of the second directory (normally '/etc') +\fIresult\fP content of parsed file .br -\fIproject_name\fP basename of the configuration file +\fIfile_name\fP absolute path of parsed file .br -\fIconfig_suffix\fP suffix of the configuration file\&. Can also be NULL\&. +\fIdelim\fP delimiters of key/value e\&.g\&. '\\t =' .br -\fIdelim\fP delimiters of key/value e\&.g\&. '\\t =' +\fIcomment\fP array of characters which define the start of a comment .br -\fIcomment\fP array of characters which define the start of a comment +\fIcallback\fP function which will be called for the given filename\&. This user defined function has the pathname as paramter and returns true if this file can be parsed\&. If not, the parsing will be aborted and ECONF_PARSING_CALLBACK_FAILED will be returned\&. .RE .PP \fBReturns:\fP .RS 4 -econf_err ECONF_SUCCESS or error code +econf_err ECONF_SUCCESS or error code .RE .PP +Usage: +.PP +.nf +#include "libeconf.h" +bool checkFile(const char *filename) { + /* checking code which returns true or false */ + return true; +} + +econf_file *key_file = NULL; +econf_err error; + +error = econf_readFileWithCallback (&key_file, "/etc/test.conf", "=", "#", checkFile); +econf_free (key_file); +.fi +.PP +.PP +Default behaviour if entries have the same name in one file: The first hit will be returned\&. Further entries will be ignored\&. This can be changed by setting the environment variable ECONF_JOIN_SAME_ENTRIES\&. In that case entries with the same name will be joined to one single entry\&. .SS "\fBeconf_err\fP econf_mergeFiles (\fBeconf_file\fP ** merged_file, \fBeconf_file\fP * usr_file, \fBeconf_file\fP * etc_file)" @@ -541,7 +568,7 @@ .br \fIusr_conf_dir\fP absolute path of the first directory (normally '/usr/etc') .br -\fIetc_conf_dir\fP absolute path of the second directory (normally '/etc') +\fIetc_conf_dir\fP absolute path of the second directory (normally '/etc') .br \fIproject_name\fP basename of the configuration file .br @@ -576,6 +603,122 @@ .fi .PP + +.SS "\fBeconf_err\fP econf_readDirsWithCallback (\fBeconf_file\fP ** key_file, const char * usr_conf_dir, const char * etc_conf_dir, const char * project_name, const char * config_suffix, const char * delim, const char * comment, bool (*callback)(const char *filename))" + +.PP +Evaluating the content of a given configuration file by reading all needed/available files in two different directories (normally in /usr/etc and /etc)\&. For each parsed file the user defined function will be called in order e.g. to check the correct file permissions\&. +.PP +\fBParameters:\fP +.RS 4 +\fIkey_file\fP content of parsed file(s) +.br +\fIusr_conf_dir\fP absolute path of the first directory (normally '/usr/etc') +.br +\fIetc_conf_dir\fP absolute path of the second directory (normally '/etc') +.br +\fIproject_name\fP basename of the configuration file +.br +\fIconfig_suffix\fP suffix of the configuration file\&. Can also be NULL\&. +.br +\fIdelim\fP delimiters of key/value e\&.g\&. '\\t =' +.br +\fIcomment\fP array of characters which define the start of a comment +.br +\fIcallback\fP function which will be called for each file\&. This user defined function has the pathname as paramter and returns true if this file can be parsed\&. If not, the parsing of all files will be aborted and ECONF_PARSING_CALLBACK_FAILED will be returned\&. +.RE +.PP +\fBReturns:\fP +.RS 4 +econf_err ECONF_SUCCESS or error code +.RE +.PP +Example: Reading content of example\&.conf in /usr/etc and /etc directory\&. +.PP +.nf +#include "libeconf.h" + +bool checkFile(const char *filename) { + /* checking code which returns true or false */ + return true; +} + +econf_file *key_file = NULL; +econf_err error; + +error = econf_readDirsWithCallback (&key_file, + "/usr/etc", + "/etc", + "example", + "conf", + "=", "#", + checkFile); + +econf_free (key_file); +.fi +.PP + +.SS "\fBeconf_err\fP econf_readDirsHistory (\fBeconf_file\fP *** key_files, size_t * size, const char * usr_conf_dir, const char * etc_conf_dir, const char * project_name, const char * config_suffix, const char * delim, const char * comment)" + +.PP +Evaluating key/values for every given configuration files in two different directories (normally in /usr/etc and /etc)\&. Returns a list of read configuration files and their values\&. +.PP +\fBParameters:\fP +.RS 4 +\fIkey_files\fP list of parsed file(s)\&. Each entry includes all key/value, path, comments,\&.\&.\&. information of the regarding file\&. +.br +\fIsize\fP Size of the evaluated key_files list\&. +.br +\fIusr_conf_dir\fP absolute path of the first directory (normally '/usr/etc') +.br +\fIetc_conf_dir\fP absolute path of the second directory (normally '/etc') +.br +\fIproject_name\fP basename of the configuration file +.br +\fIconfig_suffix\fP suffix of the configuration file\&. Can also be NULL\&. +.br +\fIdelim\fP delimiters of key/value e\&.g\&. '\\t =' +.br +\fIcomment\fP array of characters which define the start of a comment +.RE +.PP +\fBReturns:\fP +.RS 4 +econf_err ECONF_SUCCESS or error code +.RE +.PP + +.SS "\fBeconf_err\fP econf_readDirsHistoryWithCallback (\fBeconf_file\fP *** key_files, size_t * size, const char * usr_conf_dir, const char * etc_conf_dir, const char * project_name, const char * config_suffix, const char * delim, const char * comment, bool (*callback)(const char *filename))" + +.PP +Evaluating key/values for every given configuration files in two different directories (normally in /usr/etc and /etc)\&. For each parsed file the user defined function will be called in order e.g. to check the correct file permissions\&. Returns a list of read configuration files and their values\&. +.PP +\fBParameters:\fP +.RS 4 +\fIkey_files\fP list of parsed file(s)\&. Each entry includes all key/value, path, comments,\&.\&.\&. information of the regarding file\&. +.br +\fIsize\fP Size of the evaluated key_files list\&. +.br +\fIusr_conf_dir\fP absolute path of the first directory (normally '/usr/etc') +.br +\fIetc_conf_dir\fP absolute path of the second directory (normally '/etc') +.br +\fIproject_name\fP basename of the configuration file +.br +\fIconfig_suffix\fP suffix of the configuration file\&. Can also be NULL\&. +.br +\fIdelim\fP delimiters of key/value e\&.g\&. '\\t =' +.br +\fIcomment\fP array of characters which define the start of a comment +.br +\fIcallback\fP function which will be called for each file\&. This user defined function has the pathname as paramter and returns true if this file can be parsed\&. If not, the parsing of all files will be aborted and ECONF_PARSING_CALLBACK_FAILED will be returned\&. +.RE +.PP +\fBReturns:\fP +.RS 4 +econf_err ECONF_SUCCESS or error code +.RE +.PP .SS "\fBeconf_err\fP econf_newKeyFile (\fBeconf_file\fP ** result, char delimiter, char comment)" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/include/libeconf.h new/libeconf-0.4.9/include/libeconf.h --- old/libeconf-0.4.8+git20221114.7ff7704/include/libeconf.h 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/include/libeconf.h 2022-11-23 13:45:05.000000000 +0100 @@ -30,6 +30,7 @@ #include <stdbool.h> #include <stdint.h> #include <stdlib.h> +#include <sys/types.h> #ifdef __cplusplus extern "C" { @@ -74,12 +75,14 @@ ECONF_WRONG_OWNER = 16, /** File has wrong group */ ECONF_WRONG_GROUP = 17, - /** File has wrong file permission */ + /** File has wrong file permissions */ ECONF_WRONG_FILE_PERMISSION = 18, /** File has wrong dir permission */ ECONF_WRONG_DIR_PERMISSION = 19, /** File is a sym link which is not permitted */ - ECONF_ERROR_FILE_IS_SYM_LINK = 20 + ECONF_ERROR_FILE_IS_SYM_LINK = 20, + /** User defined parsing callback has failed **/ + ECONF_PARSING_CALLBACK_FAILED = 21 }; typedef enum econf_err econf_err; @@ -150,6 +153,48 @@ extern econf_err econf_readFile(econf_file **result, const char *file_name, const char *delim, const char *comment); + +/** @brief Process the file of the given file_name and save its contents into key_file object. + * The user defined function will be called in order e.g. to check the correct file permissions. + * + * @param result content of parsed file + * @param file_name absolute path of parsed file + * @param delim delimiters of key/value e.g. "\t =". + * If delim contains space characters AND none space characters, + * multiline values are not parseable. + * @param comment array of characters which define the start of a comment + * @param callback function which will be called for the given filename. This user defined function has + * the pathname as paramter and returns true if this file can be parsed. If not, the + * parsing will be aborted and ECONF_PARSING_CALLBACK_FAILED will be returned. + * @return econf_err ECONF_SUCCESS or error code + * + * Usage: + * @code + * #include "libeconf.h" + * + * bool checkFile(const char *filename) { + * - checking code which returns true or false - + * return true; + * } + * + * econf_file *key_file = NULL; + * econf_err error; + * + * error = econf_readFileWithCallback (&key_file, "/etc/test.conf", "=", "#", checkFile); + * + * econf_free (key_file); + * @endcode + * + * Default behaviour if entries have the same name in one file: The + * first hit will be returned. Further entries will be ignored. + * This can be changed by setting the environment variable + * ECONF_JOIN_SAME_ENTRIES. In that case entries with the same name + * will be joined to one single entry. + */ +extern econf_err econf_readFileWithCallback(econf_file **result, const char *file_name, + const char *delim, const char *comment, + bool (*callback)(const char *filename)); + /** @brief Merge the contents of two key_files objects. Entries in etc_file will be * prefered. * Comment and delimiter tag will be taken from usr_file. This can be changed @@ -179,7 +224,7 @@ * */ extern econf_err econf_mergeFiles(econf_file **merged_file, - econf_file *usr_file, econf_file *etc_file); + econf_file *usr_file, econf_file *etc_file); /** @brief Evaluating key/values of a given configuration by reading and merging all * needed/available files in two different directories (normally in /usr/etc and /etc). @@ -214,12 +259,65 @@ * */ extern econf_err econf_readDirs(econf_file **key_file, - const char *usr_conf_dir, - const char *etc_conf_dir, - const char *project_name, - const char *config_suffix, - const char *delim, - const char *comment); + const char *usr_conf_dir, + const char *etc_conf_dir, + const char *project_name, + const char *config_suffix, + const char *delim, + const char *comment); + +/** @brief Evaluating key/values for every given configuration files in two different + * directories (normally in /usr/etc and /etc). For each parsed file the user defined function + * will be called in order e.g. to check the correct file permissions. + * + * @param key_files list of parsed file(s). + * Each entry includes all key/value, path, comments,... information of the regarding file. + * @param size Size of the evaluated key_files list. + * @param usr_conf_dir absolute path of the first directory (normally "/usr/etc") + * @param etc_conf_dir absolute path of the second directory (normally "/etc") + * @param project_name basename of the configuration file + * @param config_suffix suffix of the configuration file. Can also be NULL. + * @param delim delimiters of key/value e.g. "\t =" + * If delim contains space characters AND none space characters, + * multiline values are not parseable. + * @param comment array of characters which define the start of a comment + * @param callback function which will be called for each file. This user defined function has the + * pathname as paramter and returns true if this file can be parsed. If not, the parsing of + * all files will be aborted and ECONF_PARSING_CALLBACK_FAILED will be returned. + * @return econf_err ECONF_SUCCESS or error code + * + * Example: Reading content of example.conf in /usr/etc and /etc directory. + * @code + * #include "libeconf.h" + * + * bool checkFile(const char *filename) { + * - checking code which returns true or false - + * return true; + * } + * + * econf_file *key_file = NULL; + * econf_err error; + * + * error = econf_readDirsWithCallback (&key_file, + * "/usr/etc", + * "/etc", + * "example", + * "conf", + * "=", "#", + * checkFile); + * + * econf_free (key_file); + * @endcode + * + */ + extern econf_err econf_readDirsWithCallback(econf_file **key_file, + const char *usr_conf_dir, + const char *etc_conf_dir, + const char *project_name, + const char *config_suffix, + const char *delim, + const char *comment, + bool (*callback)(const char *filename)); /** @brief Evaluating key/values for every given configuration files in two different * directories (normally in /usr/etc and /etc). Returns a list of read configuration @@ -248,6 +346,38 @@ const char *delim, const char *comment); +/** @brief Evaluating key/values for every given configuration files in two different + * directories (normally in /usr/etc and /etc). For each parsed file the user defined function + * will be called in order e.g. to check the correct file permissions. + * Returns a list of read configuration files and their values. + * + * @param key_files list of parsed file(s). + * Each entry includes all key/value, path, comments,... information of the regarding file. + * @param size Size of the evaluated key_files list. + * @param usr_conf_dir absolute path of the first directory (normally "/usr/etc") + * @param etc_conf_dir absolute path of the second directory (normally "/etc") + * @param project_name basename of the configuration file + * @param config_suffix suffix of the configuration file. Can also be NULL. + * @param delim delimiters of key/value e.g. "\t =" + * If delim contains space characters AND none space characters, + * multiline values are not parseable. + * @param comment array of characters which define the start of a comment + * @param callback function which will be called for each file. This user defined function has the + * pathname as paramter and returns true if this file can be parsed. If not, the parsing of + * all files will be aborted and ECONF_PARSING_CALLBACK_FAILED will be returned. + * @return econf_err ECONF_SUCCESS or error code + * + */ +extern econf_err econf_readDirsHistoryWithCallback(econf_file ***key_files, + size_t *size, + const char *usr_conf_dir, + const char *etc_conf_dir, + const char *project_name, + const char *config_suffix, + const char *delim, + const char *comment, + bool (*callback)(const char *filename)); + /* The API/ABI of the following three functions (econf_newKeyFile, econf_newIniFile and econf_writeFile) are not stable and will change */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/lib/econf_error.c new/libeconf-0.4.9/lib/econf_error.c --- old/libeconf-0.4.8+git20221114.7ff7704/lib/econf_error.c 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/lib/econf_error.c 2022-11-23 13:45:05.000000000 +0100 @@ -48,9 +48,10 @@ "Given key has NULL value", /* ECONF_KEY_HAS_NULL_VALUE */ "File has wrong owner", /* ECONF_WRONG_OWNER */ "File has wrong group", /* ECONF_WRONG_GROUP */ - "File has wrong file permission", /* ECONF_WRONG_FILE_PERMISSION */ - "File has wrong dir permission", /* ECONF_WRONG_DIR_PERMISSION */ - "File is a sym link which is not permitted" /* ECONF_ERROR_FILE_IS_SYM_LINK */ + "File has wrong file permissions", /* ECONF_WRONG_FILE_PERMISSION */ + "File has wrong dir permissions", /* ECONF_WRONG_DIR_PERMISSION */ + "File is a sym link which is not permitted", /* ECONF_ERROR_FILE_IS_SYM_LINK */ + "User defined parsing callback has failed" /* ECONF_PARSING_CALLBACK_FAILED */ }; const char * diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/lib/libeconf.c new/libeconf-0.4.9/lib/libeconf.c --- old/libeconf-0.4.8+git20221114.7ff7704/lib/libeconf.c 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/lib/libeconf.c 2022-11-23 13:45:05.000000000 +0100 @@ -136,13 +136,14 @@ } // Process the file of the given file_name and save its contents into key_file -econf_err econf_readFile(econf_file **key_file, const char *file_name, - const char *delim, const char *comment) +econf_err econf_readFileWithCallback(econf_file **key_file, const char *file_name, + const char *delim, const char *comment, + bool (*callback)(const char *filename)) { econf_err t_err; struct stat sb; - if (key_file == NULL || file_name == NULL || delim == NULL) + if (key_file == NULL || file_name == NULL || delim == NULL || comment == NULL) return ECONF_ERROR; // Checking file permissions, uid, group,... @@ -166,6 +167,10 @@ if (!(sb_dir.st_mode&file_perms_dir)) return ECONF_WRONG_DIR_PERMISSION; } + + // calling user defined checks + if (callback != NULL && !(*callback)(file_name)) + return ECONF_PARSING_CALLBACK_FAILED; // Get absolute path if not provided char *absolute_path = get_absolute_path(file_name, &t_err); @@ -198,6 +203,12 @@ return ECONF_SUCCESS; } +econf_err econf_readFile(econf_file **key_file, const char *file_name, + const char *delim, const char *comment) +{ + return econf_readFileWithCallback(key_file, file_name, delim, comment, NULL); +} + // Merge the contents of two key files econf_err econf_mergeFiles(econf_file **merged_file, econf_file *usr_file, econf_file *etc_file) { @@ -238,14 +249,15 @@ } -econf_err econf_readDirsHistory(econf_file ***key_files, - size_t *size, - const char *dist_conf_dir, - const char *etc_conf_dir, - const char *project_name, - const char *config_suffix, - const char *delim, - const char *comment) +econf_err econf_readDirsHistoryWithCallback(econf_file ***key_files, + size_t *size, + const char *dist_conf_dir, + const char *etc_conf_dir, + const char *project_name, + const char *config_suffix, + const char *delim, + const char *comment, + bool (*callback)(const char *filename)) { const char *suffix, *default_dirs[3] = {NULL, NULL, NULL}; char *distfile, *etcfile, *cp; @@ -302,7 +314,7 @@ if (etcfile) { - error = econf_readFile(&key_file, etcfile, delim, comment); + error = econf_readFileWithCallback(&key_file, etcfile, delim, comment, callback); if (error && error != ECONF_NOFILE) return error; } @@ -316,7 +328,7 @@ and merge all *.d files. */ if (distfile) { - error = econf_readFile(&key_file, distfile, delim, comment); + error = econf_readFileWithCallback(&key_file, distfile, delim, comment, callback); if (error && error != ECONF_NOFILE) return error; } @@ -388,26 +400,41 @@ return ECONF_SUCCESS; } -econf_err econf_readDirs(econf_file **result, - const char *dist_conf_dir, - const char *etc_conf_dir, - const char *project_name, - const char *config_suffix, - const char *delim, - const char *comment) +econf_err econf_readDirsHistory(econf_file ***key_files, + size_t *size, + const char *dist_conf_dir, + const char *etc_conf_dir, + const char *project_name, + const char *config_suffix, + const char *delim, + const char *comment) { + return econf_readDirsHistoryWithCallback(key_files, size, dist_conf_dir, + etc_conf_dir, project_name, + config_suffix, delim, comment, NULL); +} + +econf_err econf_readDirsWithCallback(econf_file **result, + const char *dist_conf_dir, + const char *etc_conf_dir, + const char *project_name, + const char *config_suffix, + const char *delim, + const char *comment, + bool (*callback)(const char *filename)) { size_t size = 0; econf_file **key_files; econf_err error; - error = econf_readDirsHistory(&key_files, - &size, - dist_conf_dir, - etc_conf_dir, - project_name, - config_suffix, - delim, - comment); + error = econf_readDirsHistoryWithCallback(&key_files, + &size, + dist_conf_dir, + etc_conf_dir, + project_name, + config_suffix, + delim, + comment, + callback); if (error != ECONF_SUCCESS) return error; @@ -418,6 +445,19 @@ return error; } +econf_err econf_readDirs(econf_file **result, + const char *dist_conf_dir, + const char *etc_conf_dir, + const char *project_name, + const char *config_suffix, + const char *delim, + const char *comment) +{ + return econf_readDirsWithCallback(result, dist_conf_dir, etc_conf_dir, + project_name, config_suffix, delim, + comment, NULL); +} + // Write content of a econf_file struct to specified location econf_err econf_writeFile(econf_file *key_file, const char *save_to_dir, const char *file_name) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/lib/libeconf.map new/libeconf-0.4.9/lib/libeconf.map --- old/libeconf-0.4.8+git20221114.7ff7704/lib/libeconf.map 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/lib/libeconf.map 2022-11-23 13:45:05.000000000 +0100 @@ -62,4 +62,7 @@ econf_delimiter_tag; econf_set_comment_tag; econf_set_delimiter_tag; + econf_readFileWithCallback; + econf_readDirsWithCallback; + econf_readDirsHistoryWithCallback; } LIBECONF_0.3; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/meson.build new/libeconf-0.4.9/meson.build --- old/libeconf-0.4.8+git20221114.7ff7704/meson.build 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/meson.build 2022-11-23 13:45:05.000000000 +0100 @@ -7,7 +7,7 @@ 'b_pie=true', 'warning_level=3',], license : 'MIT', - version : '0.4.8', + version : '0.4.9', ) cc = meson.get_compiler('c') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/tests/CMakeLists.txt new/libeconf-0.4.9/tests/CMakeLists.txt --- old/libeconf-0.4.8+git20221114.7ff7704/tests/CMakeLists.txt 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/tests/CMakeLists.txt 2022-11-23 13:45:05.000000000 +0100 @@ -36,6 +36,7 @@ tst-string tst-string-append tst-security + tst-checkfiles tst-delimiter-comment tst-extvalue tst-comments diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/tests/meson.build new/libeconf-0.4.9/tests/meson.build --- old/libeconf-0.4.8+git20221114.7ff7704/tests/meson.build 2022-11-14 13:57:36.000000000 +0100 +++ new/libeconf-0.4.9/tests/meson.build 2022-11-23 13:45:05.000000000 +0100 @@ -45,6 +45,8 @@ test('tst-string-append', tst_string_append_exe) tst_security_exe = executable('tst-security', 'tst-security.c', c_args: test_args, dependencies : libeconf_dep) test('tst-security', tst_security_exe) +tst_checkfiles_exe = executable('tst-checkfiles', 'tst-checkfiles.c', c_args: test_args, dependencies : libeconf_dep) +test('tst-checkfiles', tst_checkfiles_exe) tst_delimiter_comment_exe = executable('tst-delimiter-comment', 'tst-delimiter-comment.c', c_args: test_args, dependencies : libeconf_dep) test('tst-delimiter-comment', tst_delimiter_comment_exe) tst_extvalue_exe = executable('tst-extvalue', 'tst-extvalue.c', c_args: test_args, dependencies : libeconf_dep) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libeconf-0.4.8+git20221114.7ff7704/tests/tst-checkfiles.c new/libeconf-0.4.9/tests/tst-checkfiles.c --- old/libeconf-0.4.8+git20221114.7ff7704/tests/tst-checkfiles.c 1970-01-01 01:00:00.000000000 +0100 +++ new/libeconf-0.4.9/tests/tst-checkfiles.c 2022-11-23 13:45:05.000000000 +0100 @@ -0,0 +1,50 @@ +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include "libeconf.h" +bool checkLink(const char *filename); + +/* Test case: + * Using user defined callback for checking files which will be parsed. + */ + + bool checkLink(const char *filename) { + struct stat sb; + + if (lstat(filename, &sb) == -1 || (sb.st_mode&S_IFMT) == S_IFLNK) + return false; + + return true; + } + +int +main(void) +{ + econf_file *key_file = NULL; + econf_err error; + + + /* checking not allowed links*/ + if (symlink(TESTSDIR"tst-arguments-string/etc/arguments.conf", TESTSDIR"tst-arguments-string/etc/link.conf") == -1) + { + fprintf (stderr, "ERROR: cannot create sym link: %s\n", TESTSDIR"tst-arguments-string/etc/link.conf"); + return 1; + } + + error = econf_readFileWithCallback (&key_file, TESTSDIR"tst-arguments-string/etc/link.conf", "=", "#", checkLink); + remove(TESTSDIR"tst-arguments-string/etc/link.conf"); + if (error != ECONF_PARSING_CALLBACK_FAILED) + { + fprintf (stderr, "ERROR: expecting: %s\n returned: %s\n", + econf_errString(ECONF_PARSING_CALLBACK_FAILED), + econf_errString(error)); + return 1; + } + + return 0; +}