Add "extern C {...} to header files for C++ builds.
[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 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 /*
22  * Export the minimum amount of information about these structs
23  */
24 typedef struct conf_item CONF_ITEM;
25 typedef struct conf_pair CONF_PAIR;
26 typedef struct conf_part CONF_SECTION;
27 typedef struct conf_data CONF_DATA;
28
29 /*
30  *  Instead of putting the information into a configuration structure,
31  *  the configuration file routines MAY just parse it directly into
32  *  user-supplied variables.
33  */
34 #define PW_TYPE_STRING_PTR      100
35 #define PW_TYPE_BOOLEAN         101
36 #define PW_TYPE_SUBSECTION      102
37 #define PW_TYPE_FILENAME        103
38
39 typedef struct CONF_PARSER {
40   const char *name;
41   int type;                     /* PW_TYPE_STRING, etc. */
42   size_t offset;                /* relative pointer within "base" */
43   void *data;                   /* absolute pointer if base is NULL */
44   const char *dflt;             /* default as it would appear in radiusd.conf */
45 } CONF_PARSER;
46
47 /* This preprocessor trick will be useful in initializing CONF_PARSER struct */
48 #define XStringify(x) #x
49 #define Stringify(x) XStringify(x)
50
51 void            cf_pair_free(CONF_PAIR **cp);
52 int             cf_pair_replace(CONF_SECTION *cs, CONF_PAIR *cp,
53                                 const char *value);
54 void            cf_section_free(CONF_SECTION **cp);
55 int             cf_item_parse(CONF_SECTION *cs, const char *name,
56                               int type, void *data, const char *dflt);
57 int             cf_section_parse(CONF_SECTION *, void *base,
58                                  const CONF_PARSER *variables);
59 void            cf_section_parse_free(CONF_SECTION *cs, void *base);
60 const CONF_PARSER *cf_section_parse_table(CONF_SECTION *cs);
61 CONF_SECTION    *cf_file_read(const char *file);
62 int             cf_file_include(const char *file, CONF_SECTION *cs);
63
64 CONF_PAIR       *cf_pair_find(const CONF_SECTION *, const char *name);
65 CONF_PAIR       *cf_pair_find_next(const CONF_SECTION *, 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 const char      *cf_section_value_find(const CONF_SECTION *, const char *attr);
70 CONF_SECTION    *cf_top_section(CONF_SECTION *cs);
71
72 void *cf_data_find(CONF_SECTION *, const char *);
73 int cf_data_add(CONF_SECTION *, const char *, void *, void (*)(void *));
74
75 const char *cf_pair_attr(CONF_PAIR *pair);
76 const char *cf_pair_value(CONF_PAIR *pair);
77 VALUE_PAIR *cf_pairtovp(CONF_PAIR *pair);
78 const char *cf_section_name1(const CONF_SECTION *);
79 const char *cf_section_name2(const CONF_SECTION *);
80 int dump_config(CONF_SECTION *cs);
81 CONF_SECTION *cf_subsection_find_next(CONF_SECTION *section,
82                                       CONF_SECTION *subsection,
83                                       const char *name1);
84 CONF_SECTION *cf_section_find_next(CONF_SECTION *section,
85                                    CONF_SECTION *subsection,
86                                    const char *name1);
87 int cf_section_lineno(CONF_SECTION *section);
88 int cf_pair_lineno(CONF_PAIR *pair);
89 const char *cf_pair_filename(CONF_PAIR *pair);
90 const char *cf_section_filename(CONF_SECTION *section);
91 CONF_ITEM *cf_item_find_next(CONF_SECTION *section, CONF_ITEM *item);
92 int cf_item_is_section(CONF_ITEM *item);
93 int cf_item_is_pair(CONF_ITEM *item);
94 CONF_PAIR *cf_itemtopair(CONF_ITEM *item);
95 CONF_SECTION *cf_itemtosection(CONF_ITEM *item);
96 CONF_ITEM *cf_pairtoitem(CONF_PAIR *cp);
97 CONF_ITEM *cf_sectiontoitem(CONF_SECTION *cs);
98 int cf_section_template(CONF_SECTION *cs, CONF_SECTION *template);
99 void cf_log_err(CONF_ITEM *ci, const char *fmt, ...)
100 #ifdef __GNUC__
101                 __attribute__ ((format (printf, 2, 3)))
102 #endif
103 ;
104 void cf_log_info(CONF_SECTION *cs, const char *fmt, ...)
105 #ifdef __GNUC__
106                 __attribute__ ((format (printf, 2, 3)))
107 #endif
108 ;
109 void cf_log_module(CONF_SECTION *cs, const char *fmt, ...)
110 #ifdef __GNUC__
111                 __attribute__ ((format (printf, 2, 3)))
112 #endif
113 ;
114 CONF_ITEM *cf_reference_item(const CONF_SECTION *parentcs,
115                              CONF_SECTION *outercs,
116                              const char *ptr);
117 extern int cf_log_config;
118 extern int cf_log_modules;
119
120 extern int cf_pair2xml(FILE *fp, const CONF_PAIR *cp);
121 extern int cf_section2xml(FILE *fp, const CONF_SECTION *cs);
122 extern int cf_pair2file(FILE *fp, const CONF_PAIR *cp);
123 extern int cf_section2file(FILE *fp, const CONF_SECTION *cs);
124
125 /*
126  *      Big magic.
127  */
128 int cf_section_migrate(CONF_SECTION *dst, CONF_SECTION *src);
129
130 #ifdef __cplusplus
131 }
132 #endif
133
134 #endif /* _CONFFILE_H */