blob: f001cdb5955a2d54efd2ec08c3b39cb9b492a21f [file] [log] [blame]
Zi Lin5158f552021-10-27 00:55:52 +00001/* Copyright 2021 The Chromium OS Authors. All rights reserved.
2 * 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>
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15struct config_entry {
16 const char *key;
17 const char *value;
18};
19
20struct config_entry_list {
21 struct config_entry *entries;
22 size_t num_entries;
23 size_t num_allocated_;
24};
25
26/* Allocate a new |config_entry_list| struct. */
27struct config_entry_list *new_config_entry_list(void);
28
29/* Free allocated pointers in |config_entry|. */
30void clear_config_entry(struct config_entry *entry);
31
32/* Free a |config_entry_list| struct. */
33void free_config_entry_list(struct config_entry_list *list);
34
35/*
36 * Parse one config line into a entry.
37 *
38 * Returns true for success, otherwise false for parsing failures.
39 */
40bool parse_config_line(const char *config_line, struct config_entry *entry);
41
42/*
43 * Parse a minijail config file into a |config_entry_list|.
44 *
45 * Returns true for success, otherwise false for parsing failures.
46 */
47bool parse_config_file(FILE *config_file, struct config_entry_list *list);
48
49#ifdef __cplusplus
50}; /* extern "C" */
51#endif
52
53#endif /* CONFIG_PARSER_H */