libini_config  0.2.91
 All Data Structures Functions Groups Pages
ini_configobj.h
1 /*
2  INI LIBRARY
3 
4  Header file for the ini collection object.
5 
6  Copyright (C) Dmitri Pal <dpal@redhat.com> 2010
7 
8  INI Library is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  INI Library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with INI Library. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #ifndef INI_CONFIGOBJ_H
23 #define INI_CONFIGOBJ_H
24 
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <unistd.h>
28 #include <limits.h>
29 #include <stdio.h>
30 #include "simplebuffer.h"
31 
32 
42 #define INI_STOP_ON_ANY 0
43 
44 #define INI_STOP_ON_NONE 1
45 
46 #define INI_STOP_ON_ERROR 2
47 
58 #define ERR_LONGDATA 1
59 
60 #define ERR_NOCLOSESEC 2
61 
62 #define ERR_NOSECTION 3
63 
64 #define ERR_SECTIONLONG 4
65 
66 #define ERR_NOEQUAL 5
67 
68 #define ERR_NOKEY 6
69 
70 #define ERR_LONGKEY 7
71 
72 #define ERR_READ 8
73 
74 #define ERR_SPACE 9
75 
76 #define ERR_DUPKEY 10
77 
78 #define ERR_DUPKEYSEC 11
79 
80 #define ERR_DUPSECTION 12
81 
83 #define ERR_MAXPARSE ERR_DUPSECTION
84 
98 #define INI_META_NONE 0
99 
100 #define INI_META_STATS 1
101 
119 #define INI_ACCESS_CHECK_MODE 0x00000001
120 
127 #define INI_ACCESS_CHECK_UID 0x00000002
128 
135 #define INI_ACCESS_CHECK_GID 0x00000004
136 
159 #define INI_MV1S_OVERWRITE 0x0000
160 
161 #define INI_MV1S_ERROR 0x0001
162 
163 #define INI_MV1S_PRESERVE 0x0002
164 
165 #define INI_MV1S_ALLOW 0x0003
166 
167 #define INI_MV1S_DETECT 0x0004
168 
186 #define INI_MV2S_OVERWRITE 0x0000
187 
188 #define INI_MV2S_ERROR 0x0010
189 
190 #define INI_MV2S_PRESERVE 0x0020
191 
192 #define INI_MV2S_ALLOW 0x0030
193 
194 #define INI_MV2S_DETECT 0x0040
195 
212 #define INI_MS_MERGE 0x0000
213 
214 #define INI_MS_ERROR 0x0100
215 
216 #define INI_MS_OVERWRITE 0x0200
217 
218 #define INI_MS_PRESERVE 0x0300
219 
220 #define INI_MS_ALLOW 0x0400
221 
222 #define INI_MS_DETECT 0x0500
223 
238 struct ini_cfgobj;
239 struct ini_cfgfile;
240 
244 struct ini_parse_error;
245 
246 
252 /********************************************************************/
253 /* THIS IS A BEGINNING OF THE THE NEW CONFIG OBJECT INTERFACE - TBD */
254 /* It will be moved to the ini_config.h when it is ready */
255 /********************************************************************/
256 
257 
258 /* Create a configuration object */
259 int ini_config_create(struct ini_cfgobj **ini_config);
260 
261 /* Destroy a configuration object */
262 void ini_config_destroy(struct ini_cfgobj *ini_config);
263 
264 /* Create a file object for parsing a config file */
265 int ini_config_file_open(const char *filename,
266  int error_level,
267  uint32_t collision_flags,
268  uint32_t metadata_flags,
269  struct ini_cfgfile **file_ctx);
270 
271 /* Create a file object from existing one */
272 int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
273  struct ini_cfgfile **file_ctx_out);
274 
275 /* Close file context */
276 void ini_config_file_close(struct ini_cfgfile *file_ctx);
277 
278 /* Close file context and destroy the object */
279 void ini_config_file_destroy(struct ini_cfgfile *file_ctx);
280 
281 /* How many errors do we have in the list ? */
282 unsigned ini_config_error_count(struct ini_cfgfile *file_ctx);
283 
284 /* Get the list of error strings */
285 int ini_config_get_errors(struct ini_cfgfile *file_ctx,
286  char ***errors);
287 
288 /* Get the fully resolved file name */
289 const char *ini_config_get_filename(struct ini_cfgfile *file_ctx);
290 
291 /* Free error strings */
292 void ini_config_free_errors(char **errors);
293 
294 /* Parse the file and create a config object */
295 int ini_config_parse(struct ini_cfgfile *file_ctx,
296  struct ini_cfgobj *ini_config);
297 
298 /* Copy configuration */
299 int ini_config_copy(struct ini_cfgobj *ini_config,
300  struct ini_cfgobj **ini_new);
301 
302 /* Function to print errors from the list */
303 void ini_config_print_errors(FILE *file, char **error_list);
304 
305 /* Merge two configurations together creating a new one */
306 int ini_config_merge(struct ini_cfgobj *first,
307  struct ini_cfgobj *second,
308  uint32_t collision_flags,
309  struct ini_cfgobj **result);
310 
311 /* Set the folding boundary for multiline values.
312  * Use before serializing and saving to a file if the
313  * default boundary of 80 characters does not work for you.
314  */
315 int ini_config_set_wrap(struct ini_cfgobj *ini_config,
316  uint32_t boundary);
317 
318 /* Serialize configuration object into provided buffer */
319 int ini_config_serialize(struct ini_cfgobj *ini_config,
320  struct simplebuffer *sbobj);
321 
322 /* Check access */
323 int ini_config_access_check(struct ini_cfgfile *file_ctx,
324  uint32_t flags,
325  uid_t uid,
326  gid_t gid,
327  mode_t mode,
328  mode_t mask);
329 
330 /* Determins if two file context different by comparing
331  * - time stamp
332  * - device ID
333  * - i-node
334  */
335 int ini_config_changed(struct ini_cfgfile *file_ctx1,
336  struct ini_cfgfile *file_ctx2,
337  int *changed);
338 
339 
340 /****************************************************/
341 /* VALUE MANAGEMENT */
342 /****************************************************/
343 
364 char **get_section_list(struct ini_cfgobj *ini_config,
365  int *size,
366  int *error);
367 
377 void free_section_list(char **section_list);
378 
399 char **get_attribute_list(struct ini_cfgobj *ini_config,
400  const char *section,
401  int *size,
402  int *error);
403 
413 void free_attribute_list(char **attr_list);
414 
415 
448 int get_int_config_value(struct ini_cfgobj *ini_config,
449  const char *section,
450  const char *name,
451  int strict,
452  int def,
453  int *value);
454 
455 /* Similar functions are below */
456 int get_long_config_value(struct ini_cfgobj *ini_config,
457  const char *section,
458  const char *name,
459  int strict,
460  long def,
461  long *value);
462 
463 int get_unsigned_config_value(struct ini_cfgobj *ini_config,
464  const char *section,
465  const char *name,
466  int strict,
467  unsigned def,
468  unsigned *value);
469 
470 int get_ulong_config_value(struct ini_cfgobj *ini_config,
471  const char *section,
472  const char *name,
473  int strict,
474  unsigned long def,
475  unsigned long *value);
476 
477 
478 
479 
480 
481 
482 
483 #ifdef THE_PART_I_HAVE_PROCESSED
484 
485 
486 
487 
488 
489 
530 int32_t get_int32_config_value(struct collection_item *item,
531  int strict,
532  int32_t def,
533  int *error);
534 
575 uint32_t get_uint32_config_value(struct collection_item *item,
576  int strict,
577  uint32_t def,
578  int *error);
579 
620 int64_t get_int64_config_value(struct collection_item *item,
621  int strict,
622  int64_t def,
623  int *error);
624 
665 uint64_t get_uint64_config_value(struct collection_item *item,
666  int strict,
667  uint64_t def,
668  int *error);
669 
708 double get_double_config_value(struct collection_item *item,
709  int strict,
710  double def,
711  int *error);
712 
746 unsigned char get_bool_config_value(struct collection_item *item,
747  unsigned char def,
748  int *error);
749 
773 char *get_string_config_value(struct collection_item *item,
774  int *error);
797 const char *get_const_string_config_value(struct collection_item *item,
798  int *error);
799 
849 char *get_bin_config_value(struct collection_item *item,
850  int *length,
851  int *error);
852 
861 void free_bin_config_value(char *bin);
862 
917 char **get_string_config_array(struct collection_item *item,
918  const char *sep,
919  int *size,
920  int *error);
921 
976 char **get_raw_string_config_array(struct collection_item *item,
977  const char *sep,
978  int *size,
979  int *error);
980 
1023 long *get_long_config_array(struct collection_item *item,
1024  int *size,
1025  int *error);
1026 
1068 double *get_double_config_array(struct collection_item *item,
1069  int *size,
1070  int *error);
1071 
1081 void free_string_config_array(char **str_config);
1082 
1091 void free_long_config_array(long *array);
1100 void free_double_config_array(double *array);
1101 
1102 #endif
1103 
1104 #endif