00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef INI_CONFIGOBJ_H
00025 #define INI_CONFIGOBJ_H
00026
00027 #include <sys/types.h>
00028 #include <sys/stat.h>
00029 #include <unistd.h>
00030 #include <limits.h>
00031 #include <stdio.h>
00032 #include "simplebuffer.h"
00033 #include "ini_valueobj.h"
00034
00141 enum ERR_LEVEL {
00142 INI_STOP_ON_ANY = 0,
00143 INI_STOP_ON_NONE = 1,
00144 INI_STOP_ON_ERROR = 2
00145 };
00146
00159 enum ERR_PARSE {
00160 ERR_LONGDATA = 1,
00161 ERR_NOCLOSESEC,
00163 ERR_NOSECTION,
00164 ERR_SECTIONLONG,
00165 ERR_NOEQUAL,
00166 ERR_NOKEY,
00167 ERR_LONGKEY,
00168 ERR_READ,
00169 ERR_SPACE,
00171 ERR_DUPKEY,
00172 ERR_DUPKEYSEC,
00174 ERR_DUPSECTION,
00175 ERR_SPECIAL,
00176 ERR_TAB,
00178 ERR_BADCOMMENT,
00179 ERR_MAXPARSE = ERR_BADCOMMENT
00180 };
00181
00195 #define INI_META_NONE 0
00196
00197 #define INI_META_STATS 1
00198
00216 #define INI_ACCESS_CHECK_MODE 0x00000001
00217
00224 #define INI_ACCESS_CHECK_UID 0x00000002
00225
00232 #define INI_ACCESS_CHECK_GID 0x00000004
00233
00256 #define INI_MV1S_OVERWRITE 0x0000
00257
00258 #define INI_MV1S_ERROR 0x0001
00259
00260 #define INI_MV1S_PRESERVE 0x0002
00261
00262 #define INI_MV1S_ALLOW 0x0003
00263
00264 #define INI_MV1S_DETECT 0x0004
00265
00283 #define INI_MV2S_OVERWRITE 0x0000
00284
00285 #define INI_MV2S_ERROR 0x0010
00286
00287 #define INI_MV2S_PRESERVE 0x0020
00288
00289 #define INI_MV2S_ALLOW 0x0030
00290
00291 #define INI_MV2S_DETECT 0x0040
00292
00309 #define INI_MS_MERGE 0x0000
00310
00311 #define INI_MS_ERROR 0x0100
00312
00313 #define INI_MS_OVERWRITE 0x0200
00314
00315 #define INI_MS_PRESERVE 0x0300
00316
00317 #define INI_MS_DETECT 0x0400
00318
00336 #define INI_PARSE_NOWRAP 0x0001
00337
00338 #define INI_PARSE_NOSPACE 0x0002
00339
00340 #define INI_PARSE_NOTAB 0x0004
00341
00342 #define INI_PARSE_NO_C_COMMENTS 0x0008
00343
00344 #define INI_PARSE_IGNORE_NON_KVP 0x0010
00345
00369 enum INI_GET {
00370 INI_GET_FIRST_VALUE,
00371 INI_GET_NEXT_VALUE,
00372 INI_GET_LAST_VALUE
00373 };
00374
00385 #define INI_DEFAULT_SECTION "default"
00386
00393 struct ini_cfgobj;
00394 struct ini_cfgfile;
00395
00399 struct ini_parse_error;
00400
00401
00435 int ini_config_create(struct ini_cfgobj **ini_config);
00436
00445 void ini_config_destroy(struct ini_cfgobj *ini_config);
00446
00456 void ini_config_clean_state(struct ini_cfgobj *ini_config);
00457
00483 int ini_config_file_open(const char *filename,
00484 uint32_t metadata_flags,
00485 struct ini_cfgfile **file_ctx);
00486
00508 int ini_config_file_from_mem(void *data_buf,
00509 uint32_t data_len,
00510 struct ini_cfgfile **file_ctx);
00511
00521 void ini_config_file_close(struct ini_cfgfile *file_ctx);
00522
00523
00538 int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
00539 struct ini_cfgfile **file_ctx_out);
00540
00541
00550 void ini_config_file_destroy(struct ini_cfgfile *file_ctx);
00551
00563 unsigned ini_config_error_count(struct ini_cfgobj *ini_config);
00564
00581 int ini_config_get_errors(struct ini_cfgobj *ini_config,
00582 char ***errors);
00583
00593 void ini_config_free_errors(char **errors);
00594
00606 void ini_config_print_errors(FILE *file, char **error_list);
00607
00618 const char *ini_config_get_filename(struct ini_cfgfile *file_ctx);
00619
00631 const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx);
00632
00633
00634
00643 void ini_config_file_print(struct ini_cfgfile *file_ctx);
00644
00669 int ini_config_access_check(struct ini_cfgfile *file_ctx,
00670 uint32_t flags,
00671 uid_t uid,
00672 gid_t gid,
00673 mode_t mode,
00674 mode_t mask);
00675
00707 int ini_config_changed(struct ini_cfgfile *file_ctx1,
00708 struct ini_cfgfile *file_ctx2,
00709 int *changed);
00710
00733 int ini_config_parse(struct ini_cfgfile *file_ctx,
00734 int error_level,
00735 uint32_t collision_flags,
00736 uint32_t parse_flags,
00737 struct ini_cfgobj *ini_config);
00738
00752 int ini_config_copy(struct ini_cfgobj *ini_config,
00753 struct ini_cfgobj **ini_new);
00754
00780 int ini_config_merge(struct ini_cfgobj *first,
00781 struct ini_cfgobj *second,
00782 uint32_t collision_flags,
00783 struct ini_cfgobj **result);
00784
00798 int ini_config_set_wrap(struct ini_cfgobj *ini_config,
00799 uint32_t boundary);
00800
00815 int ini_config_serialize(struct ini_cfgobj *ini_config,
00816 struct simplebuffer *sbobj);
00817
00818
00819
00820
00821
00822
00859 char **ini_get_section_list(struct ini_cfgobj *ini_config,
00860 int *size,
00861 int *error);
00862
00872 void ini_free_section_list(char **section_list);
00873
00894 char **ini_get_attribute_list(struct ini_cfgobj *ini_config,
00895 const char *section,
00896 int *size,
00897 int *error);
00898
00908 void ini_free_attribute_list(char **attr_list);
00909
00951 int ini_get_config_valueobj(const char *section,
00952 const char *name,
00953 struct ini_cfgobj *ini_config,
00954 int mode,
00955 struct value_obj **vo);
00956
00957
00958
00999 int ini_get_int_config_value(struct value_obj *vo,
01000 int strict,
01001 int def,
01002 int *error);
01003
01045 unsigned ini_get_unsigned_config_value(struct value_obj *vo,
01046 int strict,
01047 unsigned def,
01048 int *error);
01049
01091 long ini_get_long_config_value(struct value_obj *vo,
01092 int strict,
01093 long def,
01094 int *error);
01095
01137 unsigned long ini_get_ulong_config_value(struct value_obj *vo,
01138 int strict,
01139 unsigned long def,
01140 int *error);
01141
01142
01183 int32_t ini_get_int32_config_value(struct value_obj *vo,
01184 int strict,
01185 int32_t def,
01186 int *error);
01187
01228 uint32_t ini_get_uint32_config_value(struct value_obj *vo,
01229 int strict,
01230 uint32_t def,
01231 int *error);
01232
01273 int64_t ini_get_int64_config_value(struct value_obj *vo,
01274 int strict,
01275 int64_t def,
01276 int *error);
01277
01318 uint64_t ini_get_uint64_config_value(struct value_obj *vo,
01319 int strict,
01320 uint64_t def,
01321 int *error);
01322
01361 double ini_get_double_config_value(struct value_obj *vo,
01362 int strict,
01363 double def,
01364 int *error);
01365
01399 unsigned char ini_get_bool_config_value(struct value_obj *vo,
01400 unsigned char def,
01401 int *error);
01402
01427 char *ini_get_string_config_value(struct value_obj *vo,
01428 int *error);
01451 const char *ini_get_const_string_config_value(struct value_obj *vo,
01452 int *error);
01453
01503 char *ini_get_bin_config_value(struct value_obj *vo,
01504 int *length,
01505 int *error);
01506
01515 void ini_free_bin_config_value(char *bin);
01516
01571 char **ini_get_string_config_array(struct value_obj *vo,
01572 const char *sep,
01573 int *size,
01574 int *error);
01575
01630 char **ini_get_raw_string_config_array(struct value_obj *vo,
01631 const char *sep,
01632 int *size,
01633 int *error);
01634
01677 long *ini_get_long_config_array(struct value_obj *vo,
01678 int *size,
01679 int *error);
01680
01722 double *ini_get_double_config_array(struct value_obj *vo,
01723 int *size,
01724 int *error);
01725
01735 void ini_free_string_config_array(char **str_config);
01736
01745 void ini_free_long_config_array(long *array);
01754 void ini_free_double_config_array(double *array);
01755
01760 #endif