libini_config 0.5.0

ini_configobj.h

00001 /*
00002     INI LIBRARY
00003 
00004     Header file for the ini configuration interface.
00005     THIS IS THE PREFERRED INTERFACE TO USE.
00006 
00007     Copyright (C) Dmitri Pal <dpal@redhat.com> 2010 - 2012
00008 
00009     INI Library is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     INI Library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with INI Library.  If not, see <http://www.gnu.org/licenses/>.
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 index_utf_t {
00142     INDEX_UTF32BE = 0,  
00143     INDEX_UTF32LE = 1,  
00144     INDEX_UTF16BE = 2,  
00145     INDEX_UTF16LE = 3,  
00146     INDEX_UTF8 = 4,     
00147     INDEX_UTF8NOBOM = 5 
00148 };
00149 
00164 enum ERR_LEVEL {
00165     INI_STOP_ON_ANY   = 0, 
00166     INI_STOP_ON_NONE  = 1, 
00167     INI_STOP_ON_ERROR = 2  
00168 };
00169 
00182 enum ERR_PARSE {
00183     ERR_LONGDATA = 1, 
00184     ERR_NOCLOSESEC,   
00186     ERR_NOSECTION,    
00187     ERR_SECTIONLONG,  
00188     ERR_NOEQUAL,      
00189     ERR_NOKEY,        
00190     ERR_LONGKEY,      
00191     ERR_READ,         
00192     ERR_SPACE,        
00194     ERR_DUPKEY,       
00195     ERR_DUPKEYSEC,    
00197     ERR_DUPSECTION,   
00198     ERR_SPECIAL,      
00199     ERR_TAB,          
00201     ERR_BADCOMMENT,   
00202     ERR_MAXPARSE = ERR_BADCOMMENT 
00203 };
00204 
00218 #define INI_META_NONE     0
00219 
00220 #define INI_META_STATS    1
00221 
00239 #define INI_ACCESS_CHECK_MODE   0x00000001
00240 
00247 #define INI_ACCESS_CHECK_UID   0x00000002
00248 
00255 #define INI_ACCESS_CHECK_GID   0x00000004
00256 
00279 #define INI_MV1S_OVERWRITE 0x0000
00280 
00281 #define INI_MV1S_ERROR     0x0001
00282 
00283 #define INI_MV1S_PRESERVE  0x0002
00284 
00285 #define INI_MV1S_ALLOW     0x0003
00286 
00287 #define INI_MV1S_DETECT    0x0004
00288 
00306 #define INI_MV2S_OVERWRITE 0x0000
00307 
00308 #define INI_MV2S_ERROR     0x0010
00309 
00310 #define INI_MV2S_PRESERVE  0x0020
00311 
00312 #define INI_MV2S_ALLOW     0x0030
00313 
00314 #define INI_MV2S_DETECT    0x0040
00315 
00332 #define INI_MS_MERGE     0x0000
00333 
00334 #define INI_MS_ERROR     0x0100
00335 
00336 #define INI_MS_OVERWRITE 0x0200
00337 
00338 #define INI_MS_PRESERVE  0x0300
00339 
00340 #define INI_MS_DETECT    0x0400
00341 
00359 #define INI_PARSE_NOWRAP           0x0001
00360 
00361 #define INI_PARSE_NOSPACE          0x0002
00362 
00363 #define INI_PARSE_NOTAB            0x0004
00364 
00365 #define INI_PARSE_NO_C_COMMENTS    0x0008
00366 
00390 enum INI_GET {
00391     INI_GET_FIRST_VALUE, 
00392     INI_GET_NEXT_VALUE,  
00393     INI_GET_LAST_VALUE   
00394 };
00395 
00410 struct access_check {
00411     uint32_t flags; 
00417     uid_t uid;      
00418     gid_t gid;      
00419     mode_t mode;    
00420     mode_t mask;    
00425 };
00426 
00428 enum augmode {
00429     INI_AUG_ANY   = 0, 
00430     INI_AUG_ADD   = 1, 
00431     INI_AUG_OVER  = 2  
00432 };
00433 
00444 #define INI_DEFAULT_SECTION "default"
00445 
00452 struct ini_cfgobj;
00453 struct ini_cfgfile;
00454 
00458 struct ini_parse_error;
00459 
00460 
00492 int ini_config_create(struct ini_cfgobj **ini_config);
00493 
00502 void ini_config_destroy(struct ini_cfgobj *ini_config);
00503 
00513 void ini_config_clean_state(struct ini_cfgobj *ini_config);
00514 
00540 int ini_config_file_open(const char *filename,
00541                          uint32_t metadata_flags,
00542                          struct ini_cfgfile **file_ctx);
00543 
00565 int ini_config_file_from_mem(void *data_buf,
00566                              uint32_t data_len,
00567                              struct ini_cfgfile **file_ctx);
00568 
00578 void ini_config_file_close(struct ini_cfgfile *file_ctx);
00579 
00580 
00595 int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
00596                            struct ini_cfgfile **file_ctx_out);
00597 
00598 
00607 void ini_config_file_destroy(struct ini_cfgfile *file_ctx);
00608 
00658 int ini_config_file_backup(struct ini_cfgfile *file_ctx,
00659                            const char *backup_dir,
00660                            const char *backup_tpl,
00661                            struct access_check *backup_access,
00662                            unsigned max_num);
00663 
00683 int ini_config_change_access(struct ini_cfgfile *file_ctx,
00684                              struct access_check *new_access);
00685 
00694 int ini_config_save(struct ini_cfgfile *file_ctx,
00695                     struct access_check *new_access,
00696                     struct ini_cfgobj *ini_config);
00697 
00698 
00699 /* Save configuration in a file using existing context but with a new name */
00731 int ini_config_save_as(struct ini_cfgfile *file_ctx,
00732                        const char *filename,
00733                        struct access_check *new_access,
00734                        struct ini_cfgobj *ini_config);
00735 
00736 
00737 
00749 enum index_utf_t ini_config_get_bom(struct ini_cfgfile *file_ctx);
00750 
00766 int ini_config_set_bom(struct ini_cfgfile *file_ctx, enum index_utf_t bom);
00767 
00768 
00780 unsigned ini_config_error_count(struct ini_cfgobj *ini_config);
00781 
00798 int ini_config_get_errors(struct ini_cfgobj *ini_config,
00799                           char ***errors);
00800 
00810 void ini_config_free_errors(char **errors);
00811 
00823 void ini_config_print_errors(FILE *file, char **error_list);
00824 
00835 const char *ini_config_get_filename(struct ini_cfgfile *file_ctx);
00836 
00848 const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx);
00849 
00850 
00851 
00860 void ini_config_file_print(struct ini_cfgfile *file_ctx);
00861 
00886 int ini_config_access_check(struct ini_cfgfile *file_ctx,
00887                             uint32_t flags,
00888                             uid_t uid,
00889                             gid_t gid,
00890                             mode_t mode,
00891                             mode_t mask);
00892 
00924 int ini_config_changed(struct ini_cfgfile *file_ctx1,
00925                        struct ini_cfgfile *file_ctx2,
00926                        int *changed);
00927 
00950 int ini_config_parse(struct ini_cfgfile *file_ctx,
00951                      int error_level,
00952                      uint32_t collision_flags,
00953                      uint32_t parse_flags,
00954                      struct ini_cfgobj *ini_config);
00955 
00969 int ini_config_copy(struct ini_cfgobj *ini_config,
00970                     struct ini_cfgobj **ini_new);
00971 
00997 int ini_config_merge(struct ini_cfgobj *first,
00998                      struct ini_cfgobj *second,
00999                      uint32_t collision_flags,
01000                      struct ini_cfgobj **result);
01001 
01002 
01064 int ini_config_augment(struct ini_cfgobj *base_cfg,
01065                        const char *path,
01066                        const char *patterns[],
01067                        const char *sections[],
01068                        struct access_check *check_perm,
01069                        int error_level,
01070                        uint32_t collision_flags,
01071                        uint32_t parse_flags,
01072                        uint32_t merge_flags,
01073                        struct ini_cfgobj **result_cfg,
01074                        struct ref_array **error_list,
01075                        struct ref_array **success_list);
01076 
01090 int ini_config_set_wrap(struct ini_cfgobj *ini_config,
01091                         uint32_t boundary);
01092 
01107 int ini_config_serialize(struct ini_cfgobj *ini_config,
01108                          struct simplebuffer *sbobj);
01109 
01110 
01111 /* Functions that add, modify or delete sections and values in
01112  * the configuration object can be found in section \ref ini_mod.
01113  */
01114 
01151 char **ini_get_section_list(struct ini_cfgobj *ini_config,
01152                             int *size,
01153                             int *error);
01154 
01164 void ini_free_section_list(char **section_list);
01165 
01186 char **ini_get_attribute_list(struct ini_cfgobj *ini_config,
01187                               const char *section,
01188                               int *size,
01189                               int *error);
01190 
01200 void ini_free_attribute_list(char **attr_list);
01201 
01243 int ini_get_config_valueobj(const char *section,
01244                             const char *name,
01245                             struct ini_cfgobj *ini_config,
01246                             int mode,
01247                             struct value_obj **vo);
01248 
01249 
01250 
01291 int ini_get_int_config_value(struct value_obj *vo,
01292                              int strict,
01293                              int def,
01294                              int *error);
01295 
01337 unsigned ini_get_unsigned_config_value(struct value_obj *vo,
01338                                        int strict,
01339                                        unsigned def,
01340                                        int *error);
01341 
01383 long ini_get_long_config_value(struct value_obj *vo,
01384                                int strict,
01385                                long def,
01386                                int *error);
01387 
01429 unsigned long ini_get_ulong_config_value(struct value_obj *vo,
01430                                          int strict,
01431                                          unsigned long def,
01432                                          int *error);
01433 
01434 
01475 int32_t ini_get_int32_config_value(struct value_obj *vo,
01476                                    int strict,
01477                                    int32_t def,
01478                                    int *error);
01479 
01520 uint32_t ini_get_uint32_config_value(struct value_obj *vo,
01521                                      int strict,
01522                                      uint32_t def,
01523                                      int *error);
01524 
01565 int64_t ini_get_int64_config_value(struct value_obj *vo,
01566                                    int strict,
01567                                    int64_t def,
01568                                    int *error);
01569 
01610 uint64_t ini_get_uint64_config_value(struct value_obj *vo,
01611                                      int strict,
01612                                      uint64_t def,
01613                                      int *error);
01614 
01653 double ini_get_double_config_value(struct value_obj *vo,
01654                                    int strict,
01655                                    double def,
01656                                    int *error);
01657 
01691 unsigned char ini_get_bool_config_value(struct value_obj *vo,
01692                                         unsigned char def,
01693                                         int *error);
01694 
01719 char *ini_get_string_config_value(struct value_obj *vo,
01720                                   int *error);
01743 const char *ini_get_const_string_config_value(struct value_obj *vo,
01744                                               int *error);
01745 
01795 char *ini_get_bin_config_value(struct value_obj *vo,
01796                                int *length,
01797                                int *error);
01798 
01807 void ini_free_bin_config_value(char *bin);
01808 
01863 char **ini_get_string_config_array(struct value_obj *vo,
01864                                    const char *sep,
01865                                    int *size,
01866                                    int *error);
01867 
01922 char **ini_get_raw_string_config_array(struct value_obj *vo,
01923                                        const char *sep,
01924                                        int *size,
01925                                        int *error);
01926 
01969 long *ini_get_long_config_array(struct value_obj *vo,
01970                                 int *size,
01971                                 int *error);
01972 
02014 double *ini_get_double_config_array(struct value_obj *vo,
02015                                     int *size,
02016                                     int *error);
02017 
02027 void ini_free_string_config_array(char **str_config);
02028 
02037 void ini_free_long_config_array(long *array);
02046 void ini_free_double_config_array(double *array);
02047 
02052 #endif
 All Data Structures Variables