/*
 * RRDMonitor: Statistics with RRDTool
 * Copyright (C) 2003-2004 Luc Saillard <luc_at_saillard_dot_org>
 *
 * Parse a .INI file format
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#ifndef _INI_H
#define _INI_H

struct ini_key
{
  char *key;			/* contains only pointer, do not modify or free */
  char *value;			/* contains only pointer, do not modify or free */
};

struct ini_section
{
  struct ini_section *next;	/* link the next section (used by the list) */
  char *name;			/* name of the section */

  int keys_used;		/* number of valid keys in 'keys' */
  int keys_allocated;		/* number of objects that can be put in 'keys' */
  struct ini_key *keys;		/* dynamic allocated objects */
};


struct ini
{
  int   fd;		/* Filedescriptor use to parse the file */
  void *mmap;		/* Memory mapped in the file */
  int   mmaplen;

  struct ini_section *first_section;	/* Linked list to section name */
  struct ini_section *last_section;	/* pointer to the last object in the linked list */
};

#define for_each_inisections(pos) \
        for ((pos) = plugins_list; (pos)->name ; (pos)++)


extern struct ini *cfg;

struct ini *ini_open(const char *configfile);
void ini_close(struct ini *ini);
const struct ini_section *ini_find_section(const char *section);
const struct ini_key *ini_find_key_in_section(const struct ini_section *section, const char *key);
const struct ini_key *ini_find_key(const char *section_name, const char *key_name);
int ini_get_integer(const char *section_name, const char *key_name, int *value);
int ini_get_string(const char *section_name, const char *key_name, const char **name);
const struct ini_section *ini_find_sections_with_driver(const struct ini_section *section, const char *driver_name);

#endif


