ini_config.h

00001 /*
00002     INI LIBRARY
00003 
00004     Header file for reading configuration from INI file
00005     and storing as a collection.
00006 
00007     Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
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 #ifndef INI_CONFIG_H
00024 #define INI_CONFIG_H
00025 
00026 #include <sys/types.h>
00027 #include <sys/stat.h>
00028 #include <unistd.h>
00029 #include <limits.h>
00030 #include <stdio.h>
00031 #include "collection.h"
00032 
00128 #define INI_DEFAULT_SECTION "default"
00129 
00153 #define COL_CLASS_INI_BASE        20000
00154 
00165 #define COL_CLASS_INI_CONFIG      COL_CLASS_INI_BASE + 0
00166 
00170 #define COL_CLASS_INI_SECTION     COL_CLASS_INI_BASE + 1
00171 
00176 #define COL_CLASS_INI_PERROR      COL_CLASS_INI_BASE + 2
00177 
00185 #define COL_CLASS_INI_PESET       COL_CLASS_INI_BASE + 3
00186 
00192 #define COL_CLASS_INI_META        COL_CLASS_INI_BASE + 4
00193 
00206 #define INI_STOP_ON_ANY     0
00207 
00208 #define INI_STOP_ON_NONE    1
00209 
00210 #define INI_STOP_ON_ERROR   2
00211 
00222 #define ERR_LONGDATA        1
00223 
00224 #define ERR_NOCLOSESEC      2
00225 
00226 #define ERR_NOSECTION       3
00227 
00228 #define ERR_SECTIONLONG     4
00229 
00230 #define ERR_NOEQUAL         5
00231 
00232 #define ERR_NOKEY           6
00233 
00234 #define ERR_LONGKEY         7
00235 
00236 #define ERR_READ            8
00237 
00238 #define ERR_SPACE           9
00239 
00241 #define ERR_MAXPARSE        ERR_SPACE
00242 
00254 #define ERR_MAXGRAMMAR      0
00255 
00266 #define ERR_MAXVALID        0
00267 
00268 
00286 #define INI_ACCESS_CHECK_MODE   0x00000001
00287 
00294 #define INI_ACCESS_CHECK_UID   0x00000002
00295 
00302 #define INI_ACCESS_CHECK_GID   0x00000004
00303 
00321 struct parse_error {
00322     unsigned line;
00323     int error;
00324 };
00325 
00326 
00381 #define INI_META_ACTION_NOPARSE     0x10000000
00382 
00393 #define INI_META_SEC_ACCESS     "ACCESS"
00394 
00399 #define INI_META_SEC_ACCESS_FLAG     0x00000001
00400 
00401 
00413 #define INI_META_KEY_UID     "uid"
00414 
00419 #define INI_META_KEY_GID     "gid"
00420 
00425 #define INI_META_KEY_PERM     "perm"
00426 
00431 #define INI_META_KEY_DEV     "dev"
00432 
00437 #define INI_META_KEY_INODE     "inode"
00438 
00443 #define INI_META_KEY_MODIFIED     "modified"
00444 
00449 #define INI_META_KEY_NAME     "name"
00450 
00458 #define INI_META_SEC_ERROR     "ERROR"
00459 
00464 #define INI_META_SEC_ERROR_FLAG     0x00000002
00465 
00466 
00480 #define INI_META_KEY_READ_ERROR     "read_error"
00481 
00482 
00507 const char *parsing_error_str(int parsing_error);
00508 
00509 
00535 int config_from_file(const char *application,
00536                      const char *config_filename,
00537                      struct collection_item **ini_config,
00538                      int error_level,
00539                      struct collection_item **error_list);
00540 
00567 int config_from_fd(const char *application,
00568                    int fd,
00569                    const char *config_source,
00570                    struct collection_item **ini_config,
00571                    int error_level,
00572                    struct collection_item **error_list);
00573 
00574 
00575 
00620 int config_from_file_with_metadata(
00621                      const char *application,
00622                      const char *config_filename,
00623                      struct collection_item **ini_config,
00624                      int error_level,
00625                      struct collection_item **error_list,
00626                      uint32_t metaflags,
00627                      struct collection_item **metadata);
00628 
00629 
00674 int config_from_fd_with_metadata(
00675                    const char *application,
00676                    int fd,
00677                    const char *config_source,
00678                    struct collection_item **ini_config,
00679                    int error_level,
00680                    struct collection_item **error_list,
00681                    uint32_t metaflags,
00682                    struct collection_item **metadata);
00683 
00684 
00713 int config_for_app(const char *application,
00714                    const char *config_file,
00715                    const char *config_dir,
00716                    struct collection_item **ini_config,
00717                    int error_level,
00718                    struct collection_item **error_set);
00719 
00769 int config_for_app_with_metadata(
00770                    const char *application,
00771                    const char *config_file,
00772                    const char *config_dir,
00773                    struct collection_item **ini_config,
00774                    int error_level,
00775                    struct collection_item **error_set,
00776                    uint32_t metaflags,
00777                    struct collection_item **meta_default,
00778                    struct collection_item **meta_appini);
00779 
00780 
00811 int config_access_check(struct collection_item *metadata,
00812                         uint32_t flags,
00813                         uid_t uid,
00814                         gid_t gid,
00815                         mode_t mode,
00816                         mode_t mask);
00817 
00818 
00845 int config_changed(struct collection_item *metadata,
00846                    struct collection_item *saved_metadata,
00847                    int *changed);
00848 
00855 void free_ini_config(struct collection_item *ini_config);
00856 
00863 void free_ini_config_errors(struct collection_item *error_set);
00864 
00865 
00872 void free_ini_config_metadata(struct collection_item *metadata);
00873 
00874 
00882 void print_file_parsing_errors(FILE *file,
00883                                struct collection_item *error_list);
00884 
00885 
00896 void print_config_parsing_errors(FILE *file,
00897                                  struct collection_item *error_set);
00898 
00919 char **get_section_list(struct collection_item *ini_config,
00920                         int *size,
00921                         int *error);
00922 
00932 void free_section_list(char **section_list);
00933 
00954 char **get_attribute_list(struct collection_item *ini_config,
00955                           const char *section,
00956                           int *size,
00957                           int *error);
00958 
00968 void free_attribute_list(char **attr_list);
00969 
00993 int get_config_item(const char *section,
00994                     const char *name,
00995                     struct collection_item *ini_config,
00996                     struct collection_item **item);
00997 
01038 int get_int_config_value(struct collection_item *item,
01039                          int strict,
01040                          int def,
01041                          int *error);
01042 
01083 long get_long_config_value(struct collection_item *item,
01084                            int strict,
01085                            long def,
01086                            int *error);
01087 
01128 unsigned get_unsigned_config_value(struct collection_item *item,
01129                                    int strict,
01130                                    unsigned def,
01131                                    int *error);
01132 
01173 unsigned long get_ulong_config_value(struct collection_item *item,
01174                                      int strict,
01175                                      unsigned long def,
01176                                      int *error);
01177 
01218 int32_t get_int32_config_value(struct collection_item *item,
01219                                int strict,
01220                                int32_t def,
01221                                int *error);
01222 
01263 uint32_t get_uint32_config_value(struct collection_item *item,
01264                                  int strict,
01265                                  uint32_t def,
01266                                  int *error);
01267 
01308 int64_t get_int64_config_value(struct collection_item *item,
01309                                int strict,
01310                                int64_t def,
01311                                int *error);
01312 
01353 uint64_t get_uint64_config_value(struct collection_item *item,
01354                                  int strict,
01355                                  uint64_t def,
01356                                  int *error);
01357 
01396 double get_double_config_value(struct collection_item *item,
01397                                int strict,
01398                                double def,
01399                                int *error);
01400 
01434 unsigned char get_bool_config_value(struct collection_item *item,
01435                                     unsigned char def,
01436                                     int *error);
01437 
01461 char *get_string_config_value(struct collection_item *item,
01462                               int *error);
01485 const char *get_const_string_config_value(struct collection_item *item,
01486                                           int *error);
01487 
01537 char *get_bin_config_value(struct collection_item *item,
01538                            int *length,
01539                            int *error);
01540 
01549 void free_bin_config_value(char *bin);
01550 
01605 char **get_string_config_array(struct collection_item *item,
01606                                const char *sep,
01607                                int *size,
01608                                int *error);
01609 
01664 char **get_raw_string_config_array(struct collection_item *item,
01665                                    const char *sep,
01666                                    int *size,
01667                                    int *error);
01668 
01711 long *get_long_config_array(struct collection_item *item,
01712                             int *size,
01713                             int *error);
01714 
01756 double *get_double_config_array(struct collection_item *item,
01757                                 int *size,
01758                                 int *error);
01759 
01769 void free_string_config_array(char **str_config);
01770 
01779 void free_long_config_array(long *array);
01788 void free_double_config_array(double *array);
01789 
01790 
01795 #endif

Generated on Thu Dec 9 12:11:52 2010 for libini_config by  doxygen 1.4.7