4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __INCLUDE_RTE_CFGFILE_H__
35 #define __INCLUDE_RTE_CFGFILE_H__
45 * RTE Configuration File
47 * This library allows reading application defined parameters from standard
48 * format configuration file.
53 #define CFG_NAME_LEN 64
57 #define CFG_VALUE_LEN 256
60 /** Configuration file */
63 /** Configuration file entry */
64 struct rte_cfgfile_entry {
65 char name[CFG_NAME_LEN]; /**< Name */
66 char value[CFG_VALUE_LEN]; /**< Value */
69 /** Configuration file operation optional arguments */
70 struct rte_cfgfile_parameters {
71 /** Config file comment character; one of '!', '#', '%', ';', '@' */
72 char comment_character;
75 /**@{ cfgfile load operation flags */
78 * Indicates that the file supports key value entries before the first
79 * defined section. These entries can be accessed in the "GLOBAL"
82 CFG_FLAG_GLOBAL_SECTION = 1,
85 * Indicates that file supports key value entries where the value can
86 * be zero length (e.g., "key=").
88 CFG_FLAG_EMPTY_VALUES = 2,
92 /** Defines the default comment character used for parsing config files. */
93 #define CFG_DEFAULT_COMMENT_CHARACTER ';'
103 * Handle to configuration file on success, NULL otherwise
105 struct rte_cfgfile *rte_cfgfile_load(const char *filename, int flags);
108 * Open config file with specified optional parameters.
115 * Additional configuration attributes. Must be configured with desired
116 * values prior to invoking this API.
118 * Handle to configuration file on success, NULL otherwise
120 struct rte_cfgfile *rte_cfgfile_load_with_params(const char *filename,
121 int flags, const struct rte_cfgfile_parameters *params);
124 * Create new cfgfile instance with empty sections and entries
127 * - CFG_FLAG_GLOBAL_SECTION
128 * Indicates that the file supports key value entries before the first
129 * defined section. These entries can be accessed in the "GLOBAL"
131 * - CFG_FLAG_EMPTY_VALUES
132 * Indicates that file supports key value entries where the value can
133 * be zero length (e.g., "key=").
135 * Handle to cfgfile instance on success, NULL otherwise
137 struct rte_cfgfile *rte_cfgfile_create(int flags);
140 * Add section in cfgfile instance.
143 * Pointer to the cfgfile structure.
145 * Section name which will be add to cfgfile.
147 * 0 on success, -ENOMEM if can't add section
150 rte_cfgfile_add_section(struct rte_cfgfile *cfg, const char *sectionname);
153 * Add entry to specified section in cfgfile instance.
156 * Pointer to the cfgfile structure.
158 * Given section name to add an entry.
162 * Entry value to add.
164 * 0 on success, -EEXIST if entry already exist, -EINVAL if bad argument
166 int rte_cfgfile_add_entry(struct rte_cfgfile *cfg,
167 const char *sectionname, const char *entryname,
168 const char *entryvalue);
171 * Update value of specified entry name in given section in config file
178 * Entry name to look for the value change
180 * New entry value. Can be also an empty string if CFG_FLAG_EMPTY_VALUES = 1
182 * 0 on success, -EINVAL if bad argument
184 int rte_cfgfile_set_entry(struct rte_cfgfile *cfg, const char *sectionname,
185 const char *entryname, const char *entryvalue);
188 * Save object cfgfile to file on disc
191 * Config file structure
193 * File name to save data
195 * 0 on success, errno otherwise
197 int rte_cfgfile_save(struct rte_cfgfile *cfg, const char *filename);
200 * Get number of sections in config file
207 * Maximum section name length
211 int rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sec_name,
215 * Get name of all config file sections.
217 * Fills in the array sections with the name of all the sections in the file
218 * (up to the number of max_sections sections).
223 * Array containing section names after successful invocation. Each element
224 * of this array should be preallocated by the user with at least
225 * CFG_NAME_LEN characters.
226 * @param max_sections
227 * Maximum number of section names to be stored in sections array
229 * Number of populated sections names
231 int rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
235 * Check if given section exists in config file
242 * TRUE (value different than 0) if section exists, FALSE (value 0) otherwise
244 int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
247 * Get number of entries in given config file section
249 * If multiple sections have the given name this function operates on the
257 * Number of entries in section on success, -1 otherwise
259 int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
260 const char *sectionname);
263 * Get number of entries in given config file section
265 * The index of a section is the same as the index of its name in the
266 * result of rte_cfgfile_sections. This API can be used when there are
267 * multiple sections with the same name.
276 * Number of entries in section on success, -1 otherwise
278 int rte_cfgfile_section_num_entries_by_index(struct rte_cfgfile *cfg,
283 * Get section entries as key-value pairs
285 * If multiple sections have the given name this function operates on the
293 * Pre-allocated array of at least max_entries entries where the section
294 * entries are stored as key-value pair after successful invocation
296 * Maximum number of section entries to be stored in entries array
298 * Number of entries populated on success, -1 otherwise
300 int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
301 const char *sectionname,
302 struct rte_cfgfile_entry *entries,
306 * Get section entries as key-value pairs
308 * The index of a section is the same as the index of its name in the
309 * result of rte_cfgfile_sections. This API can be used when there are
310 * multiple sections with the same name.
317 * Pre-allocated string of at least CFG_NAME_LEN characters where the
318 * section name is stored after successful invocation.
320 * Pre-allocated array of at least max_entries entries where the section
321 * entries are stored as key-value pair after successful invocation
323 * Maximum number of section entries to be stored in entries array
325 * Number of entries populated on success, -1 otherwise
327 int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
330 struct rte_cfgfile_entry *entries,
334 * Get value of the named entry in named config file section
336 * If multiple sections have the given name this function operates on the
346 * Entry value on success, NULL otherwise
348 const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
349 const char *sectionname,
350 const char *entryname);
353 * Check if given entry exists in named config file section
355 * If multiple sections have the given name this function operates on the
365 * TRUE (value different than 0) if entry exists, FALSE (value 0) otherwise
367 int rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname,
368 const char *entryname);
376 * 0 on success, -1 otherwise
378 int rte_cfgfile_close(struct rte_cfgfile *cfg);