cfgfile: increase entry name and value sizes
[dpdk.git] / lib / librte_cfgfile / rte_cfgfile.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #ifndef __INCLUDE_RTE_CFGFILE_H__
35 #define __INCLUDE_RTE_CFGFILE_H__
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /**
42 * @file
43 * RTE Configuration File
44 *
45 * This library allows reading application defined parameters from standard
46 * format configuration file.
47 *
48 ***/
49
50 #ifndef CFG_NAME_LEN
51 #define CFG_NAME_LEN 64
52 #endif
53
54 #ifndef CFG_VALUE_LEN
55 #define CFG_VALUE_LEN 256
56 #endif
57
58 /** Configuration file */
59 struct rte_cfgfile;
60
61 /** Configuration file entry */
62 struct rte_cfgfile_entry {
63         char name[CFG_NAME_LEN]; /**< Name */
64         char value[CFG_VALUE_LEN]; /**< Value */
65 };
66
67 /**
68 * Open config file
69 *
70 * @param filename
71 *   Config file name
72 * @param flags
73 *   Config file flags, Reserved for future use. Must be set to 0.
74 * @return
75 *   Handle to configuration file
76 */
77 struct rte_cfgfile *rte_cfgfile_load(const char *filename, int flags);
78
79 /**
80 * Get number of sections in config file
81 *
82 * @param cfg
83 *   Config file
84 * @param sec_name
85 *   Section name
86 * @param length
87 *   Maximum section name length
88 * @return
89 *   0 on success, error code otherwise
90 */
91 int rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sec_name,
92         size_t length);
93
94 /**
95 * Get name of all config file sections.
96 *
97 * Fills in the array sections with the name of all the sections in the file
98 * (up to the number of max_sections sections).
99 *
100 * @param cfg
101 *   Config file
102 * @param sections
103 *   Array containing section names after successful invocation. Each elemen
104 *   of this array should be preallocated by the user with at least
105 *   CFG_NAME_LEN characters.
106 * @param max_sections
107 *   Maximum number of section names to be stored in sections array
108 * @return
109 *   0 on success, error code otherwise
110 */
111 int rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
112         int max_sections);
113
114 /**
115 * Check if given section exists in config file
116 *
117 * @param cfg
118 *   Config file
119 * @param sectionname
120 *   Section name
121 * @return
122 *   TRUE (value different than 0) if section exists, FALSE (value 0) otherwise
123 */
124 int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname);
125
126 /**
127 * Get number of entries in given config file section
128 *
129 * @param cfg
130 *   Config file
131 * @param sectionname
132 *   Section name
133 * @return
134 *   Number of entries in section
135 */
136 int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
137         const char *sectionname);
138
139 /** Get section entries as key-value pairs
140 *
141 * @param cfg
142 *   Config file
143 * @param sectionname
144 *   Section name
145 * @param entries
146 *   Pre-allocated array of at least max_entries entries where the section
147 *   entries are stored as key-value pair after successful invocation
148 * @param max_entries
149 *   Maximum number of section entries to be stored in entries array
150 * @return
151 *   0 on success, error code otherwise
152 */
153 int rte_cfgfile_section_entries(struct rte_cfgfile *cfg,
154         const char *sectionname,
155         struct rte_cfgfile_entry *entries,
156         int max_entries);
157
158 /** Get value of the named entry in named config file section
159 *
160 * @param cfg
161 *   Config file
162 * @param sectionname
163 *   Section name
164 * @param entryname
165 *   Entry name
166 * @return
167 *   Entry value
168 */
169 const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg,
170         const char *sectionname,
171         const char *entryname);
172
173 /** Check if given entry exists in named config file section
174 *
175 * @param cfg
176 *   Config file
177 * @param sectionname
178 *   Section name
179 * @param entryname
180 *   Entry name
181 * @return
182 *   TRUE (value different than 0) if entry exists, FALSE (value 0) otherwise
183 */
184 int rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname,
185         const char *entryname);
186
187 /** Close config file
188 *
189 * @param cfg
190 *   Config file
191 * @return
192 *   0 on success, error code otherwise
193 */
194 int rte_cfgfile_close(struct rte_cfgfile *cfg);
195
196 #ifdef __cplusplus
197 }
198 #endif
199
200 #endif