ini_configobj.h

00001 /*
00002     INI LIBRARY
00003 
00004     Header file for the ini collection object.
00005 
00006     Copyright (C) Dmitri Pal <dpal@redhat.com> 2010
00007 
00008     INI Library is free software: you can redistribute it and/or modify
00009     it under the terms of the GNU Lesser General Public License as published by
00010     the Free Software Foundation, either version 3 of the License, or
00011     (at your option) any later version.
00012 
00013     INI Library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public License
00019     along with INI Library.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #ifndef INI_CONFIGOBJ_H
00023 #define INI_CONFIGOBJ_H
00024 
00025 #include <sys/types.h>
00026 #include <sys/stat.h>
00027 #include <unistd.h>
00028 #include <limits.h>
00029 #include <stdio.h>
00030 #include "simplebuffer.h"
00031 
00041 #define INI_STOP_ON_ANY     0
00042 
00043 #define INI_STOP_ON_NONE    1
00044 
00045 #define INI_STOP_ON_ERROR   2
00046 
00057 #define ERR_LONGDATA        1
00058 
00059 #define ERR_NOCLOSESEC      2
00060 
00061 #define ERR_NOSECTION       3
00062 
00063 #define ERR_SECTIONLONG     4
00064 
00065 #define ERR_NOEQUAL         5
00066 
00067 #define ERR_NOKEY           6
00068 
00069 #define ERR_LONGKEY         7
00070 
00071 #define ERR_READ            8
00072 
00073 #define ERR_SPACE           9
00074 
00076 #define ERR_MAXPARSE        ERR_SPACE
00077 
00088 struct ini_cfgobj;
00089 struct ini_cfgfile;
00090 
00094 struct ini_parse_error;
00095 
00096 
00102 /********************************************************************/
00103 /* THIS IS A BEGINNING OF THE THE NEW CONFIG OBJECT INTERFACE - TBD */
00104 /* It will be moved to the ini_config.h when it is ready            */
00105 /********************************************************************/
00106 
00107 
00108 /* Create a configuration object */
00109 int ini_config_create(struct ini_cfgobj **ini_config);
00110 
00111 /* Destroy a configuration object */
00112 void ini_config_destroy(struct ini_cfgobj *ini_config);
00113 
00114 /* Create a file object for parsing a config file */
00115 int ini_config_file_open(const char *filename,
00116                          int error_level,
00117                          uint32_t collision_flags,
00118                          uint32_t metadata_flags,
00119                          struct ini_cfgfile **file_ctx);
00120 
00121 /* Close file context and destroy the object */
00122 void ini_config_file_close(struct ini_cfgfile *file_ctx);
00123 
00124 /* How many errors do we have in the list ? */
00125 unsigned ini_config_error_count(struct ini_cfgfile *file_ctx);
00126 
00127 /* Get the list of error strings */
00128 int ini_config_get_errors(struct ini_cfgfile *file_ctx,
00129                           char ***errors);
00130 
00131 /* Get the fully resolved file name */
00132 const char *ini_config_get_filename(struct ini_cfgfile *file_ctx);
00133 
00134 /* Free error strings */
00135 void ini_config_free_errors(char **errors);
00136 
00137 /* Parse the file and create a config object */
00138 int ini_config_parse(struct ini_cfgfile *file_ctx,
00139                      struct ini_cfgobj *ini_config);
00140 
00141 /* Function to print errors from the list */
00142 void ini_print_errors(FILE *file, char **error_list);
00143 
00144 
00145 /* TBD rename the function */
00152 const char *parsing_error_str(int parsing_error);
00153 
00154 
00155 /* Merge two configurations together creating a new one */
00156 int ini_config_merge(struct ini_cfgobj *first,
00157                      struct ini_cfgobj *second,
00158                      uint32_t collision_flags,
00159                      struct ini_cfgobj **result);
00160 
00161 /* Set the folding boundary for multiline values.
00162  * Use before serializing and saving to a file if the
00163  * default boundary of 80 characters does not work for you.
00164  */
00165 int ini_config_set_wrap(struct ini_cfgobj *ini_config,
00166                         uint32_t boundary);
00167 
00168 /* Serialize configuration object into provided buffer */
00169 int ini_config_serialize(struct ini_cfgobj *ini_config,
00170                          struct simplebuffer *sbobj);
00171 
00172 /* Check access */
00173 int ini_config_access_check(struct ini_cfgfile *file_ctx,
00174                             uint32_t flags,
00175                             uid_t uid,
00176                             gid_t gid,
00177                             mode_t mode,
00178                             mode_t mask);
00179 
00180 /* Determins if two file context different by comparing
00181  * - time stamp
00182  * - device ID
00183  * - i-node
00184  */
00185 int ini_config_changed(struct ini_cfgfile *file_ctx,
00186                        struct ini_cfgfile *file_ctx_saved,
00187                        int *changed);
00188 
00189 
00190 /****************************************************/
00191 /* VALUE MANAGEMENT                                 */
00192 /****************************************************/
00193 
00214 char **get_section_list(struct ini_cfgobj *ini_config,
00215                         int *size,
00216                         int *error);
00217 
00227 void free_section_list(char **section_list);
00228 
00249 char **get_attribute_list(struct ini_cfgobj *ini_config,
00250                           const char *section,
00251                           int *size,
00252                           int *error);
00253 
00263 void free_attribute_list(char **attr_list);
00264 
00265 
00298 int get_int_config_value(struct ini_cfgobj *ini_config,
00299                          const char *section,
00300                          const char *name,
00301                          int strict,
00302                          int def,
00303                          int *value);
00304 
00305 /* Similar functions are below */
00306 int get_long_config_value(struct ini_cfgobj *ini_config,
00307                           const char *section,
00308                           const char *name,
00309                           int strict,
00310                           long def,
00311                           long *value);
00312 
00313 int get_unsigned_config_value(struct ini_cfgobj *ini_config,
00314                               const char *section,
00315                               const char *name,
00316                               int strict,
00317                               unsigned def,
00318                               unsigned *value);
00319 
00320 int get_ulong_config_value(struct ini_cfgobj *ini_config,
00321                            const char *section,
00322                            const char *name,
00323                            int strict,
00324                            unsigned long def,
00325                            unsigned long *value);
00326 
00327 
00328 
00329 
00330 
00331 
00332 
00333 #ifdef THE_PART_I_HAVE_PROCESSED
00334 
00335 
00336 
00337 
00338 
00339 
00380 int32_t get_int32_config_value(struct collection_item *item,
00381                                int strict,
00382                                int32_t def,
00383                                int *error);
00384 
00425 uint32_t get_uint32_config_value(struct collection_item *item,
00426                                  int strict,
00427                                  uint32_t def,
00428                                  int *error);
00429 
00470 int64_t get_int64_config_value(struct collection_item *item,
00471                                int strict,
00472                                int64_t def,
00473                                int *error);
00474 
00515 uint64_t get_uint64_config_value(struct collection_item *item,
00516                                  int strict,
00517                                  uint64_t def,
00518                                  int *error);
00519 
00558 double get_double_config_value(struct collection_item *item,
00559                                int strict,
00560                                double def,
00561                                int *error);
00562 
00596 unsigned char get_bool_config_value(struct collection_item *item,
00597                                     unsigned char def,
00598                                     int *error);
00599 
00623 char *get_string_config_value(struct collection_item *item,
00624                               int *error);
00647 const char *get_const_string_config_value(struct collection_item *item,
00648                                           int *error);
00649 
00699 char *get_bin_config_value(struct collection_item *item,
00700                            int *length,
00701                            int *error);
00702 
00711 void free_bin_config_value(char *bin);
00712 
00767 char **get_string_config_array(struct collection_item *item,
00768                                const char *sep,
00769                                int *size,
00770                                int *error);
00771 
00826 char **get_raw_string_config_array(struct collection_item *item,
00827                                    const char *sep,
00828                                    int *size,
00829                                    int *error);
00830 
00873 long *get_long_config_array(struct collection_item *item,
00874                             int *size,
00875                             int *error);
00876 
00918 double *get_double_config_array(struct collection_item *item,
00919                                 int *size,
00920                                 int *error);
00921 
00931 void free_string_config_array(char **str_config);
00932 
00941 void free_long_config_array(long *array);
00950 void free_double_config_array(double *array);
00951 
00952 #endif
00953 
00954 #endif

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