Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / source / iniparser / src / iniparser.h
blob98e8b33b78132a00128d7344d2cd61376c7bec04
2 /*-------------------------------------------------------------------------*/
3 /**
4 @file iniparser.h
5 @author N. Devillard
6 @date Mar 2000
7 @version $Revision: 1.20 $
8 @brief Parser for ini files.
9 */
10 /*--------------------------------------------------------------------------*/
13 $Id: iniparser.h,v 1.20 2005/08/19 17:23:21 ndevilla Exp $
14 $Author: ndevilla $
15 $Date: 2005/08/19 17:23:21 $
16 $Revision: 1.20 $
19 #ifndef _INIPARSER_H_
20 #define _INIPARSER_H_
22 /*---------------------------------------------------------------------------
23 Includes
24 ---------------------------------------------------------------------------*/
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
31 * The following #include is necessary on many Unixes but not Linux.
32 * It is not needed for Windows platforms.
33 * Uncomment it if needed.
35 /* #include <unistd.h> */
37 #include "dictionary.h"
39 /*-------------------------------------------------------------------------*/
40 /**
41 @brief Get number of sections in a dictionary
42 @param d Dictionary to examine
43 @return int Number of sections found in dictionary
45 This function returns the number of sections found in a dictionary.
46 The test to recognize sections is done on the string stored in the
47 dictionary: a section name is given as "section" whereas a key is
48 stored as "section:key", thus the test looks for entries that do not
49 contain a colon.
51 This clearly fails in the case a section name contains a colon, but
52 this should simply be avoided.
54 This function returns -1 in case of error.
56 /*--------------------------------------------------------------------------*/
58 int iniparser_getnsec(dictionary * d);
61 /*-------------------------------------------------------------------------*/
62 /**
63 @brief Get name for section n in a dictionary.
64 @param d Dictionary to examine
65 @param n Section number (from 0 to nsec-1).
66 @return Pointer to char string
68 This function locates the n-th section in a dictionary and returns
69 its name as a pointer to a string statically allocated inside the
70 dictionary. Do not free or modify the returned string!
72 This function returns NULL in case of error.
74 /*--------------------------------------------------------------------------*/
76 char * iniparser_getsecname(dictionary * d, int n);
79 /*-------------------------------------------------------------------------*/
80 /**
81 @brief Save a dictionary to a loadable ini file
82 @param d Dictionary to dump
83 @param f Opened file pointer to dump to
84 @return void
86 This function dumps a given dictionary into a loadable ini file.
87 It is Ok to specify @c stderr or @c stdout as output files.
89 /*--------------------------------------------------------------------------*/
91 void iniparser_dump_ini(dictionary * d, FILE * f);
93 /*-------------------------------------------------------------------------*/
94 /**
95 @brief Dump a dictionary to an opened file pointer.
96 @param d Dictionary to dump.
97 @param f Opened file pointer to dump to.
98 @return void
100 This function prints out the contents of a dictionary, one element by
101 line, onto the provided file pointer. It is OK to specify @c stderr
102 or @c stdout as output files. This function is meant for debugging
103 purposes mostly.
105 /*--------------------------------------------------------------------------*/
106 void iniparser_dump(dictionary * d, FILE * f);
108 /*-------------------------------------------------------------------------*/
110 @brief Get the string associated to a key, return NULL if not found
111 @param d Dictionary to search
112 @param key Key string to look for
113 @return pointer to statically allocated character string, or NULL.
115 This function queries a dictionary for a key. A key as read from an
116 ini file is given as "section:key". If the key cannot be found,
117 NULL is returned.
118 The returned char pointer is pointing to a string allocated in
119 the dictionary, do not free or modify it.
121 This function is only provided for backwards compatibility with
122 previous versions of iniparser. It is recommended to use
123 iniparser_getstring() instead.
125 /*--------------------------------------------------------------------------*/
126 char * iniparser_getstr(dictionary * d, char * key);
129 /*-------------------------------------------------------------------------*/
131 @brief Get the string associated to a key
132 @param d Dictionary to search
133 @param key Key string to look for
134 @param def Default value to return if key not found.
135 @return pointer to statically allocated character string
137 This function queries a dictionary for a key. A key as read from an
138 ini file is given as "section:key". If the key cannot be found,
139 the pointer passed as 'def' is returned.
140 The returned char pointer is pointing to a string allocated in
141 the dictionary, do not free or modify it.
143 /*--------------------------------------------------------------------------*/
144 char * iniparser_getstring(dictionary * d, char * key, char * def);
146 /*-------------------------------------------------------------------------*/
148 @brief Get the string associated to a key, convert to an int
149 @param d Dictionary to search
150 @param key Key string to look for
151 @param notfound Value to return in case of error
152 @return integer
154 This function queries a dictionary for a key. A key as read from an
155 ini file is given as "section:key". If the key cannot be found,
156 the notfound value is returned.
158 /*--------------------------------------------------------------------------*/
159 int iniparser_getint(dictionary * d, char * key, int notfound);
161 /*-------------------------------------------------------------------------*/
163 @brief Get the string associated to a key, convert to a double
164 @param d Dictionary to search
165 @param key Key string to look for
166 @param notfound Value to return in case of error
167 @return double
169 This function queries a dictionary for a key. A key as read from an
170 ini file is given as "section:key". If the key cannot be found,
171 the notfound value is returned.
173 /*--------------------------------------------------------------------------*/
174 double iniparser_getdouble(dictionary * d, char * key, double notfound);
176 /*-------------------------------------------------------------------------*/
178 @brief Get the string associated to a key, convert to a boolean
179 @param d Dictionary to search
180 @param key Key string to look for
181 @param notfound Value to return in case of error
182 @return integer
184 This function queries a dictionary for a key. A key as read from an
185 ini file is given as "section:key". If the key cannot be found,
186 the notfound value is returned.
188 A true boolean is found if one of the following is matched:
190 - A string starting with 'y'
191 - A string starting with 'Y'
192 - A string starting with 't'
193 - A string starting with 'T'
194 - A string starting with '1'
196 A false boolean is found if one of the following is matched:
198 - A string starting with 'n'
199 - A string starting with 'N'
200 - A string starting with 'f'
201 - A string starting with 'F'
202 - A string starting with '0'
204 The notfound value returned if no boolean is identified, does not
205 necessarily have to be 0 or 1.
207 /*--------------------------------------------------------------------------*/
208 int iniparser_getboolean(dictionary * d, char * key, int notfound);
211 /*-------------------------------------------------------------------------*/
213 @brief Set an entry in a dictionary.
214 @param ini Dictionary to modify.
215 @param entry Entry to modify (entry name)
216 @param val New value to associate to the entry.
217 @return int 0 if Ok, -1 otherwise.
219 If the given entry can be found in the dictionary, it is modified to
220 contain the provided value. If it cannot be found, -1 is returned.
221 It is Ok to set val to NULL.
223 /*--------------------------------------------------------------------------*/
225 int iniparser_setstr(dictionary * ini, char * entry, char * val);
227 /*-------------------------------------------------------------------------*/
229 @brief Delete an entry in a dictionary
230 @param ini Dictionary to modify
231 @param entry Entry to delete (entry name)
232 @return void
234 If the given entry can be found, it is deleted from the dictionary.
236 /*--------------------------------------------------------------------------*/
237 void iniparser_unset(dictionary * ini, char * entry);
239 /*-------------------------------------------------------------------------*/
241 @brief Finds out if a given entry exists in a dictionary
242 @param ini Dictionary to search
243 @param entry Name of the entry to look for
244 @return integer 1 if entry exists, 0 otherwise
246 Finds out if a given entry exists in the dictionary. Since sections
247 are stored as keys with NULL associated values, this is the only way
248 of querying for the presence of sections in a dictionary.
250 /*--------------------------------------------------------------------------*/
251 int iniparser_find_entry(dictionary * ini, char * entry) ;
253 /*-------------------------------------------------------------------------*/
255 @brief Parse an ini file and return an allocated dictionary object
256 @param ininame Name of the ini file to read.
257 @return Pointer to newly allocated dictionary
259 This is the parser for ini files. This function is called, providing
260 the name of the file to be read. It returns a dictionary object that
261 should not be accessed directly, but through accessor functions
262 instead.
264 The returned dictionary must be freed using iniparser_freedict().
266 /*--------------------------------------------------------------------------*/
267 dictionary * iniparser_load(char * ininame);
269 /*-------------------------------------------------------------------------*/
271 @brief Free all memory associated to an ini dictionary
272 @param d Dictionary to free
273 @return void
275 Free all memory associated to an ini dictionary.
276 It is mandatory to call this function before the dictionary object
277 gets out of the current context.
279 /*--------------------------------------------------------------------------*/
280 void iniparser_freedict(dictionary * d);
282 #endif