libini_config 0.1.3
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 
00237 #define ERR_MAXPARSE        ERR_LONGKEY
00238 
00250 #define ERR_MAXGRAMMAR      0
00251 
00262 #define ERR_MAXVALID        0
00263 
00264 
00282 #define INI_ACCESS_CHECK_MODE   0x00000001
00283 
00290 #define INI_ACCESS_CHECK_UID   0x00000002
00291 
00298 #define INI_ACCESS_CHECK_GID   0x00000004
00299 
00317 struct parse_error {
00318     unsigned line;
00319     int error;
00320 };
00321 
00322 
00377 #define INI_META_ACTION_NOPARSE     0x10000000
00378 
00389 #define INI_META_SEC_ACCESS     "ACCESS"
00390 
00395 #define INI_META_SEC_ACCESS_FLAG     0x00000001
00396 
00397 
00409 #define INI_META_KEY_UID     "uid"
00410 
00415 #define INI_META_KEY_GID     "gid"
00416 
00421 #define INI_META_KEY_PERM     "perm"
00422 
00427 #define INI_META_KEY_DEV     "dev"
00428 
00433 #define INI_META_KEY_INODE     "inode"
00434 
00439 #define INI_META_KEY_MODIFIED     "modified"
00440 
00445 #define INI_META_KEY_NAME     "name"
00446 
00454 #define INI_META_SEC_ERROR     "ERROR"
00455 
00460 #define INI_META_SEC_ERROR_FLAG     0x00000002
00461 
00462 
00476 #define INI_META_KEY_READ_ERROR     "read_error"
00477 
00478 
00503 const char *parsing_error_str(int parsing_error);
00504 
00505 
00531 int config_from_file(const char *application,
00532                      const char *config_filename,
00533                      struct collection_item **ini_config,
00534                      int error_level,
00535                      struct collection_item **error_list);
00536 
00563 int config_from_fd(const char *application,
00564                    int fd,
00565                    const char *config_source,
00566                    struct collection_item **ini_config,
00567                    int error_level,
00568                    struct collection_item **error_list);
00569 
00570 
00571 
00616 int config_from_file_with_metadata(
00617                      const char *application,
00618                      const char *config_filename,
00619                      struct collection_item **ini_config,
00620                      int error_level,
00621                      struct collection_item **error_list,
00622                      uint32_t metaflags,
00623                      struct collection_item **metadata);
00624 
00625 
00670 int config_from_fd_with_metadata(
00671                    const char *application,
00672                    int fd,
00673                    const char *config_source,
00674                    struct collection_item **ini_config,
00675                    int error_level,
00676                    struct collection_item **error_list,
00677                    uint32_t metaflags,
00678                    struct collection_item **metadata);
00679 
00680 
00709 int config_for_app(const char *application,
00710                    const char *config_file,
00711                    const char *config_dir,
00712                    struct collection_item **ini_config,
00713                    int error_level,
00714                    struct collection_item **error_set);
00715 
00765 int config_for_app_with_metadata(
00766                    const char *application,
00767                    const char *config_file,
00768                    const char *config_dir,
00769                    struct collection_item **ini_config,
00770                    int error_level,
00771                    struct collection_item **error_set,
00772                    uint32_t metaflags,
00773                    struct collection_item **meta_default,
00774                    struct collection_item **meta_appini);
00775 
00776 
00807 int config_access_check(struct collection_item *metadata,
00808                         uint32_t flags,
00809                         uid_t uid,
00810                         gid_t gid,
00811                         mode_t mode,
00812                         mode_t mask);
00813 
00814 
00841 int config_changed(struct collection_item *metadata,
00842                    struct collection_item *saved_metadata,
00843                    int *changed);
00844 
00851 void free_ini_config(struct collection_item *ini_config);
00852 
00859 void free_ini_config_errors(struct collection_item *error_set);
00860 
00861 
00868 void free_ini_config_metadata(struct collection_item *metadata);
00869 
00870 
00878 void print_file_parsing_errors(FILE *file,
00879                                struct collection_item *error_list);
00880 
00881 
00892 void print_config_parsing_errors(FILE *file,
00893                                  struct collection_item *error_set);
00894 
00915 char **get_section_list(struct collection_item *ini_config,
00916                         int *size,
00917                         int *error);
00918 
00928 void free_section_list(char **section_list);
00929 
00950 char **get_attribute_list(struct collection_item *ini_config,
00951                           const char *section,
00952                           int *size,
00953                           int *error);
00954 
00964 void free_attribute_list(char **attr_list);
00965 
00989 int get_config_item(const char *section,
00990                     const char *name,
00991                     struct collection_item *ini_config,
00992                     struct collection_item **item);
00993 
01034 int get_int_config_value(struct collection_item *item,
01035                          int strict,
01036                          int def,
01037                          int *error);
01038 
01079 long get_long_config_value(struct collection_item *item,
01080                            int strict,
01081                            long def,
01082                            int *error);
01083 
01124 unsigned get_unsigned_config_value(struct collection_item *item,
01125                                    int strict,
01126                                    unsigned def,
01127                                    int *error);
01128 
01169 unsigned long get_ulong_config_value(struct collection_item *item,
01170                                      int strict,
01171                                      unsigned long def,
01172                                      int *error);
01173 
01214 int32_t get_int32_config_value(struct collection_item *item,
01215                                int strict,
01216                                int32_t def,
01217                                int *error);
01218 
01259 uint32_t get_uint32_config_value(struct collection_item *item,
01260                                  int strict,
01261                                  uint32_t def,
01262                                  int *error);
01263 
01304 int64_t get_int64_config_value(struct collection_item *item,
01305                                int strict,
01306                                int64_t def,
01307                                int *error);
01308 
01349 uint64_t get_uint64_config_value(struct collection_item *item,
01350                                  int strict,
01351                                  uint64_t def,
01352                                  int *error);
01353 
01392 double get_double_config_value(struct collection_item *item,
01393                                int strict,
01394                                double def,
01395                                int *error);
01396 
01430 unsigned char get_bool_config_value(struct collection_item *item,
01431                                     unsigned char def,
01432                                     int *error);
01433 
01457 char *get_string_config_value(struct collection_item *item,
01458                               int *error);
01481 const char *get_const_string_config_value(struct collection_item *item,
01482                                           int *error);
01483 
01533 char *get_bin_config_value(struct collection_item *item,
01534                            int *length,
01535                            int *error);
01536 
01545 void free_bin_config_value(char *bin);
01546 
01601 char **get_string_config_array(struct collection_item *item,
01602                                const char *sep,
01603                                int *size,
01604                                int *error);
01605 
01660 char **get_raw_string_config_array(struct collection_item *item,
01661                                    const char *sep,
01662                                    int *size,
01663                                    int *error);
01664 
01707 long *get_long_config_array(struct collection_item *item,
01708                             int *size,
01709                             int *error);
01710 
01752 double *get_double_config_array(struct collection_item *item,
01753                                 int *size,
01754                                 int *error);
01755 
01765 void free_string_config_array(char **str_config);
01766 
01775 void free_long_config_array(long *array);
01784 void free_double_config_array(double *array);
01785 
01786 
01791 #endif
 All Data Structures