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
00367 enum INI_GET {
00368 INI_GET_FIRST_VALUE,
00369 INI_GET_NEXT_VALUE,
00370 INI_GET_LAST_VALUE
00371 };
00372
00383 #define INI_DEFAULT_SECTION "default"
00384
00391 struct ini_cfgobj;
00392 struct ini_cfgfile;
00393
00397 struct ini_parse_error;
00398
00399
00433 int ini_config_create(struct ini_cfgobj **ini_config);
00434
00443 void ini_config_destroy(struct ini_cfgobj *ini_config);
00444
00454 void ini_config_clean_state(struct ini_cfgobj *ini_config);
00455
00481 int ini_config_file_open(const char *filename,
00482 uint32_t metadata_flags,
00483 struct ini_cfgfile **file_ctx);
00484
00506 int ini_config_file_from_mem(void *data_buf,
00507 uint32_t data_len,
00508 struct ini_cfgfile **file_ctx);
00509
00519 void ini_config_file_close(struct ini_cfgfile *file_ctx);
00520
00521
00536 int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
00537 struct ini_cfgfile **file_ctx_out);
00538
00539
00548 void ini_config_file_destroy(struct ini_cfgfile *file_ctx);
00549
00561 unsigned ini_config_error_count(struct ini_cfgobj *ini_config);
00562
00579 int ini_config_get_errors(struct ini_cfgobj *ini_config,
00580 char ***errors);
00581
00591 void ini_config_free_errors(char **errors);
00592
00604 void ini_config_print_errors(FILE *file, char **error_list);
00605
00616 const char *ini_config_get_filename(struct ini_cfgfile *file_ctx);
00617
00629 const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx);
00630
00631
00632
00641 void ini_config_file_print(struct ini_cfgfile *file_ctx);
00642
00667 int ini_config_access_check(struct ini_cfgfile *file_ctx,
00668 uint32_t flags,
00669 uid_t uid,
00670 gid_t gid,
00671 mode_t mode,
00672 mode_t mask);
00673
00705 int ini_config_changed(struct ini_cfgfile *file_ctx1,
00706 struct ini_cfgfile *file_ctx2,
00707 int *changed);
00708
00731 int ini_config_parse(struct ini_cfgfile *file_ctx,
00732 int error_level,
00733 uint32_t collision_flags,
00734 uint32_t parse_flags,
00735 struct ini_cfgobj *ini_config);
00736
00750 int ini_config_copy(struct ini_cfgobj *ini_config,
00751 struct ini_cfgobj **ini_new);
00752
00778 int ini_config_merge(struct ini_cfgobj *first,
00779 struct ini_cfgobj *second,
00780 uint32_t collision_flags,
00781 struct ini_cfgobj **result);
00782
00796 int ini_config_set_wrap(struct ini_cfgobj *ini_config,
00797 uint32_t boundary);
00798
00813 int ini_config_serialize(struct ini_cfgobj *ini_config,
00814 struct simplebuffer *sbobj);
00815
00816
00817
00818
00819
00820
00857 char **ini_get_section_list(struct ini_cfgobj *ini_config,
00858 int *size,
00859 int *error);
00860
00870 void ini_free_section_list(char **section_list);
00871
00892 char **ini_get_attribute_list(struct ini_cfgobj *ini_config,
00893 const char *section,
00894 int *size,
00895 int *error);
00896
00906 void ini_free_attribute_list(char **attr_list);
00907
00949 int ini_get_config_valueobj(const char *section,
00950 const char *name,
00951 struct ini_cfgobj *ini_config,
00952 int mode,
00953 struct value_obj **vo);
00954
00955
00956
00997 int ini_get_int_config_value(struct value_obj *vo,
00998 int strict,
00999 int def,
01000 int *error);
01001
01043 unsigned ini_get_unsigned_config_value(struct value_obj *vo,
01044 int strict,
01045 unsigned def,
01046 int *error);
01047
01089 long ini_get_long_config_value(struct value_obj *vo,
01090 int strict,
01091 long def,
01092 int *error);
01093
01135 unsigned long ini_get_ulong_config_value(struct value_obj *vo,
01136 int strict,
01137 unsigned long def,
01138 int *error);
01139
01140
01181 int32_t ini_get_int32_config_value(struct value_obj *vo,
01182 int strict,
01183 int32_t def,
01184 int *error);
01185
01226 uint32_t ini_get_uint32_config_value(struct value_obj *vo,
01227 int strict,
01228 uint32_t def,
01229 int *error);
01230
01271 int64_t ini_get_int64_config_value(struct value_obj *vo,
01272 int strict,
01273 int64_t def,
01274 int *error);
01275
01316 uint64_t ini_get_uint64_config_value(struct value_obj *vo,
01317 int strict,
01318 uint64_t def,
01319 int *error);
01320
01359 double ini_get_double_config_value(struct value_obj *vo,
01360 int strict,
01361 double def,
01362 int *error);
01363
01397 unsigned char ini_get_bool_config_value(struct value_obj *vo,
01398 unsigned char def,
01399 int *error);
01400
01425 char *ini_get_string_config_value(struct value_obj *vo,
01426 int *error);
01449 const char *ini_get_const_string_config_value(struct value_obj *vo,
01450 int *error);
01451
01501 char *ini_get_bin_config_value(struct value_obj *vo,
01502 int *length,
01503 int *error);
01504
01513 void ini_free_bin_config_value(char *bin);
01514
01569 char **ini_get_string_config_array(struct value_obj *vo,
01570 const char *sep,
01571 int *size,
01572 int *error);
01573
01628 char **ini_get_raw_string_config_array(struct value_obj *vo,
01629 const char *sep,
01630 int *size,
01631 int *error);
01632
01675 long *ini_get_long_config_array(struct value_obj *vo,
01676 int *size,
01677 int *error);
01678
01720 double *ini_get_double_config_array(struct value_obj *vo,
01721 int *size,
01722 int *error);
01723
01733 void ini_free_string_config_array(char **str_config);
01734
01743 void ini_free_long_config_array(long *array);
01752 void ini_free_double_config_array(double *array);
01753
01758 #endif