Mike Frysinger | 4c33189 | 2022-09-13 05:17:08 -0400 | [diff] [blame] | 1 | /* Copyright 2021 The ChromiumOS Authors |
Zi Lin | 5158f55 | 2021-10-27 00:55:52 +0000 | [diff] [blame] | 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> |
Christian Blichmann | 0b83334 | 2022-01-10 14:26:50 +0100 | [diff] [blame] | 10 | #include <stddef.h> |
| 11 | #include <stdio.h> |
Zi Lin | 5158f55 | 2021-10-27 00:55:52 +0000 | [diff] [blame] | 12 | |
| 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
| 17 | struct config_entry { |
| 18 | const char *key; |
| 19 | const char *value; |
| 20 | }; |
| 21 | |
| 22 | struct 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. */ |
| 29 | struct config_entry_list *new_config_entry_list(void); |
| 30 | |
| 31 | /* Free allocated pointers in |config_entry|. */ |
| 32 | void clear_config_entry(struct config_entry *entry); |
| 33 | |
| 34 | /* Free a |config_entry_list| struct. */ |
| 35 | void 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 | */ |
| 42 | bool 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 | */ |
| 49 | bool 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 */ |