confuse-devel
[Top][All Lists]
Advanced

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

Re: [Confuse-devel] Need help with libconfuse


From: Martin Hedenfalk
Subject: Re: [Confuse-devel] Need help with libconfuse
Date: Sat, 25 Oct 2003 10:15:43 +0200

Hi,

Yes, there could be errors in your config file. Or in the program. Or a bug in the library.

LibConfuse can't find the option in it's list (the cfg_opt_t array passed to cfg_init). If there is an option not found, libConfused will print an error and abort.

Check the spelling, upper/lower case, etc.

/martin

tisdagen den 21 oktober 2003 kl 11.24 skrev Rajeev Sampige:

Hi Martin, Thanks for your help.
When I tried to parse the config file, I got the following error.

AAROTS.conf:2: no such option 'retry_count'
parse error

AAROTS.conf file will have entries like you have suggested.
All I'm doing in my .c file is to parse and print the values.
Does this error mean my config file is not proper ?

Thanks,
Rajeev


From: Martin Hedenfalk <address@hidden>
To: Rajeev Sampige <address@hidden>
CC: address@hidden
Subject: Re: [Confuse-devel] Need help with libconfuse
Date: Fri, 17 Oct 2003 14:09:34 +0200

On Fri, 2003-10-17 at 13:13, Rajeev Sampige wrote:
> Hi,

Hello!

> I'm developing a server which is supposed to open a default config file
> and get the information about some components present on the system.
>
> Sample config file looks like,
>
> # sessions
>
> polling_interval = 5
>
> retry_count=4
>
> ABC_0
> IPAddress=10.0.10.1
> UserID=admin
> Passwd=admin
>
> DEF_0
> IPAddress=10.0.10.2
> UserID=user1
> Passwd=user2
>
> The plan is to try connect to ABC_0, DEF_0 ..etc using IP address and
> other details. we could have many sets similar to ABC_0, but we will
> have only one entry of retry_count and polling_interval.
> Is it possible for me to use libconfuse APIs for this purpose ?

Yes, you can create a section called e.g. "server", and your config file
would then look something like this:

polling_interval = 5
retry_count = 4
server ABC_0 {
  IPAddress=10.0.10.1
  UserID=admin
  Passwd=admin
}
server DEF_0 {
  IPAddress=10.0.10.2
  UserID=user1
  Passwd=user2
}

> Could you suggest me a skeletal code in c ?

/* options for the "server" section */
cfg_opt_t server_opts[] = {
  CFG_STR("IPAddress", 0, CFGF_NONE),
  CFG_STR("UserID", 0, CFGF_NONE),
  CFG_STR("Passwd", 0, CFGF_NONE),
}

/* global options */
cfg_opt_t opts[] = {
  CFG_INT("polling_interval", 5, CFGF_NONE),
  CFG_INT("retry_count", 4, CFGF_NONE),
  CFG_SEC("server", server_opts, CFGF_MULTI | CFGF_TITLE),
  CFG_END()
}

main()
{
  int i;

  /* initialize and parse config file */
  cfg_t *cfg = cfg_init(opts, CFGF_NOCASE);
  cfg_parse(cfg, "filename.conf");

  /* do something with each configured server */
  for(i = 0; i < cfg_size(cfg, "server"); i++
  {
    cfg_sec_t *sec = cfg_getnsec(cfg, "server", i);

    do_something(cfg_getstr(sec, "IPAddress"),
                 cfg_getstr(sec, "UserID"),
                 cfg_getstr(sec, "Passwd"));
  }

  cfg_free(cfg);
}

> Thanks,
> Rajeev
>

HTH / Martin



_________________________________________________________________
Enjoy MSN 8 patented spam control and more with MSN 8 Dial-up Internet Service. Try it FREE for one month! http://join.msn.com/?page=dept/dialup






reply via email to

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