summaryrefslogtreecommitdiff
path: root/common/ini
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-07-15 11:56:27 -0400
committerStephen Gallagher <sgallagh@redhat.com>2009-07-16 16:29:14 -0400
commit699f1a55fd6358f04ce90d44380f1a7cb75614b6 (patch)
tree6bf5107a2c6f3f3be8bf2671230620fa8f5ac089 /common/ini
parent735ac5cb6596ac7219881a8be1b215825de9401b (diff)
downloadsssd-699f1a55fd6358f04ce90d44380f1a7cb75614b6.tar.gz
sssd-699f1a55fd6358f04ce90d44380f1a7cb75614b6.tar.bz2
sssd-699f1a55fd6358f04ce90d44380f1a7cb75614b6.zip
INI Refactoring code a bit
The inefficient function from ini_config.c is replaced with the function provided now by the collection interface. Also the unit test is updated to run from the local directory.
Diffstat (limited to 'common/ini')
-rw-r--r--common/ini/ini_config.c44
-rw-r--r--common/ini/ini_config_ut.c14
2 files changed, 16 insertions, 42 deletions
diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c
index 4f4ac2f2..43f6d3b4 100644
--- a/common/ini/ini_config.c
+++ b/common/ini/ini_config.c
@@ -148,39 +148,6 @@ int read_line(FILE *file,
int *length,
int *ext_error);
-/* Add to collection or update - CONSIDER moving to the collection.c */
-static int add_or_update(struct collection_item *current_section,
- char *key,
- void *value,
- int length,
- int type)
-{
- int found = COL_NOMATCH;
- int error;
-
- TRACE_FLOW_STRING("add_or_update", "Entry");
-
- error = col_is_item_in_collection(current_section, key,
- COL_TYPE_ANY,
- COL_TRAVERSE_IGNORE,
- &found);
-
- if (found == COL_MATCH) {
- TRACE_INFO_STRING("Updating...", "");
- error = col_update_property(current_section,
- key, type, value, length,
- COL_TRAVERSE_IGNORE);
- }
- else {
- TRACE_INFO_STRING("Adding...", "");
- error = col_add_any_property(current_section, NULL,
- key, type, value, length);
- }
-
- TRACE_FLOW_NUMBER("add_or_update returning", error);
- return error;
-}
-
/***************************************************************************/
/* Function to read single ini file and pupulate
* the provided collection with subcollcetions from the file */
@@ -280,8 +247,15 @@ static int ini_to_collection(const char *filename,
}
/* Put value into the collection */
- error = add_or_update(current_section,
- key, value, length, COL_TYPE_STRING);
+ error = col_insert_str_property(current_section,
+ NULL,
+ COL_DSP_END,
+ NULL,
+ 0,
+ COL_INSERT_DUPOVER,
+ key,
+ value,
+ length);
if (error != EOK) {
TRACE_ERROR_NUMBER("Failed to add pair to collection", error);
fclose(file);
diff --git a/common/ini/ini_config_ut.c b/common/ini/ini_config_ut.c
index 58a5d762..7aa59405 100644
--- a/common/ini/ini_config_ut.c
+++ b/common/ini/ini_config_ut.c
@@ -34,7 +34,7 @@ int basic_test(void)
struct collection_item *ini_config = NULL;
struct collection_item *error_set = NULL;
- error = config_for_app("test", "./ini/ini.conf", "./ini/ini.d",
+ error = config_for_app("test", "./ini.conf", "./ini.d",
&ini_config, INI_STOP_ON_NONE, &error_set);
if (error) {
printf("Attempt to read configuration returned error: %d\n",error);
@@ -63,14 +63,14 @@ int single_file(void)
struct collection_item *error_set = NULL;
struct collection_item *lines = NULL;
- error = config_from_file("test", "./ini/not_exist_ini.conf",
+ error = config_from_file("test", "./not_exist_ini.conf",
&ini_config, INI_STOP_ON_NONE, &error_set);
if (error) {
printf("Attempt to read configuration returned error: %d. EXPECTED.\n\n", error);
if(error != ENOENT) return error;
}
- error = config_from_file("test", "./ini/ini.conf", &ini_config, INI_STOP_ON_NONE, &error_set);
+ error = config_from_file("test", "./ini.conf", &ini_config, INI_STOP_ON_NONE, &error_set);
if (error) {
printf("Attempt to read configuration returned error: %d\n",error);
return error;
@@ -94,7 +94,7 @@ int single_file(void)
printf("TEST WITH LINES\n");
- error = config_from_file_with_lines("test", "./ini/ini.conf",
+ error = config_from_file_with_lines("test", "./ini.conf",
&ini_config, INI_STOP_ON_NONE,
&error_set, &lines);
if (error) {
@@ -176,7 +176,7 @@ int real_test(const char *file)
printf("\n\n===== REAL TEST START ======\n");
printf("Reading collection\n");
- error = config_for_app("real", file, "./ini/ini.d",
+ error = config_for_app("real", file, "./ini.d",
&ini_config, INI_STOP_ON_NONE, &error_set);
if (error) {
printf("Attempt to read configuration returned error: %d\n", error);
@@ -269,7 +269,7 @@ int get_test(void)
printf("\n\n===== GET TEST START ======\n");
printf("Reading collection\n");
- error = config_for_app("real", NULL, "./ini/ini.d",
+ error = config_for_app("real", NULL, "./ini.d",
&ini_config, INI_STOP_ON_NONE, &error_set);
if (error) {
printf("Attempt to read configuration returned error: %d\n", error);
@@ -805,7 +805,7 @@ int main(int argc, char *argv[])
(error = single_file()) ||
(error = real_test(NULL)) ||
/* This should result in merged configuration */
- (error = real_test("./ini/ini.conf")) ||
+ (error = real_test("./ini.conf")) ||
(error = get_test())) {
printf("Test failed! Error %d.\n", error);
return -1;