confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Confuse-devel] libconfuse help (several questions)


From: Martin Hedenfalk
Subject: Re: [Confuse-devel] libconfuse help (several questions)
Date: Mon, 28 Apr 2003 09:47:19 +0200

On Sun, 27 Apr 2003 22:32:19 -0300
"Ademar de Souza Reis Jr." <address@hidden> wrote:

> Hi.

Hello!

> [Please keep me in CC since I'm not subscribe to the list]
> 
> I'm trying to convert the config parser of one of my projects
> (sniffdet - http://sniffdet.sf.net) to use libconfuse, but I'm having
> some problems (I'm using libconfuse 2.0).
> 
> The new config system is basically finished (it works), but there are
> some things that I just don't know if are possible to be done with
> libconfuse or how to do them.
> 
> Here we go:
> 
> My config file has a syntax like:
> 
> """
> section1 {
>       var = value
>       ...
> }
> 
> section2 {
>       var = value
>       ...
> }
> """
> 
> 1. In my config file, all sections are optional, but if, for ex.,
> "sectionname" doesn't exist, I get an abort() when calling
> cfg_getsec(cfg,"sectionname") because of a assertion at confuse.c:235.
> Is that a bug?  Or Is there another way to discover if a section is
> present in the config file? When reading the docs, I understood
> cfg_getsec() should return 0 in this case, but it returns this value
> only if I didn't defined "sectionname" as CFG_SEC() for the main
> cfg_opt_t structure, which I did of course("sectionname" is valid,
> it's just optional).
> 
> Getting a segfault just because you commented out some parts of your
> config file is really annoying (I was stuck in this problem for some
> time) :)

Well it's not really a bug, I would rather call it unclear documentation
:-) And I agree that one can argue if having an assertion instead of
returning NULL is the most intuitive.

There are a lot of assertions in the code, to "protect" against misuse
of the API. I felt this was necessary because the library uses a lot of
casts and the compiler won't warn against wrong arguments. However, the
library should not abort due to unexpected or left out options in the
configuration file.

As it is now, the cfg_getXXX functions returns zero if the option is not
declared (with the CFG_XXX macros) and an assertion is raised if you try
to access a nonexistent index. Since sections can't have default values,
an assertion is raised even on index 0 (zero).

The function cfg_size() should be used to check the number of values. So
your code should be changed to something like:

if(cfg_size(cfg, "sectionname"))
   sec = cfg_getsec(cfg, "sectionname"))

I'm open for a discussion about what's the Right Way to do this.


> 2. Is there a callback for values different than int? The docs/example
> mention the callback to set int values (CFG_INT_CB), but what I need
> is a callback to parse string values.
> Ex.: I have statements like:
> 
> foobar {
>       fake_mac_address = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
>       fake_dest_ip_addr = "192.168.1.200"
> }
> 
> And I would like to set a callback to check if the values have valid
> syntax and are inside the valid range.

Yes, there and CFG_STR_CB, and CFG_XXX_CB for all other supported types.
They work in the same way as the int example.

> 3: Actually, my config file has a ";" at the end of every statement. I
> know that ";" has no strong semantic value in my case, but I would
> like to stay with it anyway (to keep compatibility with my old config
> file - before libconfuse). Is there a way to accept/enforce it?
> Confuse is interpreting it as part of the value being assigned,
> returning "syntax error" (this is really minor :).

No, there is currently no way to skip the ";".  I *might* accept a patch
that adds optional semicolons at the end of option assignments.

> 4. Is the CVS at savannah.nongnu.org the main one? I'm asking this
> because all files there have the last change from 7 weeks ago.

Yes it's the main one, but I've been lazy and haven't really started
using it. I simply haven't had the time to mess with savannahs ssh key
upload yet.

> That's it. Any help will be really appreciated. Thanks!
> 
> (BTW, It's my first contact with libconfuse, so please forgive me if
> I'm doing something stupid... :)
> 
> -- 
> Ademar de Souza Reis Jr. <address@hidden>
> http://www.ademar.org
> 

> WYSIWYG editor? VI! I see text, I get text!
I liked this one :-)


-- 
Martin Hedenfalk <address@hidden>
Systemutvecklare - Esplanad Business Solutions AB




reply via email to

[Prev in Thread] Current Thread [Next in Thread]