1 /* Copyright 2021 The ChromiumOS Authors 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 #include <stddef.h> 11 #include <stdio.h> 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 */ 56