1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
* Copyright (C) 2016-2024 Canonical, Ltd.
* Author: Martin Pitt <martin.pitt@ubuntu.com>
* Author: Lukas Märdian <slyon@ubuntu.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file parse.h
* @brief Parsing Netplan YAML configuration into @ref NetplanParser data structures.
*/
#pragma once
#include <glib.h>
#include "types.h"
/****************************************************
* Functions
****************************************************/
/**
* @brief Allocate and initialize a new @ref NetplanParser object.
* @note This contains unvalidated Netplan configuration from raw input, like Netplan YAML or NetworkManager keyfile.
* @return An empty @ref NetplanParser
*/
NETPLAN_PUBLIC NetplanParser*
netplan_parser_new(void);
/**
* @brief Reset a @ref NetplanParser to its initial default values.
* @details Freeing any dynamically allocated parsing data.
* @param[in] npp The @ref NetplanParser to be reset
*/
NETPLAN_PUBLIC void
netplan_parser_reset(NetplanParser *npp);
/**
* @brief Free a @ref NetplanParser, including any dynamically allocated data.
* @details Similar to @ref netplan_parser_reset, but also free and nullify the object itself.
* @param[out] npp The @ref NetplanParser to free and nullify
*/
NETPLAN_PUBLIC void
netplan_parser_clear(NetplanParser **npp);
/**
* @brief Set @ref NetplanParser flags.
* @details Parser flags are used to change the default behavior of the parser.
* @param[in] npp The @ref NetplanParser to set the flags.
* @param[in] flags The value of the flags. The possible values are defined in @ref NETPLAN_PARSER_FLAGS
* @param[out] error Filled with a @ref NetplanError in case of failure
* @return Indication of success or failure
*/
NETPLAN_PUBLIC gboolean
netplan_parser_set_flags(NetplanParser* npp, unsigned int flags, NetplanError** error);
/**
* @brief Get @ref NetplanParser flags.
* @details Parser flags are used to change the default behavior of the parser.
* @param[in] npp The @ref NetplanParser to get the flags from.
* @return The current flags set in the parser.
*/
NETPLAN_PUBLIC unsigned int
netplan_parser_get_flags(const NetplanParser* npp);
/**
* @brief Get @ref NetplanParser error count.
* @details The number of errors that were ignored when the IGNORE_ERRORS is used.
* @param[in] npp The @ref NetplanParser to get the error count from.
* @return The current error count.
*/
NETPLAN_PUBLIC unsigned int
netplan_parser_get_error_count(const NetplanParser* npp);
/**
* @brief Parse a given YAML file and create or update the list of @ref NetplanNetDefinition inside @p npp.
* @param[in] npp The @ref NetplanParser object that should contain the parsed data
* @param[in] filename Full path to a Netplan YAML configuration file
* @param[out] error Filled with a @ref NetplanError in case of failure
* @return Indication of success or failure
*/
NETPLAN_PUBLIC gboolean
netplan_parser_load_yaml(NetplanParser* npp, const char* filename, NetplanError** error);
/**
* @brief Parse a given YAML file from a file descriptor and create or update the list of
@ref NetplanNetDefinition inside @p npp.
* @param[in] npp The @ref NetplanParser object that should contain the parsed data
* @param[in] input_fd File descriptor reference to a Netplan YAML configuration file
* @param[out] error Filled with a @ref NetplanError in case of failure
* @return Indication of success or failure
*/
NETPLAN_PUBLIC gboolean
netplan_parser_load_yaml_from_fd(NetplanParser* npp, int input_fd, NetplanError** error);
/**
* @brief Parse a full hierarchy of `/{usr/lib,etc,run}/netplan/\*.yaml` files inside
* @p rootdir and create or update the list of @ref NetplanNetDefinition inside @p npp.
* @note Files with "asciibetically" higher names override/append settings from earlier ones
* (in all Netplan config directories); files in `/run/netplan/` shadow files in
* `/etc/netplan/`, which shadow files in `/usr/lib/netplan/`.
* @param[in] npp The @ref NetplanParser object that should contain the parsed data
* @param[in] rootdir If not `NULL`, parse configuration from this root directory (useful for testing)
* @param[out] error Filled with a @ref NetplanError in case of failure
* @return Indication of success or failure
*/
NETPLAN_PUBLIC gboolean
netplan_parser_load_yaml_hierarchy(NetplanParser* npp, const char* rootdir, NetplanError** error);
/**
* @brief Parse a Netplan YAML configuration file from a file descriptor, containing settings
* that are about to be deleted (e.g. `some.setting=NULL`).
* @details The `NULL`-settings are ignored when parsing subsequent YAML files.
* @param[in] npp The @ref NetplanParser object that should contain the parsed data
* @param[in] input_fd File descriptor reference to a Netplan YAML configuration file
* @param[out] error Filled with a @ref NetplanError in case of failure
* @return Indication of success or failure
*/
NETPLAN_PUBLIC gboolean
netplan_parser_load_nullable_fields(NetplanParser* npp, int input_fd, NetplanError** error);
/**
* @brief Parse a Netplan YAML configuration file from a file descriptor, containing special settings that
* are to be overriden inside the YAML hierarchy by the resulting "origin-hint" output file.
* @details Global settings (like `renderer`) or @ref NetplanNetDefinition, defined in @p input_fd
* are ignored in the existing YAML hierarchy because the @p input_fd configuration
* overrides those settings via the "origin-hint" output file.
* @note Those settings are supposed to be parsed from the "origin-hint" output file given in @p constraint only.
* @param[in] npp The @ref NetplanParser object that should contain the parsed data
* @param[in] input_fd File descriptor reference to a Netplan YAML configuration file, which would become the "origin-hint" output file afterwards
* @param[in] constraint Basename of the "origin-hint" output file
* @param[out] error Filled with a @ref NetplanError in case of failure
* @return Indication of success or failure
*/
NETPLAN_PUBLIC gboolean
netplan_parser_load_nullable_overrides(
NetplanParser* npp, int input_fd, const char* constraint, NetplanError** error);
|