summaryrefslogtreecommitdiffstats
path: root/common/ini/ini_config.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-04-10 11:30:59 -0400
committerSimo Sorce <ssorce@redhat.com>2009-04-10 16:59:24 -0400
commit24967bd826ad5437a11b1431c8289b1881b52a17 (patch)
tree2bd20ac84fcba597abc0e492e23ccebb3940b340 /common/ini/ini_config.c
parentbaf568c235c4f8e6e733c47bc0c76bf84b55b9b0 (diff)
downloadsssd-24967bd826ad5437a11b1431c8289b1881b52a17.tar.gz
sssd-24967bd826ad5437a11b1431c8289b1881b52a17.tar.xz
sssd-24967bd826ad5437a11b1431c8289b1881b52a17.zip
Added functions to create list of sections and attributes.
Diffstat (limited to 'common/ini/ini_config.c')
-rw-r--r--common/ini/ini_config.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c
index b4b4b25fd..8d19b272c 100644
--- a/common/ini/ini_config.c
+++ b/common/ini/ini_config.c
@@ -1443,3 +1443,82 @@ inline void free_double_config_array(double *array)
{
if (array != NULL) free(array);
}
+
+/* The section array should be freed using this function */
+inline void free_section_list(char **section_list)
+{
+ TRACE_FLOW_STRING("free_section_list","Entry");
+
+ free_property_list(section_list);
+
+ TRACE_FLOW_STRING("free_section_list","Exit");
+}
+
+/* The section array should be freed using this function */
+inline void free_attribute_list(char **section_list)
+{
+ TRACE_FLOW_STRING("free_section_list","Entry");
+
+ free_property_list(section_list);
+
+ TRACE_FLOW_STRING("free_section_list","Exit");
+}
+
+
+/* Get list of sections as an array of strings.
+ * Function allocates memory for the array of the sections.
+ */
+char **get_section_list(struct collection_item *ini_config, int *size, int *error)
+{
+ char **list;
+
+ TRACE_FLOW_STRING("get_section_list","Entry");
+ /* Do we have the item ? */
+ if ((ini_config == NULL) ||
+ !is_of_class(ini_config, COL_CLASS_INI_CONFIG)) {
+ TRACE_ERROR_NUMBER("Invalid argument.", EINVAL);
+ if (error) *error = EINVAL;
+ return NULL;
+ }
+
+ /* Pass it to the function from collection API */
+ list = collection_to_list(ini_config, size, error);
+
+ TRACE_FLOW_STRING("get_section_list returning", list == NULL ? "NULL" : list[0]);
+ return list;
+}
+
+/* Get list of attributes in a section as an array of strings.
+ * Function allocates memory for the array of the strings.
+ */
+char **get_attribute_list(struct collection_item *ini_config, const char *section, int *size, int *error)
+{
+ struct collection_item *subcollection = NULL;
+ char **list;
+ int err;
+
+ TRACE_FLOW_STRING("get_attribute_list","Entry");
+ /* Do we have the item ? */
+ if ((ini_config == NULL) ||
+ !is_of_class(ini_config, COL_CLASS_INI_CONFIG) ||
+ (section == NULL)) {
+ TRACE_ERROR_NUMBER("Invalid argument.", EINVAL);
+ if (error) *error = EINVAL;
+ return NULL;
+ }
+
+ /* Fetch section */
+ err = get_collection_reference(ini_config, &subcollection, section);
+ /* Check error */
+ if (err && (subcollection == NULL)) {
+ TRACE_ERROR_NUMBER("Failed to get section", err);
+ if (error) *error = EINVAL;
+ return NULL;
+ }
+
+ /* Pass it to the function from collection API */
+ list = collection_to_list(subcollection, size, error);
+
+ TRACE_FLOW_STRING("get_attribute_list returning", list == NULL ? "NULL" : list[0]);
+ return list;
+}