Coder Social home page Coder Social logo

libconfuse / libconfuse Goto Github PK

View Code? Open in Web Editor NEW
467.0 24.0 110.0 902 KB

Small configuration file parser library for C.

Home Page: https://www.nongnu.org/confuse/manual/

License: ISC License

Shell 0.74% C 90.72% Lex 4.34% Makefile 2.75% Batchfile 0.30% PowerShell 0.28% M4 0.86%
config configuration-files

libconfuse's Introduction

libConfuse

Badge GitHub Status Coverity Status

Introduction

libConfuse is a configuration file parser library written in C. It supports sections and (lists of) values, as well as other features such as single/double quoted strings, environment variable expansion, functions and nested include statements. Values can be strings, integers, floats, booleans, and sections.

The goal is not to be the configuration file parser library with a gazillion of features. Instead, it aims to be easy to use and quick to integrate with your code.

Please ensure you download a versioned archive from: https://github.com/libconfuse/libconfuse/releases/

Documentation

Examples

Build & Install

libConfuse employs the GNU configure and build system. To list available build options, start by unpacking the tarball:

tar xf confuse-3.2.2.tar.xz
cd confuse-3.2.2/
./configure --help

For most users the following commands configures, builds and installs the library to /usr/local/:

./configure && make -j9
sudo make install
sudo ldconfig

See the INSTALL file for the full installation instructions.

When checking out the code from GitHub, use ./autogen.sh to generate a configure script. This means you also need the following tools:

  • autoconf
  • automake
  • libtool
  • gettext
  • autopoint
  • flex

To build the documentation you also need the following tools:

  • doxygen
  • xmlto

This is an optional step, so you must build it explicitly from its directory:

cd doc/
make documentation

Origin & References

libConfuse was created by Martin Hedenfalk and released as open source software under the terms of the ISC license. It was previously called libcfg, but the name was changed to not confuse with other similar libraries. It is currently developed and maintained at GitHub. Please use the issue tracker to report bugs and feature requests.

libconfuse's People

Contributors

binki avatar carenas avatar cgzones avatar cr1901 avatar davidegrayson avatar fhunleth avatar flix- avatar furmur avatar gikoskos avatar heitbaum avatar jonasj76 avatar jubnzv avatar jwilk avatar lanoxx avatar lonerdan avatar lucaceresoli avatar manish364824 avatar martinh avatar musvaage avatar myd7349 avatar norwayfun avatar peda-r avatar thomasadam avatar tibabit avatar troglobit avatar uglyoldbob avatar ukleinek avatar unmanned-player avatar vapier avatar zhabinski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libconfuse's Issues

Syntax, and small confusion

Hey.

I just read thru the project, and found that in ftp.conf, this is used:

password = ${ANONPASS:-secret}

How is that interpreted? I do not see any ANONPASS variable.

The other thing I wanted to ask was: I was/am looking for a config parser that would support a syntax like this one here - but with a few changes:

var = "key"
SomeOption: $var

Do you think that one can modify libconfuse to archieve this syntax?

Kind regards, Ingwie

AM_GNU_GETTEXT error

error: possibly undefined macro: AM_GNU_GETTEXT
error: possibly undefined macro: AM_GNU_GETTEXT_VERSION

I get these errors on ubuntu 16.04 LTS

How can I fix this?

Best regards
Pieter

Are nested sections supported?

Hello!

I'm trying to use nested sections in libconfuse, is tihs supported? Here's the configuration I'd like to use:

groups {
    name = 'Esmé'
    group 1 {
        number = 1
    }
}

Here's the C program I've written to represent that:

#include <confuse.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    cfg_opt_t opts[] = {
        CFG_SEC("group", CFGF_NONE, CFGF_TITLE | CFGF_MULTI),
        CFG_INT("number", 0, CFGF_NONE),
        CFG_END()
    };

    cfg_opt_t groups_opts[] = {
        CFG_SEC("groups", opts, CFGF_NONE),
        CFG_STR("name", "Esmé", CFGF_NONE),
        CFG_END()
    };

    cfg_t *cfg;

    cfg = cfg_init(groups_opts, CFGF_NONE);
    if (cfg_parse(cfg, "example.conf") == CFG_PARSE_ERROR)
        return 1;

    cfg_free(cfg);
    return 0;
}

When compiling the program above, and running it without a configuration file, my test program segfaults. With a configuration file, it complains about "name" being an unknown option.

Am I being a numpty, or is this not supported?

TIA!

funopen() unavailable in gcc-mingw-w64-x86-64

In upgrading to libconfuse 3.1, I am now receiving the following error on mingw builds for Windows:

libconfuse.a(libconfuse_la-fmemopen.o): In function `fmemopen':
fmemopen.c:110: undefined reference to `funopen'

This can be reproduced on Debian/Ubuntu by installing the mingw crosscompiler:

sudo apt install gcc-mingw-w64-x86-64
cd confuse
CC=x86_64-w64-mingw32-gcc ./configure --enable-shared=no --disable-examples
make

Then try linking libconfuse.a to a trivial app. Since I never build the libconfuse examples in my Windows builds, I hadn't realized that they didn't compile with mingw, but in theory, they could show the issue too. If nothing else, you can see the warning the funopen isn't defined when compiling fmemopen.c.

I'm not completely sure how best to work around this issue. In the past when I've run into uses of fmemopen, it has been pretty easy to remove them, but I don't think that's the case here. However, I also don't know how one would implement fmemopen without funopen. Hence I'm posting here to see if there are any other ideas.

How to compile for ARM64

Hi, first of all thanks for that library.

I'm would like to use this library into iOS project. How I can compile the library for ARM64?

Thanks!

There are compile errors in strdup implementation

../confuse.c:118:15: error: use of undeclared identifier 'str'
siz = strlen(str) + 1;
^
../confuse.c:123:15: error: use of undeclared identifier 'str'
memcpy(copy, str, siz);

The fix could be either change the parameter to 'str' or change usage of 'str' in the function body to 's'.

JSON support

Hey.

Is it possible that this library can parse/read or write in/to JSON format?

Kind regards,
Ingwie

Support recursive sections

Is it possible to support recursive sections like:

cfg_opt_t group_opts[] =
{
    CFG_SEC("item", item_opts, CFGF_MULTI|CFGF_TITLE|CFGF_NO_TITLE_DUPES),
    CFG_SEC("group", group_opts, CFGF_MULTI),
    CFG_END()
};

Libtool version-info is not updated correctly

The recent 3.2.2 release forgot to bump the revision field in the libtool version-info as described by update rule 3 in
https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html

These update rules also happens to be restated in HACKING.md, but that file has a strange comment about "Do we need to bump the ABI version?" in the release procedure. That is the wrong thing to say. It would be better to say "Bump the libtool version info according to the Libtool version-info update rules", and not have any ifs and buts about it. It should always be done, with a revision bump according to rule 3 as a minimum.

(Sure, it is possible with releases where you have not made and changes to the library source code, but those will be rare exceptions. Hopefully...)

Cheers,
Peter

confuse.mo no such file or directory - I am following the instructions for building - to no avail

I follow the instructions as per INSTALL document and do the following.
I have Win 7 and git bash console.```

invoke the git bash console.

cd c:/python36/confuse-3.2
./configure # goes through all the checking - takes about one minute creates various files.
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating examples/Makefile
config.status: creating po/Makefile.in
config.status: creating m4/Makefile
config.status: creating tests/Makefile
config.status: creating doc/Makefile
config.status: creating doc/Doxyfile
config.status: creating libconfuse.pc
config.status: creating libconfuse.spec
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
sh: __git_ps1: command not found`

The last line sh: __git_ps1:command not found # I don't understand how this may assist me.

$ make
C:/mingw64/bin/make all-recursive
make[1]: Entering directory 'C:/python36/confuse-3.2'
Making all in m4
make[2]: Entering directory 'C:/python36/confuse-3.2/m4'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory 'C:/python36/confuse-3.2/m4'
Making all in po
make[2]: Entering directory 'C:/python36/confuse-3.2/po'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory 'C:/python36/confuse-3.2/po'
Making all in src
make[2]: Entering directory 'C:/python36/confuse-3.2/src'
C:/Program Files/Git/usr/bin/sh.exe ../libtool --tag=CC --mode=compile gcc -DLOCALEDIR="/usr/local/share/locale" -DHAVE_CONFIG_H -I. -I.. -D_GNU_SOURCE -DBUILDING_DLL -g -O2 -MT libconfuse_la-confuse.lo -MD -MP -MF .deps/libconfuse_la-confuse.Tpo -c -o libconfuse_la-confuse.lo test -f 'confuse.c' || echo './'confuse.c
/usr/bin/sh: C:/Program: No such file or directory
make[2]: *** [makefile:479: libconfuse_la-confuse.lo] Error 127
make[2]: Leaving directory 'C:/python36/confuse-3.2/src'
make[1]: *** [makefile:521: all-recursive] Error 1
make[1]: Leaving directory 'C:/python36/confuse-3.2'
make: *** [makefile:407: all] Error 2
sh: __git_ps1: command not found

Why do I get all these errors, "no such file or directory" and sh:__git_ps1 command not found when I got the *.zip package confuse-3.2.zip without modifying it?

Thank you in advance,
Anthony of Sydney

Support 64-bit integer and/or unsigned 32-bit integer configuration types

It seems that on 32-bit *nix OS, the CFG_INT config type is signed 32-bit. I've got a config type that needs to be 64-bit. I've got another config type that needs to be unsigned 32-bit. I had been using CFG_INT fine on my 64-bit OS (CFG_INT type is evidently signed 64-bit in that case), but it didn't work when I tried to cross-compile for a 32-bit ARM embedded Linux platform.

For the unsigned 32-bit case, I guess I can do a custom validator and some typecasting to make it handle unsigned 32-bit. It would be nice for libconfuse to provide for unsigned 32-bit.

For the 64-bit values, it would be great if libconfuse would add support for 64-bit integer config types.

Section containing multiple CFG_STR_LIST()s with the same key?

Hi all,

I'm trying to use a section which contains multiple string lists with the same key. Hopefully the following will illustrate how I'm trying to achieve that:

cfg_opt_t    bind_opts[] = {
    CFG_STR_LIST("key", "{CM-Return, terminal}", CFGF_NONE),
    CFG_STR_LIST("key", "{CM-Delete, lock}", CFGF_NONE),
    CFG_STR_LIST("key", "{M-question, exec}", CFGF_NONE),
    CFG_STR_LIST("key", "{M-period, ssh}", CFGF_NONE),
    CFG_STR_LIST("key", "{M-Return, hide}", CFGF_NONE),
        CFG_END()
};

cfg_opt_t    all_cfg_opts[] = {
    CFG_SEC("bindings", bind_opts, CFGF_MULTI),
        CFG_END()
};

Certainly, if I then do something like this from within my program:

cfg_t    *sec = cfg_getsec(cfg, "bindings");
cfg_print(sec, stdout);

I see:

bindings {
  key = {"CM-Return", "terminal"}
  key = {"CM-Delete", "lock"}
  key = {"M-question", "exec"}
  key = {"M-period", "ssh"}
  key = {"M-Return", "hide"}
};

Which suggests libconfuse is happy, yet when I do something like this:

fprintf(stderr, "size of bindings is: %d\n", cfg_size(bind_sec, "bindings"));

It prints the value of 1 when I expect to see 5.

Am I doing something wrong, or does libconfuse simply not support this type of structure, and is flattening down all of the key = lines into one?

Any help, greatly appreciated!

Memory leak?

I'm working with a small test program, very similar to the example given in tutorial step 4. When the example is run under valgrind, it reports a block that is "definitely lost", and another that is "still reachable". I'm using libconfuse from the CentOS 6.5 repositories, version 2.7. I installed the debuginfo packages, so valgrind gives me some symbolic info, but the line numbers are mangled, possibly due to compiler optimizations.

With some experimentation, I determined that the first loss record is the section name. My config file contains:

filter temp {
name = "test filter"
complex = true
real_coeffs = {1, 2, 3, 4}
imag_coeffs = {-1, -2, -3, -4}
}

Valgrind reports five bytes lost in a strdup call under cfg_parse_internal, and loses five bytes. If I edit the first line of the config file to read "filter temp1 {", the number of bytes lost goes up to six.

The second loss record is in cfg_parse_fp, a call to cfg_yy_switch_to_buffer.

I have called cfg_free on both the outer cfg_t (returned by cfg_parse) and the inner one (returned by cfg_getsec).

Please let me know if there's more I can do to help diagnose this.

Add thread-safe error handler for C++ to library

Good day. I'm using libconfuse in C++ project. One issue that make me sad is that I cannot set custom thread-safe error handler which has access to my class/struct members.

My proposal: make possibility to set custom error handler with modern C++ std::functions.

"#ifdef __cplusplus" can help you?

Push tags

The git repo on Savannah has some git tags. They haven't been pushed to this repo.

Stop using assert() for checking return value from OS functions.

I've noticed that libConfuse relies heavily on assert(). Personally I think I'd like to see more of a conservative approach to its use. I.e., only use it for internal DBC and not for, e.g. checking return value from malloc().

Since libConfuse is a library, I believe we should only assert on things that are clear internal "contract violations", e.g. invalid input to internal functions, or internal fault conditions that simply should not happen. Running out of memory is not one such internal condition in my opinion. Mostly because asserts can be disabled, by defining NDEBUG. Using assert() for failed malloc() is, put simply, laziness ... for a regular desktop system its possibly useful, but for embedded (headless) systems such behavior is rarely desired.

However, I'm a bit hesitant to simply roll out a massive change without posting my proposal here first. So here it is:

  1. On invalid input to a public API the API should return error. E.g, NULL or non-zero with errno=EINVAL
  2. On internal problems, e.g. allocating RAM, the API should return NULL or non-zero with errno set to represent the error condition, e.g. ENOMEM
  3. Only on internal consistency and sanity checks should the library assert() and cause an exit/abort for the calling program -- and this should probably be possible to enable/disable so release binaries set NDEBUG. Maybe even use --enable-maintainer-mode, or the reverse of that perhaps: --disable-asserts to the configure script for this.

Comments?

Cross compilation

Hi guys I would like to use your library on mips target. I have cross compliator here. But you use some auto generation script. Is somebody who can explain what should I change to cross compile the library and then can link it to my project?

out of bound read in trim_whitespace

libconfuse_poc.txt

When open a crafted file, The program could tigger out of bound read


[----------------------------------registers-----------------------------------]
RAX: 0x7ffff7fc06d0 --> 0x7ffff761c14c --> 0x2000200020002 
RBX: 0x611720 (" this is a comment(\220\216\363rbose=true")
RCX: 0x1d 
RDX: 0x23 ('#')
RSI: 0x3 
RDI: 0x60ce80 --> 0x0 
RBP: 0x60ce80 --> 0x0 
RSP: 0x7fffffffdce0 --> 0x0 
RIP: 0x4054b7 (<qend+71>:	movsx  rbp,BYTE PTR [rbx+r13*1])
R8 : 0x1 
R9 : 0x3 
R10: 0x7fffffffdaa0 --> 0x0 
R11: 0x7ffff7a41110 (<__ctype_b_loc>:	mov    rax,QWORD PTR [rip+0x391ce9]        # 0x7ffff7dd2e00)
R12: 0x20 (' ')
R13: 0x20 (' ')
R14: 0x611700 --> 0x60d6a0 --> 0x60d460 --> 0xfbad2498 
R15: 0x60d6a0 --> 0x60d460 --> 0xfbad2498
EFLAGS: 0x203 (CARRY parity adjust zero sign trap INTERRUPT direction overflow)
[-------------------------------------code-------------------------------------]
   0x4054a9 <qend+57>:	jbe    0x405535 <qend+197>
   0x4054af <qend+63>:	mov    r13d,r12d
   0x4054b2 <qend+66>:	call   0x4012f0 <__ctype_b_loc@plt>
=> 0x4054b7 <qend+71>:	movsx  rbp,BYTE PTR [rbx+r13*1]
   0x4054bc <qend+76>:	mov    rsi,QWORD PTR [rax]
   0x4054bf <qend+79>:	jmp    0x4054ce <qend+94>
   0x4054c1 <qend+81>:	nop    DWORD PTR [rax+0x0]
   0x4054c8 <qend+88>:	cmp    r13d,0x1
[------------------------------------stack-------------------------------------]
0000| 0x7fffffffdce0 --> 0x0 
0008| 0x7fffffffdce8 --> 0x47 ('G')
0016| 0x7fffffffdcf0 --> 0x60ce80 --> 0x0 
0024| 0x7fffffffdcf8 --> 0x60d712 --> 0x72657672657300 ('')
0032| 0x7fffffffdd00 --> 0x60d711 --> 0x726576726573000a ('\n')
0040| 0x7fffffffdd08 --> 0x405fef (<cfg_yylex+447>:	add    rsp,0x38)
0048| 0x7fffffffdd10 --> 0x4010 
0056| 0x7fffffffdd18 --> 0x60d460 --> 0xfbad2498 
[------------------------------------------------------------------------------]
Legend: code, data, rodata, value

Breakpoint 1, 0x00000000004054b7 in trim_whitespace (len=0x20, str=0x611720 " this is a comment(\220\216\363rbose=true") at lexer.l:397
397		if ((str[len] == 0 || isspace(str[len])) && isspace(str[len - 1]))
gdb-peda$ bt
#0  0x00000000004054b7 in trim_whitespace (len=0x20, str=0x611720 " this is a comment(\220\216\363rbose=true") at lexer.l:397
#1  qend (cfg=cfg@entry=0x60ce80, ret=0x8, trim=0x1) at lexer.l:420
#2  0x0000000000405fef in cfg_yylex (cfg=cfg@entry=0x60ce80) at lexer.l:125
#3  0x0000000000403990 in cfg_parse_internal (cfg=cfg@entry=0x60ce80, level=level@entry=0x0, force_state=force_state@entry=0xffffffff, force_opt=force_opt@entry=0x0) at confuse.c:1060
#4  0x00000000004041b9 in cfg_parse_fp (cfg=0x60ce80, fp=<optimized out>) at confuse.c:1442
#5  0x0000000000404286 in cfg_parse (cfg=cfg@entry=0x60ce80, filename=<optimized out>) at confuse.c:1535
#6  0x00000000004014ce in main (argc=argc@entry=0x2, argv=argv@entry=0x7fffffffe318) at simple.c:46
#7  0x00007ffff7a32f45 in __libc_start_main (main=0x4013b0 <main>, argc=0x2, argv=0x7fffffffe318, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe308) at libc-start.c:287
#8  0x0000000000401607 in _start ()
gdb-peda$ x/4xg $rbx-0x10
0x611710:	0x0000000000000000	0x0000000000000031
0x611720:	0x7369207369687420	0x656d6d6f63206120
gdb-peda$ p/x $r13
$3 = 0x20
gdb-peda$ 

As you can see $rbx point a 0x30 size malloc chunk (which size for user is 0x20), and $r13 is 0x20

then

0x4054b7 <qend+71>:	movsx  rbp,BYTE PTR [rbx+r13*1]

could access **1 byte out of ** the vaild memory.

the poc file

https://gitee.com/hac425/blog_data/blob/master/fuzz_pocs/libconfuse_poc

Bug with closing braces in CFG_INT_LIST

Hello.
I'm using default value for integer list
CFG_INT_LIST("freqFCLK0123", "{50,200,0,0}", CFGF_NONE),
I get an error "Missed one or more closing braces" during default value parsing.
Adding two braces }} in the end helps.
changing level from 1 to 0 in confuse.c:
ret = cfg_parse_internal(cfg, 0, xstate, &cfg->opts[i]);
also helps.
Is the problem with level?

config starting with a line of only hashes causes segfault

As discussed here
since libconfuse v3.1 a config file for i3status starting with a line of hashes only causes libconfuse to segfault:

(gdb) run
Starting program: /usr/bin/i3status 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007f6c787485da in ?? () from /usr/lib/libconfuse.so.1
(gdb) bt
#0  0x00007f6c787485da in ?? () from /usr/lib/libconfuse.so.1
#1  0x00007f6c787493fb in cfg_yylex () from /usr/lib/libconfuse.so.1
#2  0x00007f6c78746ac8 in ?? () from /usr/lib/libconfuse.so.1
#3  0x00007f6c78747359 in cfg_parse_fp () from /usr/lib/libconfuse.so.1
#4  0x00007f6c78747428 in cfg_parse () from /usr/lib/libconfuse.so.1
#5  0x00000000004057d9 in main ()
(gdb)

Copyright tag not recogonized by rpmbuild

What I've encountered:

  1. on CentOS 6.5 & CentOS 7
  2. yum install rpm-build
  3. got rpm-build.x86_64 0:4.11.3-17.el7
  4. wget https://github.com/martinh/libconfuse/releases/download/v3.0/confuse-3.0.tar.gz
  5. rpmbuild -tb confuse-3.0.tar.gz
  6. got error error: line 32: Unknown tag: Copyright: ISC

Please consider to change

Copyright: ISC
at line 32 ./libconfuse.spec to
License: ISC
since Copyright tag has been deprecated for a long time

Add feature to deprecate config options

We use libconfuse in tilda and often have the problem that we want to deprecate config options but this leads to problems:

When the config option is still present in the config file (e.g. for upgrading users) then libconfuse throws an error and we need to reset the config.

We are currently discussing if we replace libconfuse with another config library due to this, or if we are going to add a new feature to libconfuse. I would like to know if this project is still being actively maintained/developed and how likely it is that a patch will be accepted into libconfuse. If a patch would be accepted, then we might add a CFGF_DEPRECATED to the list of flags that causes libconfuse to ignore the config value and drop it when the config file is saved next. Possibly we could also split this into separate flags with a CFGF_DROP flag.

Please let us know what your plans with libconfuse are and if we can somehow help you.

Libtool version info has never been updated

src/Makefile.am specifies "-version-info 0:0:0" when libtool links the libconfuse library, and has been doing that since basically forever. This is wrong.

For reference, read about libtool versioning in the libtool manual:

https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html

However, please take particular note about this part if the version info is updated:

Never try to set the interface numbers so that they correspond to the release number of your package.

Getting "internal compiler error" when using CFG_FLOAT in a c++ program

Hi I am getting following error when using CFG_FLOAT in a c++ program

/home/vikash/projects/libconfuse-cpp/libconfuse/include/confuse.h:430:83: internal compiler error: in reshape_init_class, at cp/decl.c:5653
{name,CFGT_FLOAT,0,0,flags,0,{0,def,cfg_false,0,0},0,{.fpnumber=svalue},cb,0,0,0}

I am able to use other macros with no problem at all.

I am using 6.3.0 on Ubuntu 17.04 and 64 bit machine architecture

Convert to Linux coding style

I'm considering moving the libConfuse code base to Linux coding style (when all PRs have been audited and merged). Then we could have a simple indent script to fixup submissions with.

Comments?

API/ABI changes analysis report

Hi,

I've created the API/ABI changes analysis report for the libconfuse library and published it here: https://abi-laboratory.pro/tracker/timeline/libconfuse/

You can verify added, removed and changed API/ABI symbols with the help of this report. Hope it will be helpful for users and maintainers of the library. The report is updated regularly.

Json-format mirror report is available on Github: https://github.com/lvc/abi-reports/blob/master/report/libconfuse.json

Thank you.

libconfuse-1
libconfuse-2

Automatic handling of deprecated values

Currently libconfuse has the option to deprecate config options and also to automatically drop deprecated config options. For deprecated config options that are not flagged to be dropped a warning is printed. For use cases where the user manually edits a config file this is fine, but for use cases where we want to perform automatic migration of deprecated values this is not enough.

I think it would be nice if we had the ability to add a deprecation callback handler in libconfuse which can notify the application of deprecated values in the configuration file. This would give the application a change to migrate these values automatically. The way I imagine this would be as following:

  1. We add the CFGF_DEPRECATED to some existing but now obsolete config option, like this:

    CFG_BOOL("super_cow_power", FALSE, CFGF_DEPRECATED),
    CFG_BOOL("unicorn_power", TRUE, CFGF_NONE) /* use this instead */
    
  2. We define a deprecation handler callback function type that can be implemented by the application. It gets passed the config pointer, the option_name of the deprecated option and an optional user_data pointer as arguments:

    typedef (int) (*DeprecationHandlerFunc) (cfg_t *config, 
                                             const char *option_name,
                                             void *user_data);
    
  3. The deprecationFunc gets called for each deprecated value that remains in the config file. The app can handle the deprecated value and migrate it to some other option. By returning TRUE or FALSE from the deprecation function the app can indicate if the value was correctly migrated. If TRUE is returned no warning should be logged for the deprecated option, otherwise a warning will be logged (current behavior).

    int config_deprecation_handler (const char *option_name) {
        // load the config value from the config object and handle it
        if (migration_successful) {
           return TRUE; // migration successful
        } else {
            return FALSE;
        }
    }
    
  4. If additionally the flag CFGF_DROP is specified and the deprecation handler returned TRUE, then the option is automatically removed.

  5. When we call cfg_parse, we pass additional parameters with the deprecation_handler function and the user_data as callback:

    int result = cfg_parse (tc, config_file, deprecation_handler,
                            deprecation_user_data);
    

Please let me know what I think. Maybe I missed something, or if if this is already possible in libconfuse then it would be nice to know how.

Embedding a scripting languae

Hey there!

I am looking for a way to run a scripting language from inside libConfuse when it runs. This is ment to be used for a build system I am working on.

Is there a way to do something like that? I have seen the support for "macros" in other libraries, that looked like this:

.macro {
    some
    long and unquoted
    text that goes to a callback.
}

The last library where I tried this had it broken - so anything after the macro name would get thrown to the callback. Further, it managed to confuse itself when I had more curly brackets in there too.

.code {
    if(a == b) {
        c=a+b;
    }
}

Is something similar possible?

Kind regards, Ingwie!

New release tag

Could you make a 2.8 (or another release number) so that the bug fixed for issue #10 can be used by other projects more easily? My current situation is to refer to libconfuse via a hash tag or master which does not inspire as much confidence in others.

IRC channel: ##libconfuse (irc.freenode.net)

Hi all,

Just because I happen to idle on freenode, I've set up a channel there ##libconfuse should any one who happens to also be on that network wish to join me there as well.

Memory leak - failure to free lexer allocated memory.

Hey, I've stumbled across a possible memory leak - not sure whether it's intentional or not -

It appears as if the free_cfg() library function neglects to free the yy_buffer_stack global variable.

I externed the cfg_yylex_destroy() function and used it straight after calling to free_cfg() and the memory leak was gone.

Using cfg_setnstr? Confused about usage

I'm trying to build config files on the fly, using the cfg_setnstr functions, but I'm completely lost as to how they work internally.

My code does:
for (i = 0; i < dev->nrofhargs; i++)
cfg_setnstr(devconf, "hargs", dev->hargs[i], i);

However, I think when this is called multiple times, it is corrupting memory somewhere. Looking over the code in confuse.c, I don't see where the array of values is created.

For example, if we look at cfg_addlist_internal(), it repeatedly calls cfg_opt_setnstr(,,opt->nvalues), but nowhere does it advance nvalues, or malloc the array of values to the size of the list. How does this work? What am I missing?

I ask, because when I modify a config file repeatedly with a different number of values, eventually my program crashes in free trying to change the values.

Do cfg_opt_t need to be non-stack variables when calling cfg_init()?

Looking at the libconfuse example file cfgtest.c, in the main() function, I see that the cfg_opt_t variables are declared static. E.g.

static cfg_opt_t proxy_opts[] = ...

Is it necessary for these to be static, i.e. non-stack variables? Or would it be fine for them to be non-static?

It would be good to remove the static in the example file if it's not necessary. If it is necessary, then it would be good to add an explanation in the documentation and/or header file.

I see the comment for cfg_init() in confuse.h:

The options must no longer be defined in the same scope as where the cfg_xxx functions are used (since version 2.3).

I'm not entirely sure what that means.

Update CONTRIBUTING.md: Add section on unit tests

We've had features coming through lately with no unit tests (myself to blame for that). Having
proper tests, and CI support for automatically running them on all commtis, for a library is crucial
to a speedy release process, issue #55.

more compiling error on MSVC(MSVC6/MSVC2010).

  1. lexer.c not generated when compile use MSVC.
  2. issue for coding.
    --------------------Configuration: libConfuse - Win32 Debug--------------------
    Compiling...
    confuse.c
    e:\github\libconfuse\src\confuse.c(838) : error C2059: syntax error : '.'
    e:\github\libconfuse\src\confuse.c(1123) : error C2065: 'ssize_t' : undeclared identifier
    e:\github\libconfuse\src\confuse.c(1123) : error C2146: syntax error : missing ';' before identifier 'n'
    e:\github\libconfuse\src\confuse.c(1123) : error C2065: 'n' : undeclared identifier
    e:\github\libconfuse\src\confuse.c(1124) : error C2143: syntax error : missing ';' before 'type'
    e:\github\libconfuse\src\confuse.c(1126) : error C2065: 'path' : undeclared identifier
    e:\github\libconfuse\src\confuse.c(1128) : error C2143: syntax error : missing ';' before 'type'
    e:\github\libconfuse\src\confuse.c(1137) : error C2065: 'np' : undeclared identifier
    e:\github\libconfuse\src\confuse.c(1139) : warning C4047: 'return' : 'char *' differs in levels of indirection from 'int '
    e:\github\libconfuse\src\confuse.c(1145) : error C2079: 'st' uses undefined struct 'stat'
    e:\github\libconfuse\src\confuse.c(1325) : warning C4090: 'function' : different 'const' qualifiers
    e:\github\libconfuse\src\confuse.c(1325) : warning C4022: 'free' : pointer mismatch for actual parameter 1
    e:\github\libconfuse\src\confuse.c(1329) : warning C4090: 'function' : different 'const' qualifiers
    e:\github\libconfuse\src\confuse.c(1329) : warning C4022: 'free' : pointer mismatch for actual parameter 1
    Error executing cl.exe.

libConfuse.dll - 9 error(s), 5 warning(s)

autogen.sh fails: macro AM_PROG_AR not found

Issue

./autogen.sh fails with the following error when I run it:

$ ./autogen.sh
autoreconf: Entering directory `.'
autoreconf: running: autopoint --force
autoreconf: running: aclocal --force --warnings=portability -I m4
configure.ac:16: warning: macro `AM_PROG_AR' not found in library
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --force
configure.ac:16: warning: macro `AM_PROG_AR' not found in library
autoreconf: running: /home/rr257875/usr/bin/autoconf --force --warnings=portability
configure.ac:16: error: possibly undefined macro: AM_PROG_AR
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.

autogen.sh is running autoreconf version 2.69.

Add support for option annotation/comments

It would be neat if we could add option annotation support to libConfuse:

/* Some comment to an option */
option = value

/* Section comment, here be dragons */
section {
    key = val
    /* Another comment, why we set to true */
    bool = true
}

So that if we call cfg_print() on the above parsed cfg_t, we would get the same output.

The following variant should also be possible:

option = value              /* Some comment to an option */

but with the following the last comment would be set

/* Some comment to an option */
option = value              /* Actual comment set to to option */

Feature request: ignore unknown options

It would be nice to have a flag to ignore any options or sections that are not specified in the cfg_opt_t array passed to cfg_init. Currently, if there is some option in the config file that is not specified, a parse error is returned by cfg_parse.

Section title dupes

First: Great work is done here! I hate to write and maintain this kind of functionality for projects over and over again. This approach outstands standard INI-file alikes.

I stumbled upon section title dupes:
with CFG_SEC("Sensor", sensor_opts, CFGF_TITLE | CFGF_MULTI),
file Sensor title1 {} Sensor title2 {} works fine.
But without CFGF_NO_TITLE_DUPES set
file: Sensor title1 {} Sensor title1 {} drops the dupe silently.

A fix would be to report an parse error anyways, even if CFGF_NO_TITLE_DUPES is not set,
or if there can be section title dupes logically, just not to search for them with the flag not set.

Because I'm on the rather old 2.7 release: Am I missing something regarding to this behavior?

Parse failed when missing one opt

In my conf file, there is an opt named "repeat", such as:
repeat = 1
target = "Tom"

But in my c++ code, my cfg_opt_t is:
char optName[] = "target";
char defValue[] = "world";

cfg_opt_t opts[] = {
    CFG_STR(optName, defValue, CFGF_NONE),
    CFG_END()
};

libconfuse return failed when calling the function "cfg_parse".

I think it should return ok because I only want to use one of so many opts in my conf file. Why can't I?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.