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,
86 /** Defines the default comment character used for parsing config files. */
87 #define CFG_DEFAULT_COMMENT_CHARACTER ';'
97 * Handle to configuration file on success, NULL otherwise
99 struct rte_cfgfile *rte_cfgfile_load(const char *filename, int flags);
102 * Open config file with specified optional parameters.
109 * Additional configuration attributes. Must be configured with desired
110 * values prior to invoking this API.
112 * Handle to configuration file on success, NULL otherwise
114 struct rte_cfgfile *rte_cfgfile_load_with_params(const char *filename,
115 int flags, const struct rte_cfgfile_parameters *params);
118 * Get number of sections in config file
125 * Maximum section name length
129 int rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sec_name,
133 * Get name of all config file sections.
135 * Fills in the array sections with the name of all the sections in the file
136 * (up to the number of max_sections sections).
141 * Array containing section names after successful invocation. Each element
142 * of this array should be preallocated by the user with at least
143 * CFG_NAME_LEN characters.
144 * @param max_sections
145 * Maximum number of section names to be stored in sections array
147 * Number of populated sections names
149 int rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
153 * Check if given section exists in config file
160 * TRUE (value different than 0) if section exists, FALSE (value 0) otherwise
162 int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
165 * Get number of entries in given config file section
167 * If multiple sections have the given name this function operates on the
175 * Number of entries in section on success, -1 otherwise
177 int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
178 const char *sectionname);
181 * Get section entries as key-value pairs
183 * If multiple sections have the given name this function operates on the
191 * Pre-allocated array of at least max_entries entries where the section
192 * entries are stored as key-value pair after successful invocation
194 * Maximum number of section entries to be stored in entries array
196 * Number of entries populated on success, -1 otherwise
198 int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
199 const char *sectionname,
200 struct rte_cfgfile_entry *entries,
204 * Get section entries as key-value pairs
206 * The index of a section is the same as the index of its name in the
207 * result of rte_cfgfile_sections. This API can be used when there are
208 * multiple sections with the same name.
215 * Pre-allocated string of at least CFG_NAME_LEN characters where the
216 * section name is stored after successful invocation.
218 * Pre-allocated array of at least max_entries entries where the section
219 * entries are stored as key-value pair after successful invocation
221 * Maximum number of section entries to be stored in entries array
223 * Number of entries populated on success, -1 otherwise
225 int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
228 struct rte_cfgfile_entry *entries,
232 * Get value of the named entry in named config file section
234 * If multiple sections have the given name this function operates on the
244 * Entry value on success, NULL otherwise
246 const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
247 const char *sectionname,
248 const char *entryname);
251 * Check if given entry exists in named config file section
253 * If multiple sections have the given name this function operates on the
263 * TRUE (value different than 0) if entry exists, FALSE (value 0) otherwise
265 int rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname,
266 const char *entryname);
274 * 0 on success, -1 otherwise
276 int rte_cfgfile_close(struct rte_cfgfile *cfg);