libini_config  0.2.91
 All Data Structures Functions Groups Pages
ini_config.h
1 /*
2  INI LIBRARY
3 
4  Header file for reading configuration from INI file
5  and storing as a collection.
6 
7  Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
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 #ifndef INI_CONFIG_H
24 #define INI_CONFIG_H
25 
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <limits.h>
30 #include <stdio.h>
31 #include "collection.h"
32 
128 #define INI_DEFAULT_SECTION "default"
129 
153 #define COL_CLASS_INI_BASE 20000
154 
165 #define COL_CLASS_INI_CONFIG COL_CLASS_INI_BASE + 0
166 
170 #define COL_CLASS_INI_SECTION COL_CLASS_INI_BASE + 1
171 
176 #define COL_CLASS_INI_PERROR COL_CLASS_INI_BASE + 2
177 
185 #define COL_CLASS_INI_PESET COL_CLASS_INI_BASE + 3
186 
192 #define COL_CLASS_INI_META COL_CLASS_INI_BASE + 4
193 
206 #define INI_STOP_ON_ANY 0
207 
208 #define INI_STOP_ON_NONE 1
209 
210 #define INI_STOP_ON_ERROR 2
211 
222 #define ERR_LONGDATA 1
223 
224 #define ERR_NOCLOSESEC 2
225 
226 #define ERR_NOSECTION 3
227 
228 #define ERR_SECTIONLONG 4
229 
230 #define ERR_NOEQUAL 5
231 
232 #define ERR_NOKEY 6
233 
234 #define ERR_LONGKEY 7
235 
236 #define ERR_READ 8
237 
238 #define ERR_SPACE 9
239 
241 #define ERR_MAXPARSE ERR_SPACE
242 
254 #define ERR_MAXGRAMMAR 0
255 
266 #define ERR_MAXVALID 0
267 
268 
286 #define INI_ACCESS_CHECK_MODE 0x00000001
287 
294 #define INI_ACCESS_CHECK_UID 0x00000002
295 
302 #define INI_ACCESS_CHECK_GID 0x00000004
303 
321 struct parse_error {
322  unsigned line;
323  int error;
324 };
325 
326 
381 #define INI_META_ACTION_NOPARSE 0x10000000
382 
393 #define INI_META_SEC_ACCESS "ACCESS"
394 
399 #define INI_META_SEC_ACCESS_FLAG 0x00000001
400 
401 
413 #define INI_META_KEY_UID "uid"
414 
419 #define INI_META_KEY_GID "gid"
420 
425 #define INI_META_KEY_PERM "perm"
426 
431 #define INI_META_KEY_DEV "dev"
432 
437 #define INI_META_KEY_INODE "inode"
438 
443 #define INI_META_KEY_MODIFIED "modified"
444 
449 #define INI_META_KEY_NAME "name"
450 
458 #define INI_META_SEC_ERROR "ERROR"
459 
464 #define INI_META_SEC_ERROR_FLAG 0x00000002
465 
466 
480 #define INI_META_KEY_READ_ERROR "read_error"
481 
482 
527 int config_from_file(const char *application,
528  const char *config_filename,
529  struct collection_item **ini_config,
530  int error_level,
531  struct collection_item **error_list);
532 
559 int config_from_fd(const char *application,
560  int fd,
561  const char *config_source,
562  struct collection_item **ini_config,
563  int error_level,
564  struct collection_item **error_list);
565 
566 
567 
613  const char *application,
614  const char *config_filename,
615  struct collection_item **ini_config,
616  int error_level,
617  struct collection_item **error_list,
618  uint32_t metaflags,
619  struct collection_item **metadata);
620 
621 
667  const char *application,
668  int fd,
669  const char *config_source,
670  struct collection_item **ini_config,
671  int error_level,
672  struct collection_item **error_list,
673  uint32_t metaflags,
674  struct collection_item **metadata);
675 
676 
705 int config_for_app(const char *application,
706  const char *config_file,
707  const char *config_dir,
708  struct collection_item **ini_config,
709  int error_level,
710  struct collection_item **error_set);
711 
762  const char *application,
763  const char *config_file,
764  const char *config_dir,
765  struct collection_item **ini_config,
766  int error_level,
767  struct collection_item **error_set,
768  uint32_t metaflags,
769  struct collection_item **meta_default,
770  struct collection_item **meta_appini);
771 
772 
803 int config_access_check(struct collection_item *metadata,
804  uint32_t flags,
805  uid_t uid,
806  gid_t gid,
807  mode_t mode,
808  mode_t mask);
809 
810 
837 int config_changed(struct collection_item *metadata,
838  struct collection_item *saved_metadata,
839  int *changed);
840 
847 void free_ini_config(struct collection_item *ini_config);
848 
855 void free_ini_config_errors(struct collection_item *error_set);
856 
857 
864 void free_ini_config_metadata(struct collection_item *metadata);
865 
866 
874 void print_file_parsing_errors(FILE *file,
875  struct collection_item *error_list);
876 
877 
888 void print_config_parsing_errors(FILE *file,
889  struct collection_item *error_set);
890 
911 char **get_section_list(struct collection_item *ini_config,
912  int *size,
913  int *error);
914 
924 void free_section_list(char **section_list);
925 
946 char **get_attribute_list(struct collection_item *ini_config,
947  const char *section,
948  int *size,
949  int *error);
950 
960 void free_attribute_list(char **attr_list);
961 
985 int get_config_item(const char *section,
986  const char *name,
987  struct collection_item *ini_config,
988  struct collection_item **item);
989 
1030 int get_int_config_value(struct collection_item *item,
1031  int strict,
1032  int def,
1033  int *error);
1034 
1075 long get_long_config_value(struct collection_item *item,
1076  int strict,
1077  long def,
1078  int *error);
1079 
1120 unsigned get_unsigned_config_value(struct collection_item *item,
1121  int strict,
1122  unsigned def,
1123  int *error);
1124 
1165 unsigned long get_ulong_config_value(struct collection_item *item,
1166  int strict,
1167  unsigned long def,
1168  int *error);
1169 
1210 int32_t get_int32_config_value(struct collection_item *item,
1211  int strict,
1212  int32_t def,
1213  int *error);
1214 
1255 uint32_t get_uint32_config_value(struct collection_item *item,
1256  int strict,
1257  uint32_t def,
1258  int *error);
1259 
1300 int64_t get_int64_config_value(struct collection_item *item,
1301  int strict,
1302  int64_t def,
1303  int *error);
1304 
1345 uint64_t get_uint64_config_value(struct collection_item *item,
1346  int strict,
1347  uint64_t def,
1348  int *error);
1349 
1388 double get_double_config_value(struct collection_item *item,
1389  int strict,
1390  double def,
1391  int *error);
1392 
1426 unsigned char get_bool_config_value(struct collection_item *item,
1427  unsigned char def,
1428  int *error);
1429 
1453 char *get_string_config_value(struct collection_item *item,
1454  int *error);
1477 const char *get_const_string_config_value(struct collection_item *item,
1478  int *error);
1479 
1529 char *get_bin_config_value(struct collection_item *item,
1530  int *length,
1531  int *error);
1532 
1541 void free_bin_config_value(char *bin);
1542 
1597 char **get_string_config_array(struct collection_item *item,
1598  const char *sep,
1599  int *size,
1600  int *error);
1601 
1656 char **get_raw_string_config_array(struct collection_item *item,
1657  const char *sep,
1658  int *size,
1659  int *error);
1660 
1703 long *get_long_config_array(struct collection_item *item,
1704  int *size,
1705  int *error);
1706 
1748 double *get_double_config_array(struct collection_item *item,
1749  int *size,
1750  int *error);
1751 
1761 void free_string_config_array(char **str_config);
1762 
1771 void free_long_config_array(long *array);
1780 void free_double_config_array(double *array);
1781 
1782 
1787 #endif