1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef __INCLUDE_RTE_CFGFILE_H__
6 #define __INCLUDE_RTE_CFGFILE_H__
16 * RTE Configuration File
18 * This library allows reading application defined parameters from standard
19 * format configuration file.
24 #define CFG_NAME_LEN 64
28 #define CFG_VALUE_LEN 256
31 /** Configuration file */
34 /** Configuration file entry */
35 struct rte_cfgfile_entry {
36 char name[CFG_NAME_LEN]; /**< Name */
37 char value[CFG_VALUE_LEN]; /**< Value */
40 /** Configuration file operation optional arguments */
41 struct rte_cfgfile_parameters {
42 /** Config file comment character; one of '!', '#', '%', ';', '@' */
43 char comment_character;
46 /**@{ cfgfile load operation flags */
49 * Indicates that the file supports key value entries before the first
50 * defined section. These entries can be accessed in the "GLOBAL"
53 CFG_FLAG_GLOBAL_SECTION = 1,
56 * Indicates that file supports key value entries where the value can
57 * be zero length (e.g., "key=").
59 CFG_FLAG_EMPTY_VALUES = 2,
63 /** Defines the default comment character used for parsing config files. */
64 #define CFG_DEFAULT_COMMENT_CHARACTER ';'
74 * Handle to configuration file on success, NULL otherwise
76 struct rte_cfgfile *rte_cfgfile_load(const char *filename, int flags);
79 * Open config file with specified optional parameters.
86 * Additional configuration attributes. Must be configured with desired
87 * values prior to invoking this API.
89 * Handle to configuration file on success, NULL otherwise
91 struct rte_cfgfile *rte_cfgfile_load_with_params(const char *filename,
92 int flags, const struct rte_cfgfile_parameters *params);
95 * Create new cfgfile instance with empty sections and entries
98 * - CFG_FLAG_GLOBAL_SECTION
99 * Indicates that the file supports key value entries before the first
100 * defined section. These entries can be accessed in the "GLOBAL"
102 * - CFG_FLAG_EMPTY_VALUES
103 * Indicates that file supports key value entries where the value can
104 * be zero length (e.g., "key=").
106 * Handle to cfgfile instance on success, NULL otherwise
108 struct rte_cfgfile *rte_cfgfile_create(int flags);
111 * Add section in cfgfile instance.
114 * Pointer to the cfgfile structure.
116 * Section name which will be add to cfgfile.
118 * 0 on success, -ENOMEM if can't add section
121 rte_cfgfile_add_section(struct rte_cfgfile *cfg, const char *sectionname);
124 * Add entry to specified section in cfgfile instance.
127 * Pointer to the cfgfile structure.
129 * Given section name to add an entry.
133 * Entry value to add.
135 * 0 on success, -EEXIST if entry already exist, -EINVAL if bad argument
137 int rte_cfgfile_add_entry(struct rte_cfgfile *cfg,
138 const char *sectionname, const char *entryname,
139 const char *entryvalue);
142 * Update value of specified entry name in given section in config file
149 * Entry name to look for the value change
151 * New entry value. Can be also an empty string if CFG_FLAG_EMPTY_VALUES = 1
153 * 0 on success, -EINVAL if bad argument
155 int rte_cfgfile_set_entry(struct rte_cfgfile *cfg, const char *sectionname,
156 const char *entryname, const char *entryvalue);
159 * Save object cfgfile to file on disc
162 * Config file structure
164 * File name to save data
166 * 0 on success, errno otherwise
168 int rte_cfgfile_save(struct rte_cfgfile *cfg, const char *filename);
171 * Get number of sections in config file
178 * Maximum section name length
182 int rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sec_name,
186 * Get name of all config file sections.
188 * Fills in the array sections with the name of all the sections in the file
189 * (up to the number of max_sections sections).
194 * Array containing section names after successful invocation. Each element
195 * of this array should be preallocated by the user with at least
196 * CFG_NAME_LEN characters.
197 * @param max_sections
198 * Maximum number of section names to be stored in sections array
200 * Number of populated sections names
202 int rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
206 * Check if given section exists in config file
213 * TRUE (value different than 0) if section exists, FALSE (value 0) otherwise
215 int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
218 * Get number of entries in given config file section
220 * If multiple sections have the given name this function operates on the
228 * Number of entries in section on success, -1 otherwise
230 int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
231 const char *sectionname);
234 * Get number of entries in given config file section
236 * The index of a section is the same as the index of its name in the
237 * result of rte_cfgfile_sections. This API can be used when there are
238 * multiple sections with the same name.
247 * Number of entries in section on success, -1 otherwise
249 int rte_cfgfile_section_num_entries_by_index(struct rte_cfgfile *cfg,
254 * Get section entries as key-value pairs
256 * If multiple sections have the given name this function operates on the
264 * Pre-allocated array of at least max_entries entries where the section
265 * entries are stored as key-value pair after successful invocation
267 * Maximum number of section entries to be stored in entries array
269 * Number of entries populated on success, -1 otherwise
271 int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
272 const char *sectionname,
273 struct rte_cfgfile_entry *entries,
277 * Get section entries as key-value pairs
279 * The index of a section is the same as the index of its name in the
280 * result of rte_cfgfile_sections. This API can be used when there are
281 * multiple sections with the same name.
288 * Pre-allocated string of at least CFG_NAME_LEN characters where the
289 * section name is stored after successful invocation.
291 * Pre-allocated array of at least max_entries entries where the section
292 * entries are stored as key-value pair after successful invocation
294 * Maximum number of section entries to be stored in entries array
296 * Number of entries populated on success, -1 otherwise
298 int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
301 struct rte_cfgfile_entry *entries,
305 * Get value of the named entry in named config file section
307 * If multiple sections have the given name this function operates on the
317 * Entry value on success, NULL otherwise
319 const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
320 const char *sectionname,
321 const char *entryname);
324 * Check if given entry exists in named config file section
326 * If multiple sections have the given name this function operates on the
336 * TRUE (value different than 0) if entry exists, FALSE (value 0) otherwise
338 int rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname,
339 const char *entryname);
347 * 0 on success, -1 otherwise
349 int rte_cfgfile_close(struct rte_cfgfile *cfg);