libini_config  0.5.0
ini_configobj.h
1 /*
2  INI LIBRARY
3 
4  Header file for the ini configuration interface.
5  THIS IS THE PREFERRED INTERFACE TO USE.
6 
7  Copyright (C) Dmitri Pal <dpal@redhat.com> 2010 - 2012
8 
9  INI Library is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  INI Library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with INI Library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 
24 #ifndef INI_CONFIGOBJ_H
25 #define INI_CONFIGOBJ_H
26 
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <unistd.h>
30 #include <limits.h>
31 #include <stdio.h>
32 #include "simplebuffer.h"
33 #include "ini_valueobj.h"
34 
148 };
149 
164 enum ERR_LEVEL {
168 };
169 
182 enum ERR_PARSE {
203 };
204 
218 #define INI_META_NONE 0
219 
220 #define INI_META_STATS 1
221 
239 #define INI_ACCESS_CHECK_MODE 0x00000001
240 
247 #define INI_ACCESS_CHECK_UID 0x00000002
248 
255 #define INI_ACCESS_CHECK_GID 0x00000004
256 
279 #define INI_MV1S_OVERWRITE 0x0000
280 
281 #define INI_MV1S_ERROR 0x0001
282 
283 #define INI_MV1S_PRESERVE 0x0002
284 
285 #define INI_MV1S_ALLOW 0x0003
286 
287 #define INI_MV1S_DETECT 0x0004
288 
306 #define INI_MV2S_OVERWRITE 0x0000
307 
308 #define INI_MV2S_ERROR 0x0010
309 
310 #define INI_MV2S_PRESERVE 0x0020
311 
312 #define INI_MV2S_ALLOW 0x0030
313 
314 #define INI_MV2S_DETECT 0x0040
315 
332 #define INI_MS_MERGE 0x0000
333 
334 #define INI_MS_ERROR 0x0100
335 
336 #define INI_MS_OVERWRITE 0x0200
337 
338 #define INI_MS_PRESERVE 0x0300
339 
340 #define INI_MS_DETECT 0x0400
341 
359 #define INI_PARSE_NOWRAP 0x0001
360 
361 #define INI_PARSE_NOSPACE 0x0002
362 
363 #define INI_PARSE_NOTAB 0x0004
364 
365 #define INI_PARSE_NO_C_COMMENTS 0x0008
366 
367 #define INI_PARSE_IGNORE_NON_KVP 0x0010
368 
392 enum INI_GET {
396 };
397 
412 struct access_check {
413  uint32_t flags;
419  uid_t uid;
420  gid_t gid;
421  mode_t mode;
422  mode_t mask;
427 };
428 
430 enum augmode {
434 };
435 
446 #define INI_DEFAULT_SECTION "default"
447 
454 struct ini_cfgobj;
455 struct ini_cfgfile;
456 
460 struct ini_parse_error;
461 
462 
494 int ini_config_create(struct ini_cfgobj **ini_config);
495 
504 void ini_config_destroy(struct ini_cfgobj *ini_config);
505 
515 void ini_config_clean_state(struct ini_cfgobj *ini_config);
516 
542 int ini_config_file_open(const char *filename,
543  uint32_t metadata_flags,
544  struct ini_cfgfile **file_ctx);
545 
567 int ini_config_file_from_mem(void *data_buf,
568  uint32_t data_len,
569  struct ini_cfgfile **file_ctx);
570 
580 void ini_config_file_close(struct ini_cfgfile *file_ctx);
581 
582 
597 int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
598  struct ini_cfgfile **file_ctx_out);
599 
600 
609 void ini_config_file_destroy(struct ini_cfgfile *file_ctx);
610 
660 int ini_config_file_backup(struct ini_cfgfile *file_ctx,
661  const char *backup_dir,
662  const char *backup_tpl,
663  struct access_check *backup_access,
664  unsigned max_num);
665 
685 int ini_config_change_access(struct ini_cfgfile *file_ctx,
686  struct access_check *new_access);
687 
696 int ini_config_save(struct ini_cfgfile *file_ctx,
697  struct access_check *new_access,
698  struct ini_cfgobj *ini_config);
699 
700 
701 /* Save configuration in a file using existing context but with a new name */
733 int ini_config_save_as(struct ini_cfgfile *file_ctx,
734  const char *filename,
735  struct access_check *new_access,
736  struct ini_cfgobj *ini_config);
737 
738 
739 
751 enum index_utf_t ini_config_get_bom(struct ini_cfgfile *file_ctx);
752 
768 int ini_config_set_bom(struct ini_cfgfile *file_ctx, enum index_utf_t bom);
769 
770 
782 unsigned ini_config_error_count(struct ini_cfgobj *ini_config);
783 
800 int ini_config_get_errors(struct ini_cfgobj *ini_config,
801  char ***errors);
802 
812 void ini_config_free_errors(char **errors);
813 
825 void ini_config_print_errors(FILE *file, char **error_list);
826 
837 const char *ini_config_get_filename(struct ini_cfgfile *file_ctx);
838 
850 const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx);
851 
852 
853 
862 void ini_config_file_print(struct ini_cfgfile *file_ctx);
863 
888 int ini_config_access_check(struct ini_cfgfile *file_ctx,
889  uint32_t flags,
890  uid_t uid,
891  gid_t gid,
892  mode_t mode,
893  mode_t mask);
894 
926 int ini_config_changed(struct ini_cfgfile *file_ctx1,
927  struct ini_cfgfile *file_ctx2,
928  int *changed);
929 
952 int ini_config_parse(struct ini_cfgfile *file_ctx,
953  int error_level,
954  uint32_t collision_flags,
955  uint32_t parse_flags,
956  struct ini_cfgobj *ini_config);
957 
971 int ini_config_copy(struct ini_cfgobj *ini_config,
972  struct ini_cfgobj **ini_new);
973 
999 int ini_config_merge(struct ini_cfgobj *first,
1000  struct ini_cfgobj *second,
1001  uint32_t collision_flags,
1002  struct ini_cfgobj **result);
1003 
1004 
1066 int ini_config_augment(struct ini_cfgobj *base_cfg,
1067  const char *path,
1068  const char *patterns[],
1069  const char *sections[],
1070  struct access_check *check_perm,
1071  int error_level,
1072  uint32_t collision_flags,
1073  uint32_t parse_flags,
1074  uint32_t merge_flags,
1075  struct ini_cfgobj **result_cfg,
1076  struct ref_array **error_list,
1077  struct ref_array **success_list);
1078 
1092 int ini_config_set_wrap(struct ini_cfgobj *ini_config,
1093  uint32_t boundary);
1094 
1109 int ini_config_serialize(struct ini_cfgobj *ini_config,
1110  struct simplebuffer *sbobj);
1111 
1112 
1113 /* Functions that add, modify or delete sections and values in
1114  * the configuration object can be found in section \ref ini_mod.
1115  */
1116 
1153 char **ini_get_section_list(struct ini_cfgobj *ini_config,
1154  int *size,
1155  int *error);
1156 
1166 void ini_free_section_list(char **section_list);
1167 
1188 char **ini_get_attribute_list(struct ini_cfgobj *ini_config,
1189  const char *section,
1190  int *size,
1191  int *error);
1192 
1202 void ini_free_attribute_list(char **attr_list);
1203 
1245 int ini_get_config_valueobj(const char *section,
1246  const char *name,
1247  struct ini_cfgobj *ini_config,
1248  int mode,
1249  struct value_obj **vo);
1250 
1251 
1252 
1293 int ini_get_int_config_value(struct value_obj *vo,
1294  int strict,
1295  int def,
1296  int *error);
1297 
1339 unsigned ini_get_unsigned_config_value(struct value_obj *vo,
1340  int strict,
1341  unsigned def,
1342  int *error);
1343 
1385 long ini_get_long_config_value(struct value_obj *vo,
1386  int strict,
1387  long def,
1388  int *error);
1389 
1431 unsigned long ini_get_ulong_config_value(struct value_obj *vo,
1432  int strict,
1433  unsigned long def,
1434  int *error);
1435 
1436 
1477 int32_t ini_get_int32_config_value(struct value_obj *vo,
1478  int strict,
1479  int32_t def,
1480  int *error);
1481 
1522 uint32_t ini_get_uint32_config_value(struct value_obj *vo,
1523  int strict,
1524  uint32_t def,
1525  int *error);
1526 
1567 int64_t ini_get_int64_config_value(struct value_obj *vo,
1568  int strict,
1569  int64_t def,
1570  int *error);
1571 
1612 uint64_t ini_get_uint64_config_value(struct value_obj *vo,
1613  int strict,
1614  uint64_t def,
1615  int *error);
1616 
1655 double ini_get_double_config_value(struct value_obj *vo,
1656  int strict,
1657  double def,
1658  int *error);
1659 
1693 unsigned char ini_get_bool_config_value(struct value_obj *vo,
1694  unsigned char def,
1695  int *error);
1696 
1721 char *ini_get_string_config_value(struct value_obj *vo,
1722  int *error);
1745 const char *ini_get_const_string_config_value(struct value_obj *vo,
1746  int *error);
1747 
1797 char *ini_get_bin_config_value(struct value_obj *vo,
1798  int *length,
1799  int *error);
1800 
1809 void ini_free_bin_config_value(char *bin);
1810 
1865 char **ini_get_string_config_array(struct value_obj *vo,
1866  const char *sep,
1867  int *size,
1868  int *error);
1869 
1924 char **ini_get_raw_string_config_array(struct value_obj *vo,
1925  const char *sep,
1926  int *size,
1927  int *error);
1928 
1971 long *ini_get_long_config_array(struct value_obj *vo,
1972  int *size,
1973  int *error);
1974 
2016 double *ini_get_double_config_array(struct value_obj *vo,
2017  int *size,
2018  int *error);
2019 
2029 void ini_free_string_config_array(char **str_config);
2030 
2039 void ini_free_long_config_array(long *array);
2048 void ini_free_double_config_array(double *array);
2049 
2054 #endif
Definition: ini_configobj.h:183
Definition: ini_configobj.h:199
int ini_get_config_valueobj(const char *section, const char *name, struct ini_cfgobj *ini_config, int mode, struct value_obj **vo)
Retrieve a value object form the configuration.
void ini_free_long_config_array(long *array)
Free array of long values.
void ini_config_file_print(struct ini_cfgfile *file_ctx)
Print file context.
Definition: ini_configobj.h:192
void ini_free_attribute_list(char **attr_list)
Free list of attributes.
mode_t mode
Definition: ini_configobj.h:421
ERR_LEVEL
Definition: ini_configobj.h:164
void ini_config_free_errors(char **errors)
Free array of parsing errors.
char ** ini_get_string_config_array(struct value_obj *vo, const char *sep, int *size, int *error)
Convert value to an array of strings.
Definition: ini_configobj.h:194
Definition: ini_configobj.h:167
Definition: ini_configobj.h:147
INI_GET
Definition: ini_configobj.h:392
int ini_config_save_as(struct ini_cfgfile *file_ctx, const char *filename, struct access_check *new_access, struct ini_cfgobj *ini_config)
Save configuration with a new name.
Definition: ini_configobj.h:190
const char * ini_config_get_filename(struct ini_cfgfile *file_ctx)
Get the fully resolved file name.
Definition: ini_configobj.h:432
Definition: ini_configobj.h:394
void ini_free_section_list(char **section_list)
Free list of sections.
uint32_t ini_get_uint32_config_value(struct value_obj *vo, int strict, uint32_t def, int *error)
Convert value to uint32_t number.
int ini_config_file_backup(struct ini_cfgfile *file_ctx, const char *backup_dir, const char *backup_tpl, struct access_check *backup_access, unsigned max_num)
Save configuration in a backup configuration file.
unsigned ini_config_error_count(struct ini_cfgobj *ini_config)
Check parsing errors count.
void ini_config_destroy(struct ini_cfgobj *ini_config)
Destroy a configuration object.
Definition: ini_configobj.h:198
int ini_config_changed(struct ini_cfgfile *file_ctx1, struct ini_cfgfile *file_ctx2, int *changed)
Check if file has changed.
Definition: ini_configobj.h:395
Definition: ini_configobj.h:184
long * ini_get_long_config_array(struct value_obj *vo, int *size, int *error)
Convert value to an array of long values.
int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in, struct ini_cfgfile **file_ctx_out)
Reopen the configuration file.
long ini_get_long_config_value(struct value_obj *vo, int strict, long def, int *error)
Convert value to long number.
Definition: ini_configobj.h:187
unsigned ini_get_unsigned_config_value(struct value_obj *vo, int strict, unsigned def, int *error)
Convert value object to a unsigned number.
char ** ini_get_raw_string_config_array(struct value_obj *vo, const char *sep, int *size, int *error)
Convert value to an array of strings.
void ini_free_bin_config_value(char *bin)
Free binary buffer.
Definition: ini_configobj.h:412
int ini_config_get_errors(struct ini_cfgobj *ini_config, char ***errors)
Get array of parsing errors.
uid_t uid
Definition: ini_configobj.h:419
void ini_config_clean_state(struct ini_cfgobj *ini_config)
Flush cached search data.
Definition: ini_configobj.h:393
char * ini_get_string_config_value(struct value_obj *vo, int *error)
Get the copy of string stored in the configuration value.
Definition: ini_configobj.h:165
uint64_t ini_get_uint64_config_value(struct value_obj *vo, int strict, uint64_t def, int *error)
Convert value to integer number.
int ini_config_merge(struct ini_cfgobj *first, struct ini_cfgobj *second, uint32_t collision_flags, struct ini_cfgobj **result)
Merge two configuration objects.
gid_t gid
Definition: ini_configobj.h:420
Definition: ini_configobj.h:191
int ini_config_set_wrap(struct ini_cfgobj *ini_config, uint32_t boundary)
Set the folding boundary.
Definition: ini_configobj.h:433
Definition: ini_configobj.h:144
Definition: ini_configobj.h:195
double * ini_get_double_config_array(struct value_obj *vo, int *size, int *error)
Convert value to an array of floating point values.
Definition: ini_configobj.h:189
Definition: ini_configobj.h:142
Definition: ini_configobj.h:188
enum index_utf_t ini_config_get_bom(struct ini_cfgfile *file_ctx)
Return the encoding indicator.
index_utf_t
Definition: ini_configobj.h:141
int ini_get_int_config_value(struct value_obj *vo, int strict, int def, int *error)
Convert value to integer number.
Definition: ini_configobj.h:201
void ini_config_file_close(struct ini_cfgfile *file_ctx)
Close configuration file after parsing.
Definition: ini_configobj.h:146
Definition: ini_configobj.h:143
void ini_config_print_errors(FILE *file, char **error_list)
Print errors to a file.
int ini_config_change_access(struct ini_cfgfile *file_ctx, struct access_check *new_access)
Change permissions and ownership of the file.
int ini_config_set_bom(struct ini_cfgfile *file_ctx, enum index_utf_t bom)
Set the encoding indicator.
unsigned char ini_get_bool_config_value(struct value_obj *vo, unsigned char def, int *error)
Convert value into a logical value.
char ** ini_get_section_list(struct ini_cfgobj *ini_config, int *size, int *error)
Get list of sections.
const char * ini_get_const_string_config_value(struct value_obj *vo, int *error)
Get the string stored in the configuration value.
ERR_PARSE
Definition: ini_configobj.h:182
Definition: ini_configobj.h:145
void ini_free_double_config_array(double *array)
Free array of floating pointer values.
int ini_config_copy(struct ini_cfgobj *ini_config, struct ini_cfgobj **ini_new)
Create a copy of the configuration object.
Definition: ini_configobj.h:197
int ini_config_access_check(struct ini_cfgfile *file_ctx, uint32_t flags, uid_t uid, gid_t gid, mode_t mode, mode_t mask)
Check file properties.
void ini_config_file_destroy(struct ini_cfgfile *file_ctx)
Close configuration file and free all data.
Definition: ini_configobj.h:202
char ** ini_get_attribute_list(struct ini_cfgobj *ini_config, const char *section, int *size, int *error)
Get list of attributes.
Definition: ini_configobj.h:186
int32_t ini_get_int32_config_value(struct value_obj *vo, int strict, int32_t def, int *error)
Convert value to int32_t number.
int ini_config_save(struct ini_cfgfile *file_ctx, struct access_check *new_access, struct ini_cfgobj *ini_config)
Save configuration in a file.
Definition: ini_configobj.h:431
int ini_config_augment(struct ini_cfgobj *base_cfg, const char *path, const char *patterns[], const char *sections[], struct access_check *check_perm, int error_level, uint32_t collision_flags, uint32_t parse_flags, uint32_t merge_flags, struct ini_cfgobj **result_cfg, struct ref_array **error_list, struct ref_array **success_list)
Augment configuration.
char * ini_get_bin_config_value(struct value_obj *vo, int *length, int *error)
Convert value into a binary sequence.
int ini_config_create(struct ini_cfgobj **ini_config)
Create a configuration object.
int ini_config_file_open(const char *filename, uint32_t metadata_flags, struct ini_cfgfile **file_ctx)
Create a configuration file object.
int ini_config_serialize(struct ini_cfgobj *ini_config, struct simplebuffer *sbobj)
Serialize configuration object.
int64_t ini_get_int64_config_value(struct value_obj *vo, int strict, int64_t def, int *error)
Convert value to integer number.
Definition: ini_configobj.h:166
mode_t mask
Definition: ini_configobj.h:422
double ini_get_double_config_value(struct value_obj *vo, int strict, double def, int *error)
Convert value to floating point number.
int ini_config_parse(struct ini_cfgfile *file_ctx, int error_level, uint32_t collision_flags, uint32_t parse_flags, struct ini_cfgobj *ini_config)
Parse the file and populate a configuration object.
uint32_t flags
Definition: ini_configobj.h:413
int ini_config_file_from_mem(void *data_buf, uint32_t data_len, struct ini_cfgfile **file_ctx)
Create a configuration file object using memory buffer.
unsigned long ini_get_ulong_config_value(struct value_obj *vo, int strict, unsigned long def, int *error)
Convert value to unsigned long number.
const struct stat * ini_config_get_stat(struct ini_cfgfile *file_ctx)
Get pointer to collected stat data.
void ini_free_string_config_array(char **str_config)
Free array of string values.
augmode
Definition: ini_configobj.h:430