Zi Lin | 5158f55 | 2021-10-27 00:55:52 +0000 | [diff] [blame^] | 1 | /* 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 |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
| 15 | struct config_entry { |
| 16 | const char *key; |
| 17 | const char *value; |
| 18 | }; |
| 19 | |
| 20 | struct 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. */ |
| 27 | struct config_entry_list *new_config_entry_list(void); |
| 28 | |
| 29 | /* Free allocated pointers in |config_entry|. */ |
| 30 | void clear_config_entry(struct config_entry *entry); |
| 31 | |
| 32 | /* Free a |config_entry_list| struct. */ |
| 33 | void 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 | */ |
| 40 | bool 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 | */ |
| 47 | bool 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 */ |