libini_config 0.6.1
Loading...
Searching...
No Matches
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
35#ifndef DING_ATTR_FORMAT
36# if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)))
37# define DING_ATTR_FORMAT(fmt, args) __attribute__((__format__(__printf__, fmt, args)))
38# else
39# define DING_ATTR_FORMAT(fmt, args)
40# endif
41#endif
42
155 INDEX_UTF8NOBOM = 5
157
177
200 ERR_SPACE,
207 ERR_TAB,
212
226#define INI_META_NONE 0
228#define INI_META_STATS 1
229
247#define INI_ACCESS_CHECK_MODE 0x00000001
248
255#define INI_ACCESS_CHECK_UID 0x00000002
256
263#define INI_ACCESS_CHECK_GID 0x00000004
264
287#define INI_MV1S_OVERWRITE 0x0000
289#define INI_MV1S_ERROR 0x0001
291#define INI_MV1S_PRESERVE 0x0002
293#define INI_MV1S_ALLOW 0x0003
295#define INI_MV1S_DETECT 0x0004
296
314#define INI_MV2S_OVERWRITE 0x0000
316#define INI_MV2S_ERROR 0x0010
318#define INI_MV2S_PRESERVE 0x0020
320#define INI_MV2S_ALLOW 0x0030
322#define INI_MV2S_DETECT 0x0040
323
340#define INI_MS_MERGE 0x0000
342#define INI_MS_ERROR 0x0100
344#define INI_MS_OVERWRITE 0x0200
346#define INI_MS_PRESERVE 0x0300
349#define INI_MS_DETECT 0x0400
350
368#define INI_PARSE_NOWRAP 0x0001
370#define INI_PARSE_NOSPACE 0x0002
372#define INI_PARSE_NOTAB 0x0004
374#define INI_PARSE_NO_C_COMMENTS 0x0008
376#define INI_PARSE_IGNORE_NON_KVP 0x0010
377
406
422 uint32_t flags;
428 uid_t uid;
429 gid_t gid;
430 mode_t mode;
431 mode_t mask;
436};
437
442 INI_AUG_OVER = 2
444
455#define INI_DEFAULT_SECTION "default"
456
463struct ini_cfgobj;
464struct ini_cfgfile;
465
469struct ini_parse_error;
470
471
503int ini_config_create(struct ini_cfgobj **ini_config);
504
513void ini_config_destroy(struct ini_cfgobj *ini_config);
514
524void ini_config_clean_state(struct ini_cfgobj *ini_config);
525
551int ini_config_file_open(const char *filename,
552 uint32_t metadata_flags,
553 struct ini_cfgfile **file_ctx);
554
576int ini_config_file_from_mem(void *data_buf,
577 uint32_t data_len,
578 struct ini_cfgfile **file_ctx);
579
589void ini_config_file_close(struct ini_cfgfile *file_ctx);
590
591
606int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in,
607 struct ini_cfgfile **file_ctx_out);
608
609
618void ini_config_file_destroy(struct ini_cfgfile *file_ctx);
619
669int ini_config_file_backup(struct ini_cfgfile *file_ctx,
670 const char *backup_dir,
671 const char *backup_tpl,
672 struct access_check *backup_access,
673 unsigned max_num);
674
694int ini_config_change_access(struct ini_cfgfile *file_ctx,
695 struct access_check *new_access);
696
705int ini_config_save(struct ini_cfgfile *file_ctx,
706 struct access_check *new_access,
707 struct ini_cfgobj *ini_config);
708
709
710/* Save configuration in a file using existing context but with a new name */
742int ini_config_save_as(struct ini_cfgfile *file_ctx,
743 const char *filename,
744 struct access_check *new_access,
745 struct ini_cfgobj *ini_config);
746
747
748
760enum index_utf_t ini_config_get_bom(struct ini_cfgfile *file_ctx);
761
777int ini_config_set_bom(struct ini_cfgfile *file_ctx, enum index_utf_t bom);
778
779
791unsigned ini_config_error_count(struct ini_cfgobj *ini_config);
792
809int ini_config_get_errors(struct ini_cfgobj *ini_config,
810 char ***errors);
811
821void ini_config_free_errors(char **errors);
822
834void ini_config_print_errors(FILE *file, char **error_list);
835
846const char *ini_config_get_filename(struct ini_cfgfile *file_ctx);
847
859const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx);
860
861
862
871void ini_config_file_print(struct ini_cfgfile *file_ctx);
872
897int ini_config_access_check(struct ini_cfgfile *file_ctx,
898 uint32_t flags,
899 uid_t uid,
900 gid_t gid,
901 mode_t mode,
902 mode_t mask);
903
935int ini_config_changed(struct ini_cfgfile *file_ctx1,
936 struct ini_cfgfile *file_ctx2,
937 int *changed);
938
961int ini_config_parse(struct ini_cfgfile *file_ctx,
962 int error_level,
963 uint32_t collision_flags,
964 uint32_t parse_flags,
965 struct ini_cfgobj *ini_config);
966
980int ini_config_copy(struct ini_cfgobj *ini_config,
981 struct ini_cfgobj **ini_new);
982
1008int ini_config_merge(struct ini_cfgobj *first,
1009 struct ini_cfgobj *second,
1010 uint32_t collision_flags,
1011 struct ini_cfgobj **result);
1012
1013
1078int ini_config_augment(struct ini_cfgobj *base_cfg,
1079 const char *path,
1080 const char *patterns[],
1081 const char *sections[],
1082 struct access_check *check_perm,
1083 int error_level,
1084 uint32_t collision_flags,
1085 uint32_t parse_flags,
1086 uint32_t merge_flags,
1087 struct ini_cfgobj **result_cfg,
1088 struct ref_array **error_list,
1089 struct ref_array **success_list);
1090
1104int ini_config_set_wrap(struct ini_cfgobj *ini_config,
1105 uint32_t boundary);
1106
1121int ini_config_serialize(struct ini_cfgobj *ini_config,
1122 struct simplebuffer *sbobj);
1123
1124
1125/* Functions that add, modify or delete sections and values in
1126 * the configuration object can be found in section \ref ini_mod.
1127 */
1128
1165char **ini_get_section_list(struct ini_cfgobj *ini_config,
1166 int *size,
1167 int *error);
1168
1178void ini_free_section_list(char **section_list);
1179
1200char **ini_get_attribute_list(struct ini_cfgobj *ini_config,
1201 const char *section,
1202 int *size,
1203 int *error);
1204
1214void ini_free_attribute_list(char **attr_list);
1215
1257int ini_get_config_valueobj(const char *section,
1258 const char *name,
1259 struct ini_cfgobj *ini_config,
1260 int mode,
1261 struct value_obj **vo);
1262
1263
1264
1305int ini_get_int_config_value(struct value_obj *vo,
1306 int strict,
1307 int def,
1308 int *error);
1309
1351unsigned ini_get_unsigned_config_value(struct value_obj *vo,
1352 int strict,
1353 unsigned def,
1354 int *error);
1355
1397long ini_get_long_config_value(struct value_obj *vo,
1398 int strict,
1399 long def,
1400 int *error);
1401
1443unsigned long ini_get_ulong_config_value(struct value_obj *vo,
1444 int strict,
1445 unsigned long def,
1446 int *error);
1447
1448
1489int32_t ini_get_int32_config_value(struct value_obj *vo,
1490 int strict,
1491 int32_t def,
1492 int *error);
1493
1534uint32_t ini_get_uint32_config_value(struct value_obj *vo,
1535 int strict,
1536 uint32_t def,
1537 int *error);
1538
1579int64_t ini_get_int64_config_value(struct value_obj *vo,
1580 int strict,
1581 int64_t def,
1582 int *error);
1583
1624uint64_t ini_get_uint64_config_value(struct value_obj *vo,
1625 int strict,
1626 uint64_t def,
1627 int *error);
1628
1667double ini_get_double_config_value(struct value_obj *vo,
1668 int strict,
1669 double def,
1670 int *error);
1671
1705unsigned char ini_get_bool_config_value(struct value_obj *vo,
1706 unsigned char def,
1707 int *error);
1708
1733char *ini_get_string_config_value(struct value_obj *vo,
1734 int *error);
1757const char *ini_get_const_string_config_value(struct value_obj *vo,
1758 int *error);
1759
1809char *ini_get_bin_config_value(struct value_obj *vo,
1810 int *length,
1811 int *error);
1812
1822
1877char **ini_get_string_config_array(struct value_obj *vo,
1878 const char *sep,
1879 int *size,
1880 int *error);
1881
1936char **ini_get_raw_string_config_array(struct value_obj *vo,
1937 const char *sep,
1938 int *size,
1939 int *error);
1940
1983long *ini_get_long_config_array(struct value_obj *vo,
1984 int *size,
1985 int *error);
1986
2028double *ini_get_double_config_array(struct value_obj *vo,
2029 int *size,
2030 int *error);
2031
2041void ini_free_string_config_array(char **str_config);
2042
2061
2065struct ini_errobj;
2066
2078int ini_errobj_create(struct ini_errobj **_errobj);
2079
2088void ini_errobj_destroy(struct ini_errobj **errobj);
2089
2103int ini_errobj_add_msg(struct ini_errobj *errobj,
2104 const char *format, ...)
2105 DING_ATTR_FORMAT(2, 3);
2106
2117void ini_errobj_reset(struct ini_errobj *errobj);
2118
2132const char *ini_errobj_get_msg(struct ini_errobj *errobj);
2133
2143void ini_errobj_next(struct ini_errobj *errobj);
2144
2155int ini_errobj_no_more_msgs(struct ini_errobj *errobj);
2156
2166size_t ini_errobj_count(struct ini_errobj *errobj);
2167
2168typedef int (ini_validator_func)(const char *rule_name,
2169 struct ini_cfgobj *rules_obj,
2170 struct ini_cfgobj *config_obj,
2171 struct ini_errobj *errobj,
2172 void **data);
2173
2174typedef int (ini_schema_validator_func)(const char *rule_name,
2175 struct ini_cfgobj *rules_obj,
2176 struct ini_errobj *errobj,
2177 void **data);
2178
2183 const char *name;
2184 ini_validator_func *func;
2185 /* currently unused, for future expansion */
2186 ini_schema_validator_func *schema_validator;
2187};
2188
2202int ini_rules_read_from_file(const char *filename,
2203 struct ini_cfgobj **_rules_obj);
2204
2229int ini_rules_check(struct ini_cfgobj *rules_obj,
2230 struct ini_cfgobj *config_obj,
2231 struct ini_validator **extra_validators,
2232 struct ini_errobj *errobj);
2233
2239void ini_rules_destroy(struct ini_cfgobj *ini_config);
2240
2245#endif
augmode
Definition: ini_configobj.h:439
@ INI_AUG_ADD
Definition: ini_configobj.h:441
@ INI_AUG_OVER
Definition: ini_configobj.h:442
@ INI_AUG_ANY
Definition: ini_configobj.h:440
index_utf_t
Definition: ini_configobj.h:149
@ INDEX_UTF32LE
Definition: ini_configobj.h:151
@ INDEX_UTF32BE
Definition: ini_configobj.h:150
@ INDEX_UTF8
Definition: ini_configobj.h:154
@ INDEX_UTF8NOBOM
Definition: ini_configobj.h:155
@ INDEX_UTF16LE
Definition: ini_configobj.h:153
@ INDEX_UTF16BE
Definition: ini_configobj.h:152
ERR_LEVEL
Definition: ini_configobj.h:172
@ INI_STOP_ON_NONE
Definition: ini_configobj.h:174
@ INI_STOP_ON_ERROR
Definition: ini_configobj.h:175
@ INI_STOP_ON_ANY
Definition: ini_configobj.h:173
void ini_config_clean_state(struct ini_cfgobj *ini_config)
Flush cached search data.
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.
const struct stat * ini_config_get_stat(struct ini_cfgfile *file_ctx)
Get pointer to collected stat data.
int ini_config_create(struct ini_cfgobj **ini_config)
Create a configuration object.
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.
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_changed(struct ini_cfgfile *file_ctx1, struct ini_cfgfile *file_ctx2, int *changed)
Check if file has changed.
int ini_config_serialize(struct ini_cfgobj *ini_config, struct simplebuffer *sbobj)
Serialize configuration object.
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_free_errors(char **errors)
Free array of parsing errors.
void ini_config_file_close(struct ini_cfgfile *file_ctx)
Close configuration file after parsing.
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.
int ini_config_file_reopen(struct ini_cfgfile *file_ctx_in, struct ini_cfgfile **file_ctx_out)
Reopen the configuration file.
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.
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_get_errors(struct ini_cfgobj *ini_config, char ***errors)
Get array of parsing errors.
int ini_config_merge(struct ini_cfgobj *first, struct ini_cfgobj *second, uint32_t collision_flags, struct ini_cfgobj **result)
Merge two configuration objects.
const char * ini_config_get_filename(struct ini_cfgfile *file_ctx)
Get the fully resolved file name.
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.
void ini_config_file_print(struct ini_cfgfile *file_ctx)
Print file context.
void ini_config_print_errors(FILE *file, char **error_list)
Print errors to a file.
int ini_config_copy(struct ini_cfgobj *ini_config, struct ini_cfgobj **ini_new)
Create a copy of the configuration object.
int ini_config_set_wrap(struct ini_cfgobj *ini_config, uint32_t boundary)
Set the folding boundary.
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.
void ini_config_file_destroy(struct ini_cfgfile *file_ctx)
Close configuration file and free all data.
int ini_config_set_bom(struct ini_cfgfile *file_ctx, enum index_utf_t bom)
Set the encoding indicator.
int ini_config_save(struct ini_cfgfile *file_ctx, struct access_check *new_access, struct ini_cfgobj *ini_config)
Save configuration in a file.
enum index_utf_t ini_config_get_bom(struct ini_cfgfile *file_ctx)
Return the encoding indicator.
char ** ini_get_section_list(struct ini_cfgobj *ini_config, int *size, int *error)
Get list of sections.
void ini_free_attribute_list(char **attr_list)
Free list of attributes.
char ** ini_get_attribute_list(struct ini_cfgobj *ini_config, const char *section, int *size, int *error)
Get list of attributes.
void ini_free_section_list(char **section_list)
Free list of sections.
void ini_errobj_next(struct ini_errobj *errobj)
Move to the next message in errobj.
int64_t ini_get_int64_config_value(struct value_obj *vo, int strict, int64_t def, int *error)
Convert value to integer number.
const char * ini_errobj_get_msg(struct ini_errobj *errobj)
Get pointer to current message in errobj.
int ini_rules_read_from_file(const char *filename, struct ini_cfgobj **_rules_obj)
Read rules from INI file.
unsigned long ini_get_ulong_config_value(struct value_obj *vo, int strict, unsigned long def, int *error)
Convert value to unsigned long 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.
unsigned char ini_get_bool_config_value(struct value_obj *vo, unsigned char def, int *error)
Convert value into a logical value.
const char * ini_get_const_string_config_value(struct value_obj *vo, int *error)
Get the string stored in the configuration value.
double ini_get_double_config_value(struct value_obj *vo, int strict, double def, int *error)
Convert value to floating point number.
void ini_errobj_destroy(struct ini_errobj **errobj)
Free structure that holds error messages.
unsigned ini_get_unsigned_config_value(struct value_obj *vo, int strict, unsigned def, int *error)
Convert value object to a unsigned number.
int ini_rules_check(struct ini_cfgobj *rules_obj, struct ini_cfgobj *config_obj, struct ini_validator **extra_validators, struct ini_errobj *errobj)
Check configuration file using rules.
void ini_rules_destroy(struct ini_cfgobj *ini_config)
Free the rules.
size_t ini_errobj_count(struct ini_errobj *errobj)
Return number of messages in errobj.
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_errobj_add_msg(struct ini_errobj *errobj, const char *format,...) DING_ATTR_FORMAT(2
Add new printf formated message to errobj.
double * ini_get_double_config_array(struct value_obj *vo, int *size, int *error)
Convert value to an array of floating point values.
char ** ini_get_string_config_array(struct value_obj *vo, const char *sep, int *size, int *error)
Convert value to an array of strings.
int ini_errobj_create(struct ini_errobj **_errobj)
Create structure to hold error messages.
int void ini_errobj_reset(struct ini_errobj *errobj)
Reset iterator in errobj.
char * ini_get_bin_config_value(struct value_obj *vo, int *length, int *error)
Convert value into a binary sequence.
long * ini_get_long_config_array(struct value_obj *vo, int *size, int *error)
Convert value to an array of long values.
uint64_t ini_get_uint64_config_value(struct value_obj *vo, int strict, uint64_t def, int *error)
Convert value to integer number.
void ini_free_string_config_array(char **str_config)
Free array of string values.
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_double_config_array(double *array)
Free array of floating pointer values.
long ini_get_long_config_value(struct value_obj *vo, int strict, long def, int *error)
Convert value to long number.
void ini_free_long_config_array(long *array)
Free array of long values.
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_errobj_no_more_msgs(struct ini_errobj *errobj)
Check if errobj has more messages.
void ini_free_bin_config_value(char *bin)
Free binary buffer.
char * ini_get_string_config_value(struct value_obj *vo, int *error)
Get the copy of string stored in the configuration value.
int ini_get_int_config_value(struct value_obj *vo, int strict, int def, int *error)
Convert value to integer number.
ERR_PARSE
Definition: ini_configobj.h:190
@ ERR_SPACE
Definition: ini_configobj.h:200
@ ERR_MAXPARSE
Definition: ini_configobj.h:210
@ ERR_TAB
Definition: ini_configobj.h:207
@ ERR_DUPSECTION
Definition: ini_configobj.h:205
@ ERR_NOEQUAL
Definition: ini_configobj.h:196
@ ERR_BADCOMMENT
Definition: ini_configobj.h:209
@ ERR_SPECIAL
Definition: ini_configobj.h:206
@ ERR_READ
Definition: ini_configobj.h:199
@ ERR_SECTIONLONG
Definition: ini_configobj.h:195
@ ERR_NOSECTION
Definition: ini_configobj.h:194
@ ERR_LONGDATA
Definition: ini_configobj.h:191
@ ERR_LONGKEY
Definition: ini_configobj.h:198
@ ERR_NOKEY
Definition: ini_configobj.h:197
@ ERR_DUPKEY
Definition: ini_configobj.h:202
@ ERR_NOCLOSESEC
Definition: ini_configobj.h:192
@ ERR_DUPKEYSEC
Definition: ini_configobj.h:203
INI_GET
Definition: ini_configobj.h:401
@ INI_GET_LAST_VALUE
Definition: ini_configobj.h:404
@ INI_GET_FIRST_VALUE
Definition: ini_configobj.h:402
@ INI_GET_NEXT_VALUE
Definition: ini_configobj.h:403
Definition: ini_configobj.h:421
uid_t uid
Definition: ini_configobj.h:428
uint32_t flags
Definition: ini_configobj.h:422
gid_t gid
Definition: ini_configobj.h:429
mode_t mode
Definition: ini_configobj.h:430
mode_t mask
Definition: ini_configobj.h:431
Structure used to define application specific (external to libini) validator.
Definition: ini_configobj.h:2182