Debian Codegraph @

ini/ini_list.c

raw symbols SCIP
1 /*
2 INI LIBRARY
3
4 Value interpretation functions for single values
5 and corresponding memory cleanup functions.
6
7 Copyright (C) Dmitri Pal <[email protected]> 2010
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 #include "config.h"
24 #include <stdio.h>
25 #include <errno.h>
26 #include "trace.h"
27 #include "collection.h"
28 #include "collection_tools.h"
29 #include "ini_config.h"
30
31
32 /* The section array should be freed using this function */
33 void free_section_list(char **section_list)
34 {
35 TRACE_FLOW_STRING("free_section_list","Entry");
36
37 col_free_property_list(section_list);
38
39 TRACE_FLOW_STRING("free_section_list","Exit");
40 }
41
42 /* The section array should be freed using this function */
43 void free_attribute_list(char **section_list)
44 {
45 TRACE_FLOW_STRING("free_attribute_list","Entry");
46
47 col_free_property_list(section_list);
48
49 TRACE_FLOW_STRING("free_attribute_list","Exit");
50 }
51
52
53 /* Get list of sections as an array of strings.
54 * Function allocates memory for the array of the sections.
55 */
56 char **get_section_list(struct collection_item *ini_config, int *size, int *error)
57 {
58 char **list;
59
60 TRACE_FLOW_STRING("get_section_list","Entry");
61 /* Do we have the item ? */
62 if ((ini_config == NULL) ||
63 ((col_is_of_class(ini_config, COL_CLASS_INI_CONFIG) == 0) &&
64 (col_is_of_class(ini_config, COL_CLASS_INI_META) == 0))) {
65 TRACE_ERROR_NUMBER("Invalid argument.", EINVAL);
66 if (error) *error = EINVAL;
67 return NULL;
68 }
69
70 /* Pass it to the function from collection API */
71 list = col_collection_to_list(ini_config, size, error);
72
73 TRACE_FLOW_STRING("get_section_list returning", ((list == NULL) ? "NULL" : list[0]));
74 return list;
75 }
76
77 /* Get list of attributes in a section as an array of strings.
78 * Function allocates memory for the array of the strings.
79 */
80 char **get_attribute_list(struct collection_item *ini_config, const char *section, int *size, int *error)
81 {
82 struct collection_item *subcollection = NULL;
83 char **list;
84 int err;
85
86 TRACE_FLOW_STRING("get_attribute_list","Entry");
87 /* Do we have the item ? */
88 if ((ini_config == NULL) ||
89 ((col_is_of_class(ini_config, COL_CLASS_INI_CONFIG) == 0) &&
90 (col_is_of_class(ini_config, COL_CLASS_INI_META) == 0)) ||
91 (section == NULL)) {
92 TRACE_ERROR_NUMBER("Invalid argument.", EINVAL);
93 if (error) *error = EINVAL;
94 return NULL;
95 }
96
97 /* Fetch section */
98 err = col_get_collection_reference(ini_config, &subcollection, section);
99 /* Check error */
100 if (err && (subcollection == NULL)) {
101 TRACE_ERROR_NUMBER("Failed to get section", err);
102 if (error) *error = EINVAL;
103 return NULL;
104 }
105
106 /* Pass it to the function from collection API */
107 list = col_collection_to_list(subcollection, size, error);
108
109 col_destroy_collection(subcollection);
110
111 TRACE_FLOW_STRING("get_attribute_list returning", ((list == NULL) ? "NULL" : list[0]));
112 return list;
113 }