conf-parser.h revision 10e87ee7f66b59a504c0ed2025463ba5faa69923
337eebb936be1da1215535e866965ce54c82d755Lennart Poettering/*-*- Mode: C; c-basic-offset: 8 -*-*/
652e737517bbbae692923246aeb687e2d1f314efZbigniew Jędrzejewski-Szmek
0e0320e04500d1e68630b3973714f14cfb7b3450Lennart Poettering#ifndef fooconfparserhfoo
652e737517bbbae692923246aeb687e2d1f314efZbigniew Jędrzejewski-Szmek#define fooconfparserhfoo
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering/***
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering This file is part of systemd.
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering Copyright 2010 Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering systemd is free software; you can redistribute it and/or modify it
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering under the terms of the GNU General Public License as published by
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering the Free Software Foundation; either version 2 of the License, or
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering (at your option) any later version.
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering systemd is distributed in the hope that it will be useful, but
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0e0320e04500d1e68630b3973714f14cfb7b3450Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
652e737517bbbae692923246aeb687e2d1f314efZbigniew Jędrzejewski-Szmek General Public License for more details.
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering You should have received a copy of the GNU General Public License
0e0320e04500d1e68630b3973714f14cfb7b3450Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering***/
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering#include <stdio.h>
93a1d735aca5584a005d851f12cb0b8c7bb5e5caLennart Poettering#include <stdbool.h>
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
0e0320e04500d1e68630b3973714f14cfb7b3450Lennart Poettering/* An abstract parser for simple, line based, shallow configuration
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering * files consisting of variable assignments only. */
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poetteringtypedef int (*ConfigParserCallback)(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering/* Wraps info for parsing a specific configuration variable */
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poetteringtypedef struct ConfigItem {
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering const char *lvalue; /* name of the variable */
0e0320e04500d1e68630b3973714f14cfb7b3450Lennart Poettering ConfigParserCallback parse; /* Function that is called to parse the variable's value */
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering void *data; /* Where to store the variable's data */
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering const char *section;
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering} ConfigItem;
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering/* The configuration file parsing routine. Expects a table of
3a67e927e3be7efb8edf314a31aa4f8f5cba4f53Tom Gundersen * config_items in *t that is terminated by an item where lvalue is
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering * NULL */
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poetteringint config_parse(const char *filename, FILE *f, const char* const *sections, const ConfigItem *t, bool relaxed, void *userdata);
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering/* Generic parsers */
0e0320e04500d1e68630b3973714f14cfb7b3450Lennart Poetteringint config_parse_int(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poetteringint config_parse_unsigned(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
0e0320e04500d1e68630b3973714f14cfb7b3450Lennart Poetteringint config_parse_size(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poetteringint config_parse_bool(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
2b93b027d3a68b5d7ae26d0c2cd487eb5019d2a9Lennart Poetteringint config_parse_string(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poetteringint config_parse_path(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
0e0320e04500d1e68630b3973714f14cfb7b3450Lennart Poetteringint config_parse_strv(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poetteringint config_parse_path_strv(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata);
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering
7c9a6f906308a6474f1ebb98058c4a33a02c33f1Lennart Poettering#endif
a91df40e69fec72cc98c9829721fa5153da28bc2Kay Sievers