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 * Get number of sections in config file
131 * Maximum section name length
135 int rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sec_name,
139 * Get name of all config file sections.
141 * Fills in the array sections with the name of all the sections in the file
142 * (up to the number of max_sections sections).
147 * Array containing section names after successful invocation. Each element
148 * of this array should be preallocated by the user with at least
149 * CFG_NAME_LEN characters.
150 * @param max_sections
151 * Maximum number of section names to be stored in sections array
153 * Number of populated sections names
155 int rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
159 * Check if given section exists in config file
166 * TRUE (value different than 0) if section exists, FALSE (value 0) otherwise
168 int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
171 * Get number of entries in given config file section
173 * If multiple sections have the given name this function operates on the
181 * Number of entries in section on success, -1 otherwise
183 int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
184 const char *sectionname);
187 * Get section entries as key-value pairs
189 * If multiple sections have the given name this function operates on the
197 * Pre-allocated array of at least max_entries entries where the section
198 * entries are stored as key-value pair after successful invocation
200 * Maximum number of section entries to be stored in entries array
202 * Number of entries populated on success, -1 otherwise
204 int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
205 const char *sectionname,
206 struct rte_cfgfile_entry *entries,
210 * Get section entries as key-value pairs
212 * The index of a section is the same as the index of its name in the
213 * result of rte_cfgfile_sections. This API can be used when there are
214 * multiple sections with the same name.
221 * Pre-allocated string of at least CFG_NAME_LEN characters where the
222 * section name is stored after successful invocation.
224 * Pre-allocated array of at least max_entries entries where the section
225 * entries are stored as key-value pair after successful invocation
227 * Maximum number of section entries to be stored in entries array
229 * Number of entries populated on success, -1 otherwise
231 int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg,
234 struct rte_cfgfile_entry *entries,
238 * Get value of the named entry in named config file section
240 * If multiple sections have the given name this function operates on the
250 * Entry value on success, NULL otherwise
252 const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
253 const char *sectionname,
254 const char *entryname);
257 * Check if given entry exists in named config file section
259 * If multiple sections have the given name this function operates on the
269 * TRUE (value different than 0) if entry exists, FALSE (value 0) otherwise
271 int rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname,
272 const char *entryname);
280 * 0 on success, -1 otherwise
282 int rte_cfgfile_close(struct rte_cfgfile *cfg);