From branch_1_1
[freeradius.git] / src / include / conffile.h
1 #ifndef _CONFFILE_H
2 #define _CONFFILE_H
3
4 /*
5  * conffile.h   Defines for the conffile parsing routines.
6  *
7  * Version:     $Id$
8  *
9  */
10
11 #include <freeradius-devel/ident.h>
12 RCSIDH(conffile_h, "$Id$")
13
14 #include <stddef.h>
15 #include <freeradius-devel/token.h>
16
17 /*
18  * Export the minimum amount of information about these structs
19  */
20 typedef struct conf_item CONF_ITEM;
21 typedef struct conf_pair CONF_PAIR;
22 typedef struct conf_part CONF_SECTION;
23 typedef struct conf_data CONF_DATA;
24
25 /*
26  *  Instead of putting the information into a configuration structure,
27  *  the configuration file routines MAY just parse it directly into
28  *  user-supplied variables.
29  */
30 #define PW_TYPE_STRING_PTR      100
31 #define PW_TYPE_BOOLEAN         101
32 #define PW_TYPE_SUBSECTION      102
33 #define PW_TYPE_FILENAME        103
34
35 typedef struct CONF_PARSER {
36   const char *name;
37   int type;                     /* PW_TYPE_STRING, etc. */
38   size_t offset;                /* relative pointer within "base" */
39   void *data;                   /* absolute pointer if base is NULL */
40   const char *dflt;             /* default as it would appear in radiusd.conf */
41 } CONF_PARSER;
42
43 /* This preprocessor trick will be useful in initializing CONF_PARSER struct */
44 #define XStringify(x) #x
45 #define Stringify(x) XStringify(x)
46 /* And this pointer trick too */
47 #ifndef offsetof
48 # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
49 #endif
50
51 void            cf_pair_free(CONF_PAIR **cp);
52 void            cf_section_free(CONF_SECTION **cp);
53 int             cf_item_parse(CONF_SECTION *cs, const char *name,
54                               int type, void *data, const char *dflt);
55 int             cf_section_parse(const CONF_SECTION *, void *base,
56                                  const CONF_PARSER *variables);
57 /*
58  *      Free strings we've parsed into a structure.
59  */
60 void            cf_section_parse_free_strings(void *base,
61                                               const CONF_PARSER *variables);
62 CONF_SECTION    *cf_file_read(const char *file);
63 int             cf_file_include(const char *file, CONF_SECTION *cs);
64
65 CONF_PAIR       *cf_pair_find(const CONF_SECTION *, const char *name);
66 CONF_PAIR       *cf_pair_find_next(const CONF_SECTION *, const CONF_PAIR *, const char *name);
67 CONF_SECTION    *cf_section_find(const char *name);
68 CONF_SECTION    *cf_section_sub_find(const CONF_SECTION *, const char *name);
69 CONF_SECTION    *cf_section_sub_find_name2(const CONF_SECTION *, const char *name1, const char *name2);
70 char            *cf_section_value_find(const CONF_SECTION *, const char *attr);
71
72 void *cf_data_find(CONF_SECTION *, const char *);
73 int cf_data_add(CONF_SECTION *, const char *, void *, void (*)(void *));
74
75 char *cf_pair_attr(CONF_PAIR *pair);
76 char *cf_pair_value(CONF_PAIR *pair);
77 const char *cf_section_name1(const CONF_SECTION *);
78 const char *cf_section_name2(const CONF_SECTION *);
79 int dump_config(void);
80 CONF_SECTION *cf_subsection_find_next(CONF_SECTION *section,
81                                       CONF_SECTION *subsection,
82                                       const char *name1);
83 int cf_section_lineno(CONF_SECTION *section);
84 int cf_pair_lineno(CONF_PAIR *pair);
85 CONF_ITEM *cf_item_find_next(CONF_SECTION *section, CONF_ITEM *item);
86 int cf_item_is_section(CONF_ITEM *item);
87 int cf_item_is_pair(CONF_ITEM *item);
88 CONF_PAIR *cf_itemtopair(CONF_ITEM *item);
89 CONF_SECTION *cf_itemtosection(CONF_ITEM *item);
90 CONF_ITEM *cf_pairtoitem(CONF_PAIR *cp);
91 CONF_ITEM *cf_sectiontoitem(CONF_SECTION *cs);
92
93 /*
94  *      Big magic.
95  */
96 int cf_section_migrate(CONF_SECTION *dst, CONF_SECTION *src);
97
98 #endif /* _CONFFILE_H */