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