• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef fooconfparserhfoo
2 #define fooconfparserhfoo
3 
4 /***
5   This file is part of PulseAudio.
6 
7   Copyright 2004-2006 Lennart Poettering
8 
9   PulseAudio is free software; you can redistribute it and/or modify
10   it under the terms of the GNU Lesser General Public License as published
11   by the Free Software Foundation; either version 2.1 of the License,
12   or (at your option) any later version.
13 
14   PulseAudio is distributed in the hope that it will be useful, but
15   WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   General Public License for more details.
18 
19   You should have received a copy of the GNU Lesser General Public License
20   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
21 ***/
22 
23 #include <stdio.h>
24 
25 #include <pulse/proplist.h>
26 
27 /* An abstract parser for simple, line based, shallow configuration
28  * files consisting of variable assignments only. */
29 
30 typedef struct pa_config_parser_state pa_config_parser_state;
31 
32 typedef int (*pa_config_parser_cb_t)(pa_config_parser_state *state);
33 
34 /* Wraps info for parsing a specific configuration variable */
35 typedef struct pa_config_item {
36     const char *lvalue; /* name of the variable */
37     pa_config_parser_cb_t parse; /* Function that is called to parse the variable's value */
38     void *data; /* Where to store the variable's data */
39     const char *section;
40 } pa_config_item;
41 
42 struct pa_config_parser_state {
43     const char *filename;
44     unsigned lineno;
45     char *section;
46     char *lvalue;
47     char *rvalue;
48     void *data; /* The data pointer of the current pa_config_item. */
49     void *userdata; /* The pointer that was given to pa_config_parse(). */
50 
51     /* Private data to be used only by conf-parser.c. */
52     const pa_config_item *item_table;
53     char buf[4096];
54     pa_proplist *proplist;
55     bool in_proplist;
56 };
57 
58 /* The configuration file parsing routine. Expects a table of
59  * pa_config_items in *t that is terminated by an item where lvalue is
60  * NULL.
61  *
62  * If use_dot_d is true, then after parsing the file named by the filename
63  * argument, the function will parse all files ending with ".conf" in
64  * alphabetical order from a directory whose name is filename + ".d", if such
65  * directory exists.
66  *
67  * Some configuration files may contain a Properties section, which
68  * is a bit special. Normally all accepted lvalues must be predefined
69  * in the pa_config_item table, but in the Properties section the
70  * pa_config_item table is ignored, and all lvalues are accepted (as
71  * long as they are valid proplist keys). If the proplist pointer is
72  * non-NULL, the parser will parse any section named "Properties" as
73  * properties, and those properties will be merged into the given
74  * proplist. If proplist is NULL, then sections named "Properties"
75  * are not allowed at all in the configuration file. */
76 int pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, pa_proplist *proplist, bool use_dot_d,
77                     void *userdata);
78 
79 /* Generic parsers for integers, size_t, booleans and strings */
80 int pa_config_parse_int(pa_config_parser_state *state);
81 int pa_config_parse_unsigned(pa_config_parser_state *state);
82 int pa_config_parse_size(pa_config_parser_state *state);
83 int pa_config_parse_bool(pa_config_parser_state *state);
84 int pa_config_parse_not_bool(pa_config_parser_state *state);
85 int pa_config_parse_string(pa_config_parser_state *state);
86 
87 #endif
88