summaryrefslogtreecommitdiff
path: root/common/ini
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-07-02 19:22:33 -0400
committerStephen Gallagher <sgallagh@redhat.com>2009-07-02 20:02:34 -0400
commitaf6b9f749f3f9ade3727bb0b43baffbdbd26cdcb (patch)
tree333b6d40428e45c62fbb7d111939363a7786f853 /common/ini
parent09c4b073ca0bdf8d208cbcc7e84a7d33629213d2 (diff)
downloadsssd-af6b9f749f3f9ade3727bb0b43baffbdbd26cdcb.tar.gz
sssd-af6b9f749f3f9ade3727bb0b43baffbdbd26cdcb.tar.bz2
sssd-af6b9f749f3f9ade3727bb0b43baffbdbd26cdcb.zip
Adding wrappers to free data in INI API.
See ticket #37 in sssd track.
Diffstat (limited to 'common/ini')
-rw-r--r--common/ini/ini_config.c24
-rw-r--r--common/ini/ini_config.h9
-rw-r--r--common/ini/ini_config_ut.c116
3 files changed, 91 insertions, 58 deletions
diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c
index 1d318db9..9b23c94c 100644
--- a/common/ini/ini_config.c
+++ b/common/ini/ini_config.c
@@ -415,6 +415,30 @@ static int ini_to_collection(const char *filename,
}
/*********************************************************************/
+/* Function to free configuration */
+void free_ini_config(struct collection_item *ini_config)
+{
+ TRACE_FLOW_STRING("free_ini_config", "Entry");
+ col_destroy_collection(ini_config);
+ TRACE_FLOW_STRING("free_ini_config", "Exit");
+}
+
+/* Function to free configuration error list */
+void free_ini_config_errors(struct collection_item *error_set)
+{
+ TRACE_FLOW_STRING("free_ini_config_errors", "Entry");
+ col_destroy_collection(error_set);
+ TRACE_FLOW_STRING("free_ini_config_errors", "Exit");
+}
+
+/* Function to free configuration lines list */
+void free_ini_config_lines(struct collection_item *lines)
+{
+ TRACE_FLOW_STRING("free_ini_config_lines", "Entry");
+ col_destroy_collection(lines);
+ TRACE_FLOW_STRING("free_ini_config_lines", "Exit");
+}
+
/* Read configuration information from a file */
int config_from_file(const char *application,
const char *config_file,
diff --git a/common/ini/ini_config.h b/common/ini/ini_config.h
index fdf35438..46e83d1c 100644
--- a/common/ini/ini_config.h
+++ b/common/ini/ini_config.h
@@ -122,6 +122,15 @@ int config_for_app(const char *application, /* Name of the applica
int error_level, /* Level of error tolerance */
struct collection_item **error_set); /* Collection of collections of parsing errors */
+/* Function to free configuration */
+void free_ini_config(struct collection_item *ini_config);
+
+/* Function to free configuration error list */
+void free_ini_config_errors(struct collection_item *error_set);
+
+/* Function to free configuration line list */
+void free_ini_config_lines(struct collection_item *lines);
+
/* Print errors and warnings that were detected while parsing one file */
/* Use this function to print results of the config_from_file() call */
void print_file_parsing_errors(FILE *file, /* File to send errors to */
diff --git a/common/ini/ini_config_ut.c b/common/ini/ini_config_ut.c
index ce379211..24912738 100644
--- a/common/ini/ini_config_ut.c
+++ b/common/ini/ini_config_ut.c
@@ -51,8 +51,8 @@ int basic_test()
printf("----------------------\n\n\n");
- col_destroy_collection(ini_config);
- col_destroy_collection(error_set);
+ free_ini_config(ini_config);
+ free_ini_config_errors(error_set);
return 0;
}
@@ -86,8 +86,8 @@ int single_file()
printf("----------------------\n\n\n");
- col_destroy_collection(ini_config);
- col_destroy_collection(error_set);
+ free_ini_config(ini_config);
+ free_ini_config_errors(error_set);
ini_config = NULL;
error_set = NULL;
@@ -111,9 +111,9 @@ int single_file()
printf("----------------------\n\n\n");
- col_destroy_collection(ini_config);
- col_destroy_collection(error_set);
- col_destroy_collection(lines);
+ free_ini_config(ini_config);
+ free_ini_config_errors(error_set);
+ free_ini_config_lines(lines);
return 0;
}
@@ -160,7 +160,7 @@ int negative_test()
return -1;
}
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return 0;
}
@@ -236,8 +236,8 @@ int real_test(const char *file)
printf("About to clean up.\n");
col_unbind_iterator(iterator);
- col_destroy_collection(ini_config);
- col_destroy_collection(error_set);
+ free_ini_config(ini_config);
+ free_ini_config_errors(error_set);
return 0;
}
@@ -280,7 +280,7 @@ int get_test()
col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT);
printf("Debugging the error collection:\n");
col_debug_collection(error_set, COL_TRAVERSE_DEFAULT);
- col_destroy_collection(error_set);
+ free_ini_config_errors(error_set);
printf("Negtive test - trying to get non existing key-value pair.\n");
@@ -289,14 +289,14 @@ int get_test()
error = get_config_item("monitor1", "description1", ini_config, &item);
if (error) {
printf("Expected success but got error! %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should not be found */
if (item != (struct collection_item *)(NULL)) {
printf("Expected NULL but got something else!\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -305,14 +305,14 @@ int get_test()
error = get_config_item("monitor", "description1", ini_config, &item);
if (error) {
printf("Expected success but got error! %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should not be found */
if(item != (struct collection_item *)(NULL)) {
printf("Expected NULL but got something else!\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -323,14 +323,14 @@ int get_test()
error = get_config_item("monitor", "description", ini_config, &item);
if (error) {
printf("Expected success but got error! %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should be found */
if (item == (struct collection_item *)(NULL)) {
printf("Expected item but got something NULL!\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -343,7 +343,7 @@ int get_test()
cstrn = get_const_string_config_value(NULL, NULL);
if (cstrn != NULL) {
printf("Expected error got success.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -354,7 +354,7 @@ int get_test()
cstr = get_const_string_config_value(item, &error);
if (error) {
printf("Expected success got error %d.\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
@@ -368,7 +368,7 @@ int get_test()
str = get_string_config_value(item, &error);
if (error) {
printf("Expected success got error %d.\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
@@ -383,14 +383,14 @@ int get_test()
error = get_config_item("monitor", "bad_number", ini_config, &item);
if (error) {
printf("Expected success but got error! %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should be found */
if (item == (struct collection_item *)(NULL)) {
printf("Expected item but got something NULL!\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -405,7 +405,7 @@ int get_test()
printf("Expected error.\n");
if(number != 10) {
printf("It failed to set default value.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
}
@@ -418,14 +418,14 @@ int get_test()
if (error) {
/* We expected error in this case */
printf("Did not expect error.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
if (number != 5) {
/* We expected error in this case */
printf("We expected that the conversion will return 5.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -437,14 +437,14 @@ int get_test()
error = get_config_item("domains/LOCAL","enumerate", ini_config, &item);
if (error) {
printf("Expected success but got error! %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should be found */
if (item == (struct collection_item *)(NULL)) {
printf("Expected success but got NULL.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -455,14 +455,14 @@ int get_test()
number = get_int_config_value(item, 1, 100, &error);
if (error) {
printf("Did not expect error. Got %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* It is 3 in the file */
if (number != 3) {
printf("We expected that the conversion will return 3.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -475,14 +475,14 @@ int get_test()
number_long = get_long_config_value(item, 1, 100, &error);
if (error) {
printf("Did not expect error. Got %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* It is 3 in the file */
if (number_long != 3) {
printf("We expected that the conversion will return 3.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -495,14 +495,14 @@ int get_test()
number_unsigned = get_unsigned_config_value(item, 1, 100, &error);
if (error) {
printf("Did not expect error. Got %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* It is 3 in the file */
if(number_unsigned != 3) {
printf("We expected that the conversion will return 3.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -515,14 +515,14 @@ int get_test()
number_ulong = get_ulong_config_value(item, 1, 100, &error);
if (error) {
printf("Did not expect error. Got %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* It is 3 in the file */
if (number_ulong != 3) {
printf("We expected that the conversion will return 3.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -535,14 +535,14 @@ int get_test()
number_double = get_double_config_value(item, 1, 100., &error);
if (error) {
printf("Did not expect error. Got %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* It is 3 in the file */
if (number_double != 3.) {
printf("We expected that the conversion will return 3.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -555,7 +555,7 @@ int get_test()
logical = get_bool_config_value(item, 1, &error);
if (!error) {
printf("Expect error. Got success.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -566,14 +566,14 @@ int get_test()
error = get_config_item("domains/LOCAL","legacy", ini_config, &item);
if (error) {
printf("Expected success but got error! %d\n",error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should be found */
if (item == (struct collection_item *)(NULL)) {
printf("Expected success but got NULL.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -583,7 +583,7 @@ int get_test()
logical = get_bool_config_value(item, 1, &error);
if (error) {
printf("Expect success got error %d.\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
@@ -600,14 +600,14 @@ int get_test()
error = get_config_item("domains/EXAMPLE.COM","binary_test", ini_config, &item);
if (error) {
printf("Expected success but got error! %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should be found */
if (item == (struct collection_item *)(NULL)) {
printf("Expected success but got NULL.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -617,7 +617,7 @@ int get_test()
binary = get_bin_config_value(item, &length, &error);
if (error) {
printf("Expect success got error %d.\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
@@ -635,14 +635,14 @@ int get_test()
error = get_config_item("domains", "domainsorder", ini_config, &item);
if(error) {
printf("Expected success but got error! %d\n",error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should be found */
if (item == (struct collection_item *)(NULL)) {
printf("Expected success but got NULL.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -654,7 +654,7 @@ int get_test()
strarray = get_string_config_array(item, ",", NULL, &error);
if (error) {
printf("Expect success got error %d.\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
@@ -674,7 +674,7 @@ int get_test()
strarray = get_string_config_array(item, ",", &size, &error);
if (error) {
printf("Expect success got error %d.\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
@@ -689,14 +689,14 @@ int get_test()
error = get_config_item("domains/EXAMPLE.COM", "long_array", ini_config, &item);
if(error) {
printf("Expected success but got error! %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should be found */
if (item == (struct collection_item *)(NULL)) {
printf("Expected success but got NULL.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -707,7 +707,7 @@ int get_test()
array = get_long_config_array(item, &size, &error);
if(error) {
printf("Expect success got error %d.\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
@@ -722,14 +722,14 @@ int get_test()
error = get_config_item("domains/EXAMPLE.COM", "double_array", ini_config, &item);
if (error) {
printf("Expected success but got error! %d\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
/* Item should be found */
if (item == (struct collection_item *)(NULL)) {
printf("Expected success but got NULL.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -740,7 +740,7 @@ int get_test()
darray = get_double_config_array(item, &size, &error);
if (error) {
printf("Expect success got error %d.\n", error);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return error;
}
@@ -755,7 +755,7 @@ int get_test()
prop_array = get_section_list(ini_config, NULL, NULL);
if (prop_array == NULL) {
printf("Expect success got error.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -772,7 +772,7 @@ int get_test()
prop_array = get_section_list(ini_config, &size, NULL);
if (prop_array == NULL) {
printf("Expect success got error.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
@@ -785,14 +785,14 @@ int get_test()
prop_array = get_attribute_list(ini_config, "domains/EXAMPLE.COM", &size, &error);
if (prop_array == NULL) {
printf("Expect success got error.\n");
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
return -1;
}
for (i=0;i<size;i++) printf("Attribute: [%s]\n", prop_array[i]);
free_attribute_list(prop_array);
- col_destroy_collection(ini_config);
+ free_ini_config(ini_config);
printf("Done with get test!\n");
return EOK;
}