153a5a1b3Sopenharmony_ci#ifndef fooconfparserhfoo
253a5a1b3Sopenharmony_ci#define fooconfparserhfoo
353a5a1b3Sopenharmony_ci
453a5a1b3Sopenharmony_ci/***
553a5a1b3Sopenharmony_ci  This file is part of PulseAudio.
653a5a1b3Sopenharmony_ci
753a5a1b3Sopenharmony_ci  Copyright 2004-2006 Lennart Poettering
853a5a1b3Sopenharmony_ci
953a5a1b3Sopenharmony_ci  PulseAudio is free software; you can redistribute it and/or modify
1053a5a1b3Sopenharmony_ci  it under the terms of the GNU Lesser General Public License as published
1153a5a1b3Sopenharmony_ci  by the Free Software Foundation; either version 2.1 of the License,
1253a5a1b3Sopenharmony_ci  or (at your option) any later version.
1353a5a1b3Sopenharmony_ci
1453a5a1b3Sopenharmony_ci  PulseAudio is distributed in the hope that it will be useful, but
1553a5a1b3Sopenharmony_ci  WITHOUT ANY WARRANTY; without even the implied warranty of
1653a5a1b3Sopenharmony_ci  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1753a5a1b3Sopenharmony_ci  General Public License for more details.
1853a5a1b3Sopenharmony_ci
1953a5a1b3Sopenharmony_ci  You should have received a copy of the GNU Lesser General Public License
2053a5a1b3Sopenharmony_ci  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
2153a5a1b3Sopenharmony_ci***/
2253a5a1b3Sopenharmony_ci
2353a5a1b3Sopenharmony_ci#include <stdio.h>
2453a5a1b3Sopenharmony_ci
2553a5a1b3Sopenharmony_ci#include <pulse/proplist.h>
2653a5a1b3Sopenharmony_ci
2753a5a1b3Sopenharmony_ci/* An abstract parser for simple, line based, shallow configuration
2853a5a1b3Sopenharmony_ci * files consisting of variable assignments only. */
2953a5a1b3Sopenharmony_ci
3053a5a1b3Sopenharmony_citypedef struct pa_config_parser_state pa_config_parser_state;
3153a5a1b3Sopenharmony_ci
3253a5a1b3Sopenharmony_citypedef int (*pa_config_parser_cb_t)(pa_config_parser_state *state);
3353a5a1b3Sopenharmony_ci
3453a5a1b3Sopenharmony_ci/* Wraps info for parsing a specific configuration variable */
3553a5a1b3Sopenharmony_citypedef struct pa_config_item {
3653a5a1b3Sopenharmony_ci    const char *lvalue; /* name of the variable */
3753a5a1b3Sopenharmony_ci    pa_config_parser_cb_t parse; /* Function that is called to parse the variable's value */
3853a5a1b3Sopenharmony_ci    void *data; /* Where to store the variable's data */
3953a5a1b3Sopenharmony_ci    const char *section;
4053a5a1b3Sopenharmony_ci} pa_config_item;
4153a5a1b3Sopenharmony_ci
4253a5a1b3Sopenharmony_cistruct pa_config_parser_state {
4353a5a1b3Sopenharmony_ci    const char *filename;
4453a5a1b3Sopenharmony_ci    unsigned lineno;
4553a5a1b3Sopenharmony_ci    char *section;
4653a5a1b3Sopenharmony_ci    char *lvalue;
4753a5a1b3Sopenharmony_ci    char *rvalue;
4853a5a1b3Sopenharmony_ci    void *data; /* The data pointer of the current pa_config_item. */
4953a5a1b3Sopenharmony_ci    void *userdata; /* The pointer that was given to pa_config_parse(). */
5053a5a1b3Sopenharmony_ci
5153a5a1b3Sopenharmony_ci    /* Private data to be used only by conf-parser.c. */
5253a5a1b3Sopenharmony_ci    const pa_config_item *item_table;
5353a5a1b3Sopenharmony_ci    char buf[4096];
5453a5a1b3Sopenharmony_ci    pa_proplist *proplist;
5553a5a1b3Sopenharmony_ci    bool in_proplist;
5653a5a1b3Sopenharmony_ci};
5753a5a1b3Sopenharmony_ci
5853a5a1b3Sopenharmony_ci/* The configuration file parsing routine. Expects a table of
5953a5a1b3Sopenharmony_ci * pa_config_items in *t that is terminated by an item where lvalue is
6053a5a1b3Sopenharmony_ci * NULL.
6153a5a1b3Sopenharmony_ci *
6253a5a1b3Sopenharmony_ci * If use_dot_d is true, then after parsing the file named by the filename
6353a5a1b3Sopenharmony_ci * argument, the function will parse all files ending with ".conf" in
6453a5a1b3Sopenharmony_ci * alphabetical order from a directory whose name is filename + ".d", if such
6553a5a1b3Sopenharmony_ci * directory exists.
6653a5a1b3Sopenharmony_ci *
6753a5a1b3Sopenharmony_ci * Some configuration files may contain a Properties section, which
6853a5a1b3Sopenharmony_ci * is a bit special. Normally all accepted lvalues must be predefined
6953a5a1b3Sopenharmony_ci * in the pa_config_item table, but in the Properties section the
7053a5a1b3Sopenharmony_ci * pa_config_item table is ignored, and all lvalues are accepted (as
7153a5a1b3Sopenharmony_ci * long as they are valid proplist keys). If the proplist pointer is
7253a5a1b3Sopenharmony_ci * non-NULL, the parser will parse any section named "Properties" as
7353a5a1b3Sopenharmony_ci * properties, and those properties will be merged into the given
7453a5a1b3Sopenharmony_ci * proplist. If proplist is NULL, then sections named "Properties"
7553a5a1b3Sopenharmony_ci * are not allowed at all in the configuration file. */
7653a5a1b3Sopenharmony_ciint pa_config_parse(const char *filename, FILE *f, const pa_config_item *t, pa_proplist *proplist, bool use_dot_d,
7753a5a1b3Sopenharmony_ci                    void *userdata);
7853a5a1b3Sopenharmony_ci
7953a5a1b3Sopenharmony_ci/* Generic parsers for integers, size_t, booleans and strings */
8053a5a1b3Sopenharmony_ciint pa_config_parse_int(pa_config_parser_state *state);
8153a5a1b3Sopenharmony_ciint pa_config_parse_unsigned(pa_config_parser_state *state);
8253a5a1b3Sopenharmony_ciint pa_config_parse_size(pa_config_parser_state *state);
8353a5a1b3Sopenharmony_ciint pa_config_parse_bool(pa_config_parser_state *state);
8453a5a1b3Sopenharmony_ciint pa_config_parse_not_bool(pa_config_parser_state *state);
8553a5a1b3Sopenharmony_ciint pa_config_parse_string(pa_config_parser_state *state);
8653a5a1b3Sopenharmony_ci
8753a5a1b3Sopenharmony_ci#endif
88