blob: b158e5cc194cbfbb00e9b5d3bcadcd14a138d744 [file] [log] [blame]
Mike Frysinger4c331892022-09-13 05:17:08 -04001/* Copyright 2021 The ChromiumOS Authors
Zi Lin5158f552021-10-27 00:55:52 +00002 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6#ifndef CONFIG_PARSER_H
7#define CONFIG_PARSER_H
8
9#include <stdbool.h>
Christian Blichmann0b833342022-01-10 14:26:50 +010010#include <stddef.h>
11#include <stdio.h>
Zi Lin5158f552021-10-27 00:55:52 +000012
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17struct config_entry {
18 const char *key;
19 const char *value;
20};
21
22struct config_entry_list {
23 struct config_entry *entries;
24 size_t num_entries;
25 size_t num_allocated_;
26};
27
28/* Allocate a new |config_entry_list| struct. */
29struct config_entry_list *new_config_entry_list(void);
30
31/* Free allocated pointers in |config_entry|. */
32void clear_config_entry(struct config_entry *entry);
33
34/* Free a |config_entry_list| struct. */
35void free_config_entry_list(struct config_entry_list *list);
36
37/*
38 * Parse one config line into a entry.
39 *
40 * Returns true for success, otherwise false for parsing failures.
41 */
42bool parse_config_line(const char *config_line, struct config_entry *entry);
43
44/*
45 * Parse a minijail config file into a |config_entry_list|.
46 *
47 * Returns true for success, otherwise false for parsing failures.
48 */
49bool parse_config_file(FILE *config_file, struct config_entry_list *list);
50
51#ifdef __cplusplus
52}; /* extern "C" */
53#endif
54
55#endif /* CONFIG_PARSER_H */