2 * Copyright (c) 2007, Anthony Minessale II
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of the original author; nor the names of any contributors
17 * may be used to endorse or promote products derived from this software
18 * 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 OWNER
25 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * @defgroup config Config File Parser
37 * This module implements a basic interface and file format parser
46 * \# lines that begin with \# are comments
59 #endif /* defined(__cplusplus) */
62 #define ESL_URL_SEPARATOR "://"
66 #define ESL_PATH_SEPARATOR "\\"
67 #ifndef ESL_CONFIG_DIR
68 #define ESL_CONFIG_DIR "c:\\openesl"
70 #define esl_is_file_path(file) (*(file +1) == ':' || *file == '/' || strstr(file, SWITCH_URL_SEPARATOR))
72 #define ESL_PATH_SEPARATOR "/"
73 #ifndef ESL_CONFIG_DIR
74 #define ESL_CONFIG_DIR "/etc/openesl"
76 #define esl_is_file_path(file) ((*file == '/') || strstr(file, SWITCH_URL_SEPARATOR))
80 \brief Evaluate the truthfullness of a string expression
81 \param expr a string expression
84 #define esl_true(expr)\
85 (expr && ( !strcasecmp(expr, "yes") ||\
86 !strcasecmp(expr, "on") ||\
87 !strcasecmp(expr, "true") ||\
88 !strcasecmp(expr, "enabled") ||\
89 !strcasecmp(expr, "active") ||\
90 !strcasecmp(expr, "allow") ||\
94 \brief Evaluate the falsefullness of a string expression
95 \param expr a string expression
98 #define esl_false(expr)\
99 (expr && ( !strcasecmp(expr, "no") ||\
100 !strcasecmp(expr, "off") ||\
101 !strcasecmp(expr, "false") ||\
102 !strcasecmp(expr, "disabled") ||\
103 !strcasecmp(expr, "inactive") ||\
104 !strcasecmp(expr, "disallow") ||\
105 !atoi(expr))) ? 1 : 0
107 typedef struct esl_config esl_config_t;
109 /*! \brief A simple file handle representing an open configuration file **/
111 /*! FILE stream buffer to the opened file */
113 /*! path to the file */
115 /*! current category */
117 /*! current section */
119 /*! buffer of current line being read */
121 /*! current line number in file */
123 /*! current category number in file */
125 /*! current section number in file */
132 \brief Open a configuration file
133 \param cfg (esl_config_t *) config handle to use
134 \param file_path path to the file
135 \return 1 (true) on success 0 (false) on failure
137 ESL_DECLARE(int) esl_config_open_file(esl_config_t * cfg, const char *file_path);
140 \brief Close a previously opened configuration file
141 \param cfg (esl_config_t *) config handle to use
143 ESL_DECLARE(void) esl_config_close_file(esl_config_t * cfg);
146 \brief Retrieve next name/value pair from configuration file
147 \param cfg (esl_config_t *) config handle to use
148 \param var pointer to aim at the new variable name
149 \param val pointer to aim at the new value
151 ESL_DECLARE(int) esl_config_next_pair(esl_config_t * cfg, char **var, char **val);
154 \brief Retrieve the CAS bits from a configuration string value
155 \param strvalue pointer to the configuration string value (expected to be in format whatever:xxxx)
156 \param outbits pointer to aim at the CAS bits
158 ESL_DECLARE(int) esl_config_get_cas_bits(char *strvalue, unsigned char *outbits);
165 #endif /* defined(__cplusplus) */
167 #endif /* defined(ESL_CONFIG_H) */
177 * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: