1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
8 * Licensed under the Apache License, Version 2.0 (the License);
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * @file config-parser.h
24 * ini type config file parser
26 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
42 * Prototype for a parser for a specific configuration setting
44 typedef int (*ConfigParserCallback)(
54 * @brief A callback function of #config_parse_dir.
56 * @param path a parsing config file name
57 * @param data user data to be passed by #config_parse_dir.
59 typedef int (*ConfigParseFunc)(const char *path, void *data);
62 * Wraps information for parsing a specific configuration variable, to
63 * be stored in a simple array
65 typedef struct ConfigTableItem {
72 * Name of the variable
77 * Function that is called to parse the variable's value
79 ConfigParserCallback cb;
82 * Distinguish different variables passed to the same callback
87 * Where to store the variable's data
93 * @brief config parser function
95 * @param filename full path of config file
96 * @param table a table of #ConfigTableItem to parse
98 * @return 0 on success, -errno on failure.
100 int config_parse(const char *filename, void *table);
103 * @brief parse all regular config files in directory
105 * @param dir dir full path
106 * @param fp config parse function.
107 * @param data user data to be passed to config parser function
109 * @return 0 on success, -errno on failure.
111 int config_parse_dir(const char *dir, ConfigParseFunc fp, void *data);
115 * @brief A common int type rvalue parser.
117 * @param filename a parsing config file name
118 * @param line a parsing config file line
119 * @param section a parsing config file section
120 * @param lvalue a parsing config file left value
121 * @param ltype a parsing config file left value type. (not used.)
122 * @param rvalue a parsing config file rvalue
123 * @param data user data
125 * @return 0 on success, -errno on failure.
127 int config_parse_int(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
130 * @brief A common boolean type rvalue parser.
132 * @param filename a parsing config file name
133 * @param line a parsing config file line
134 * @param section a parsing config file section
135 * @param lvalue a parsing config file left value
136 * @param ltype a parsing config file left value type. (not used.)
137 * @param rvalue a parsing config file rvalue
138 * @param data user data
140 * @return 0 on success, -errno on failure.
142 int config_parse_bool(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
145 * @brief A common string type rvalue parser.
147 * @param filename a parsing config file name
148 * @param line a parsing config file line
149 * @param section a parsing config file section
150 * @param lvalue a parsing config file left value
151 * @param ltype a parsing config file left value type. (not used.)
152 * @param rvalue a parsing config file rvalue
153 * @param data user data
155 * @return 0 on success, -errno on failure.
157 int config_parse_string(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);
160 * @brief A common byte type rvalue parser.
162 * @param filename a parsing config file name
163 * @param line a parsing config file line
164 * @param section a parsing config file section
165 * @param lvalue a parsing config file left value
166 * @param ltype a parsing config file left value type. (not used.)
167 * @param rvalue a parsing config file rvalue
168 * @param data user data
170 * @return 0 on success, -errno on failure.
172 int config_parse_bytes(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data);