summaryrefslogtreecommitdiffstats
path: root/common/ini/ini_config.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-07-17 19:22:13 -0400
committerSimo Sorce <ssorce@redhat.com>2009-07-20 10:50:51 -0400
commite519ed7c7f203a6a95e58b7e770253c093d2dec6 (patch)
tree432b4e983ae6bc3df72bec4fdaade59dd8d2cb58 /common/ini/ini_config.c
parentc0a1d64228042c3d4bbf62447a49d085fd30fda1 (diff)
downloadsssd-e519ed7c7f203a6a95e58b7e770253c093d2dec6.tar.gz
sssd-e519ed7c7f203a6a95e58b7e770253c093d2dec6.tar.xz
sssd-e519ed7c7f203a6a95e58b7e770253c093d2dec6.zip
COLLECTION & INI Cleanup
I started to cleanup the unit tests from the type cust around NULL and found several problems that I had to address: 1) The choice of the "." as a search separator turned out to be a poor choice. The problem was that the file name has "." and INI was relaying on files to be used as property names. I corrected that part in the INI but after discussion with Simo we decided to switch from "." to "!" as special symbol anyways. 2) Found that the property rename was not reinitializing the hash. Corrected. Added ticket to add unit tests around it (#83).
Diffstat (limited to 'common/ini/ini_config.c')
-rw-r--r--common/ini/ini_config.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c
index 43f6d3b41..e4b1f3655 100644
--- a/common/ini/ini_config.c
+++ b/common/ini/ini_config.c
@@ -73,6 +73,9 @@
#define RET_EOF 5
#define RET_ERROR 6
+#define INI_ERROR "errors"
+#define INI_ERROR_NAME "errname"
+
/* Different error string functions can be passed as callbacks */
typedef const char * (*error_fn)(int error);
@@ -175,7 +178,7 @@ static int ini_to_collection(const char *filename,
TRACE_FLOW_STRING("ini_to_collection", "Entry");
/* Open file for reading */
- file = fopen(filename,"r");
+ file = fopen(filename, "r");
if (file == NULL) {
error = errno;
TRACE_ERROR_NUMBER("Failed to open file - but this is OK", error);
@@ -185,12 +188,20 @@ static int ini_to_collection(const char *filename,
/* Open the collection of errors */
if (error_list != NULL) {
*error_list = NULL;
- error = col_create_collection(error_list, filename, COL_CLASS_INI_PERROR);
+ error = col_create_collection(error_list, INI_ERROR, COL_CLASS_INI_PERROR);
if (error) {
TRACE_ERROR_NUMBER("Failed to create error collection", error);
fclose(file);
return error;
}
+ /* Add file name as the first item */
+ error = col_add_str_property(*error_list, NULL, INI_ERROR_NAME, filename, 0);
+ if (error) {
+ TRACE_ERROR_NUMBER("Failed to and name to collection", error);
+ fclose(file);
+ col_destroy_collection(*error_list);
+ return error;
+ }
created = 1;
}
@@ -891,9 +902,9 @@ static void print_error_list(FILE *file,
/* Process collection header */
if (col_get_item_type(item) == COL_TYPE_COLLECTION) {
col_get_collection_count(item, &count);
- if (count > 1)
- fprintf(file, error_header, col_get_item_property(item, NULL));
- else break;
+ if (count <= 2) break;
+ } else if (col_get_item_type(item) == COL_TYPE_STRING) {
+ fprintf(file, error_header, (char *)col_get_item_data(item));
}
else {
/* Put error into provided format */
@@ -1009,6 +1020,7 @@ void print_config_parsing_errors(FILE *file,
if (error) {
TRACE_ERROR_STRING("Error (extract):", FAILED_TO_PROCCESS);
fprintf(file, "%s\n", FAILED_TO_PROCCESS);
+ col_unbind_iterator(iterator);
return;
}
print_file_parsing_errors(file, file_errors);