From 09c4b073ca0bdf8d208cbcc7e84a7d33629213d2 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Thu, 2 Jul 2009 12:52:32 -0400 Subject: Changing function names for collection API. Patch prepends prefix "col_" to all functions related to collection. This caused some formatiing issues so the alignement was addressed too. --- common/ini/ini_config.c | 274 +++++++++++++++++++++++---------------------- common/ini/ini_config_ut.c | 176 ++++++++++++++--------------- 2 files changed, 226 insertions(+), 224 deletions(-) (limited to 'common/ini') diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c index 8c54ad5cc..1d318db9c 100644 --- a/common/ini/ini_config.c +++ b/common/ini/ini_config.c @@ -160,19 +160,21 @@ static int add_or_update(struct collection_item *current_section, TRACE_FLOW_STRING("add_or_update", "Entry"); - error = is_item_in_collection(current_section, key, - COL_TYPE_ANY, COL_TRAVERSE_IGNORE, &found); + 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 = update_property(current_section, - key, type, value, length, - COL_TRAVERSE_IGNORE); + error = col_update_property(current_section, + key, type, value, length, + COL_TRAVERSE_IGNORE); } else { TRACE_INFO_STRING("Adding...", ""); - error = add_any_property(current_section, NULL, - key, type, value, length); + error = col_add_any_property(current_section, NULL, + key, type, value, length); } TRACE_FLOW_NUMBER("add_or_update returning", error); @@ -216,7 +218,7 @@ static int ini_to_collection(const char *filename, /* Open the collection of errors */ if (error_list != NULL) { *error_list = NULL; - error = create_collection(error_list, filename, COL_CLASS_INI_PERROR); + error = col_create_collection(error_list, filename, COL_CLASS_INI_PERROR); if (error) { TRACE_ERROR_NUMBER("Failed to create error collection", error); fclose(file); @@ -237,13 +239,13 @@ static int ini_to_collection(const char *filename, case RET_PAIR: /* Add line to the collection of lines */ if (lines) { - error = add_int_property(*lines, NULL, key, line); + error = col_add_int_property(*lines, NULL, key, line); if (error) { TRACE_ERROR_NUMBER("Failed to add line to line collection", error); fclose(file); - destroy_collection(current_section); + col_destroy_collection(current_section); if (created) { - destroy_collection(*error_list); + col_destroy_collection(*error_list); *error_list = NULL; } return error; @@ -253,22 +255,22 @@ static int ini_to_collection(const char *filename, /* Do we have a section at the top of the file ? */ if (section_count == 0) { /* Check if collection already exists */ - error = get_collection_reference(ini_config, ¤t_section, - INI_DEFAULT_SECTION); + error = col_get_collection_reference(ini_config, ¤t_section, + INI_DEFAULT_SECTION); if (error != EOK) { /* Create default collection */ - if ((error = create_collection(¤t_section, - INI_DEFAULT_SECTION, - COL_CLASS_INI_SECTION)) || - (error = add_collection_to_collection(ini_config, - NULL,NULL, - current_section, - COL_ADD_MODE_REFERENCE))) { + if ((error = col_create_collection(¤t_section, + INI_DEFAULT_SECTION, + COL_CLASS_INI_SECTION)) || + (error = col_add_collection_to_collection(ini_config, + NULL,NULL, + current_section, + COL_ADD_MODE_REFERENCE))) { TRACE_ERROR_NUMBER("Failed to create collection", error); fclose(file); - destroy_collection(current_section); + col_destroy_collection(current_section); if (created) { - destroy_collection(*error_list); + col_destroy_collection(*error_list); *error_list = NULL; } return error; @@ -283,9 +285,9 @@ static int ini_to_collection(const char *filename, if (error != EOK) { TRACE_ERROR_NUMBER("Failed to add pair to collection", error); fclose(file); - destroy_collection(current_section); + col_destroy_collection(current_section); if (created) { - destroy_collection(*error_list); + col_destroy_collection(*error_list); *error_list = NULL; } return error; @@ -298,13 +300,13 @@ static int ini_to_collection(const char *filename, /* For easier search make line numbers for the sections negative. * This would allow differentiating sections and attributes. */ - error = add_int_property(*lines, NULL, key, -1 * line); + error = col_add_int_property(*lines, NULL, key, -1 * line); if (error) { TRACE_ERROR_NUMBER("Failed to add line to line collection", error); fclose(file); - destroy_collection(current_section); + col_destroy_collection(current_section); if (created) { - destroy_collection(*error_list); + col_destroy_collection(*error_list); *error_list = NULL; } return error; @@ -312,23 +314,23 @@ static int ini_to_collection(const char *filename, } /* Read a new section */ - destroy_collection(current_section); + col_destroy_collection(current_section); current_section = NULL; - error = get_collection_reference(ini_config, ¤t_section, key); + error = col_get_collection_reference(ini_config, ¤t_section, key); if (error != EOK) { /* Create default collection */ - if ((error = create_collection(¤t_section, key, - COL_CLASS_INI_SECTION)) || - (error = add_collection_to_collection(ini_config, - NULL, NULL, - current_section, - COL_ADD_MODE_REFERENCE))) { + if ((error = col_create_collection(¤t_section, key, + COL_CLASS_INI_SECTION)) || + (error = col_add_collection_to_collection(ini_config, + NULL, NULL, + current_section, + COL_ADD_MODE_REFERENCE))) { TRACE_ERROR_NUMBER("Failed to add collection", error); fclose(file); - destroy_collection(current_section); + col_destroy_collection(current_section); if (created) { - destroy_collection(*error_list); + col_destroy_collection(*error_list); *error_list = NULL; } return error; @@ -348,14 +350,14 @@ static int ini_to_collection(const char *filename, case RET_ERROR: pe.line = line; pe.error = ext_err; - error = add_binary_property(*error_list, NULL, - ERROR_TXT, &pe, sizeof(pe)); + error = col_add_binary_property(*error_list, NULL, + ERROR_TXT, &pe, sizeof(pe)); if (error) { TRACE_ERROR_NUMBER("Failed to add error to collection", error); fclose(file); - destroy_collection(current_section); + col_destroy_collection(current_section); if (created) { - destroy_collection(*error_list); + col_destroy_collection(*error_list); *error_list = NULL; } return error; @@ -363,7 +365,7 @@ static int ini_to_collection(const char *filename, /* Exit if there was an error parsing file */ if (error_level != INI_STOP_ON_NONE) { TRACE_ERROR_STRING("Invalid format of the file", ""); - destroy_collection(current_section); + col_destroy_collection(current_section); fclose(file); return EIO; } @@ -373,14 +375,14 @@ static int ini_to_collection(const char *filename, default: pe.line = line; pe.error = ext_err; - error = add_binary_property(*error_list, NULL, - WARNING_TXT, &pe, sizeof(pe)); + error = col_add_binary_property(*error_list, NULL, + WARNING_TXT, &pe, sizeof(pe)); if (error) { TRACE_ERROR_NUMBER("Failed to add warning to collection", error); fclose(file); - destroy_collection(current_section); + col_destroy_collection(current_section); if (created) { - destroy_collection(*error_list); + col_destroy_collection(*error_list); *error_list = NULL; } return error; @@ -388,7 +390,7 @@ static int ini_to_collection(const char *filename, /* Exit if we are told to exit on warnings */ if (error_level == INI_STOP_ON_ANY) { TRACE_ERROR_STRING("Invalid format of the file", ""); - if (created) destroy_collection(current_section); + if (created) col_destroy_collection(current_section); fclose(file); return EIO; } @@ -401,11 +403,11 @@ static int ini_to_collection(const char *filename, /* Close file */ fclose(file); - DEBUG_COLLECTION(ini_config); + COL_DEBUG_COLLECTION(ini_config); - destroy_collection(current_section); + col_destroy_collection(current_section); - DEBUG_COLLECTION(ini_config); + COL_DEBUG_COLLECTION(ini_config); TRACE_FLOW_STRING("ini_to_collection", "Success Exit"); @@ -457,9 +459,9 @@ int config_from_file_with_lines(const char *application, /* Create collection if needed */ if (*ini_config == NULL) { - error = create_collection(ini_config, - application, - COL_CLASS_INI_CONFIG); + error = col_create_collection(ini_config, + application, + COL_CLASS_INI_CONFIG); if (error != EOK) { TRACE_ERROR_NUMBER("Failed to create collection", error); return error; @@ -467,7 +469,7 @@ int config_from_file_with_lines(const char *application, created = 1; } /* Is the collection of the right class? */ - else if (is_of_class(*ini_config, COL_CLASS_INI_CONFIG)) { + else if (col_is_of_class(*ini_config, COL_CLASS_INI_CONFIG)) { TRACE_ERROR_NUMBER("Wrong collection type", EINVAL); return EINVAL; } @@ -480,19 +482,19 @@ int config_from_file_with_lines(const char *application, if (*lines) { TRACE_ERROR_NUMBER("Collection of lines is not empty", EINVAL); if (created) { - destroy_collection(*ini_config); + col_destroy_collection(*ini_config); *ini_config = NULL; } return EINVAL; } - error = create_collection(lines, - application, - COL_CLASS_INI_LINES); + error = col_create_collection(lines, + application, + COL_CLASS_INI_LINES); if (error != EOK) { TRACE_ERROR_NUMBER("Failed to create collection", error); if (created) { - destroy_collection(*ini_config); + col_destroy_collection(*ini_config); *ini_config = NULL; } return error; @@ -505,12 +507,12 @@ int config_from_file_with_lines(const char *application, error_level, error_list, lines); /* In case of error when we created collection - delete it */ if (error && created) { - destroy_collection(*ini_config); + col_destroy_collection(*ini_config); *ini_config = NULL; } /* Also create collection of lines if we created it */ if (error && created_lines) { - destroy_collection(*lines); + col_destroy_collection(*lines); *lines = NULL; } @@ -549,9 +551,9 @@ int config_for_app(const char *application, pass_specific = &error_list_specific; *error_set = NULL; /* Construct the overarching error collection */ - error = create_collection(error_set, - FILE_ERROR_SET, - COL_CLASS_INI_PESET); + error = col_create_collection(error_set, + FILE_ERROR_SET, + COL_CLASS_INI_PESET); if (error != EOK) { TRACE_ERROR_NUMBER("Failed to create collection", error); return error; @@ -566,18 +568,18 @@ int config_for_app(const char *application, /* Create collection if needed */ if (*ini_config == NULL) { TRACE_INFO_STRING("New config collection. Allocate.", ""); - error = create_collection(ini_config, - application, - COL_CLASS_INI_CONFIG); + error = col_create_collection(ini_config, + application, + COL_CLASS_INI_CONFIG); if (error != EOK) { TRACE_ERROR_NUMBER("Failed to create collection", error); - destroy_collection(*error_set); + col_destroy_collection(*error_set); *error_set = NULL; return error; } } /* Is the collection of the right class? */ - else if (is_of_class(*ini_config, COL_CLASS_INI_CONFIG)) { + else if (col_is_of_class(*ini_config, COL_CLASS_INI_CONFIG)) { TRACE_ERROR_NUMBER("Wrong collection type", EINVAL); return EINVAL; } @@ -592,7 +594,7 @@ int config_for_app(const char *application, TRACE_ERROR_NUMBER("Failed to read master file", error); /* In case of error when we created collection - delete it */ if(error && created) { - destroy_collection(*ini_config); + col_destroy_collection(*ini_config); *ini_config = NULL; } /* We do not clear the error_set here */ @@ -601,15 +603,15 @@ int config_for_app(const char *application, /* Add error results if any to the overarching error collection */ if ((pass_common != NULL) && (*pass_common != NULL)) { TRACE_INFO_STRING("Process erros resulting from file:", config_file); - error = add_collection_to_collection(*error_set, NULL, NULL, - *pass_common, - COL_ADD_MODE_EMBED); + error = col_add_collection_to_collection(*error_set, NULL, NULL, + *pass_common, + COL_ADD_MODE_EMBED); if (error) { if (created) { - destroy_collection(*ini_config); + col_destroy_collection(*ini_config); *ini_config = NULL; } - destroy_collection(*error_set); + col_destroy_collection(*error_set); *error_set = NULL; TRACE_ERROR_NUMBER("Failed to add error collection to another error collection", error); return error; @@ -625,10 +627,10 @@ int config_for_app(const char *application, TRACE_ERROR_NUMBER("Failed to allocate memory for file name", error); /* In case of error when we created collection - delete it */ if(error && created) { - destroy_collection(*ini_config); + col_destroy_collection(*ini_config); *ini_config = NULL; } - destroy_collection(*error_set); + col_destroy_collection(*error_set); *error_set = NULL; return error; } @@ -645,7 +647,7 @@ int config_for_app(const char *application, TRACE_ERROR_NUMBER("Failed to read specific application file", error); /* In case of error when we created collection - delete it */ if (error && created) { - destroy_collection(*ini_config); + col_destroy_collection(*ini_config); *ini_config = NULL; } /* We do not clear the error_set here */ @@ -655,15 +657,15 @@ int config_for_app(const char *application, /* Add error results if any to the overarching error collection */ if ((pass_specific != NULL) && (*pass_specific != NULL)) { TRACE_INFO_STRING("Process erros resulting from file:", file_name); - error = add_collection_to_collection(*error_set, NULL, NULL, - *pass_specific, - COL_ADD_MODE_EMBED); + error = col_add_collection_to_collection(*error_set, NULL, NULL, + *pass_specific, + COL_ADD_MODE_EMBED); if (error) { if (created) { - destroy_collection(*ini_config); + col_destroy_collection(*ini_config); *ini_config = NULL; } - destroy_collection(*error_set); + col_destroy_collection(*error_set); *error_set = NULL; TRACE_ERROR_NUMBER("Failed to add error collection to another error collection", error); return error; @@ -861,14 +863,14 @@ static void print_error_list(FILE *file, } /* Make sure we go the right collection */ - if (!is_of_class(error_list, cclass)) { + if (!col_is_of_class(error_list, cclass)) { TRACE_ERROR_STRING("Wrong collection class:", wrong_col_error); fprintf(file,"%s\n", wrong_col_error); return; } /* Bind iterator */ - error = bind_iterator(&iterator, error_list, COL_TRAVERSE_DEFAULT); + error = col_bind_iterator(&iterator, error_list, COL_TRAVERSE_DEFAULT); if (error) { TRACE_ERROR_STRING("Error (bind):", failed_to_process); fprintf(file, "%s\n", failed_to_process); @@ -877,11 +879,11 @@ static void print_error_list(FILE *file, while(1) { /* Loop through a collection */ - error = iterate_collection(iterator, &item); + error = col_iterate_collection(iterator, &item); if (error) { TRACE_ERROR_STRING("Error (iterate):", failed_to_process); fprintf(file, "%s\n", failed_to_process); - unbind_iterator(iterator); + col_unbind_iterator(iterator); return; } @@ -889,17 +891,17 @@ static void print_error_list(FILE *file, if (item == NULL) break; /* Process collection header */ - if (get_item_type(item) == COL_TYPE_COLLECTION) { - get_collection_count(item, &count); + if (col_get_item_type(item) == COL_TYPE_COLLECTION) { + col_get_collection_count(item, &count); if (count > 1) - fprintf(file, error_header, get_item_property(item, NULL)); + fprintf(file, error_header, col_get_item_property(item, NULL)); else break; } else { /* Put error into provided format */ - pe = (struct parse_error *)(get_item_data(item)); + pe = (struct parse_error *)(col_get_item_data(item)); fprintf(file, line_format, - get_item_property(item, NULL), /* Error or warning */ + col_get_item_property(item, NULL), /* Error or warning */ pe->error, /* Error */ pe->line, /* Line */ error_function(pe->error)); /* Error str */ @@ -908,7 +910,7 @@ static void print_error_list(FILE *file, } /* Do not forget to unbind iterator - otherwise there will be a leak */ - unbind_iterator(iterator); + col_unbind_iterator(iterator); TRACE_FLOW_STRING("print_error_list", "Exit"); } @@ -975,14 +977,14 @@ void print_config_parsing_errors(FILE *file, } /* Make sure we go the right collection */ - if (!is_of_class(error_list, COL_CLASS_INI_PESET)) { + if (!col_is_of_class(error_list, COL_CLASS_INI_PESET)) { TRACE_ERROR_STRING("Wrong collection class:", WRONG_COLLECTION); fprintf(file, "%s\n", WRONG_COLLECTION); return; } /* Bind iterator */ - error = bind_iterator(&iterator, error_list, COL_TRAVERSE_DEFAULT); + error = col_bind_iterator(&iterator, error_list, COL_TRAVERSE_DEFAULT); if (error) { TRACE_ERROR_STRING("Error (bind):", FAILED_TO_PROCCESS); fprintf(file,"%s\n", FAILED_TO_PROCCESS); @@ -991,11 +993,11 @@ void print_config_parsing_errors(FILE *file, while(1) { /* Loop through a collection */ - error = iterate_collection(iterator, &item); + error = col_iterate_collection(iterator, &item); if (error) { TRACE_ERROR_STRING("Error (iterate):", FAILED_TO_PROCCESS); fprintf(file, "%s\n", FAILED_TO_PROCCESS); - unbind_iterator(iterator); + col_unbind_iterator(iterator); return; } @@ -1003,21 +1005,21 @@ void print_config_parsing_errors(FILE *file, if (item == NULL) break; /* Print per file sets of errors */ - if (get_item_type(item) == COL_TYPE_COLLECTIONREF) { + if (col_get_item_type(item) == COL_TYPE_COLLECTIONREF) { /* Extract a sub collection */ - error = get_reference_from_item(item, &file_errors); + error = col_get_reference_from_item(item, &file_errors); if (error) { TRACE_ERROR_STRING("Error (extract):", FAILED_TO_PROCCESS); fprintf(file, "%s\n", FAILED_TO_PROCCESS); return; } print_file_parsing_errors(file, file_errors); - destroy_collection(file_errors); + col_destroy_collection(file_errors); } } /* Do not forget to unbind iterator - otherwise there will be a leak */ - unbind_iterator(iterator); + col_unbind_iterator(iterator); TRACE_FLOW_STRING("print_config_parsing_errors", "Exit"); } @@ -1043,7 +1045,7 @@ int get_config_item(const char *section, } /* Is the collection of a right type */ - if (!is_of_class(ini_config, COL_CLASS_INI_CONFIG)) { + if (!col_is_of_class(ini_config, COL_CLASS_INI_CONFIG)) { TRACE_ERROR_NUMBER("Wrong collection type", EINVAL); return EINVAL; } @@ -1057,7 +1059,7 @@ int get_config_item(const char *section, TRACE_INFO_STRING("In Section:", section); /* Get Subcollection */ - error = get_collection_reference(ini_config, §ion_handle, to_find); + error = col_get_collection_reference(ini_config, §ion_handle, to_find); /* Check error */ if (error && (error != ENOENT)) { TRACE_ERROR_NUMBER("Failed to get section", error); @@ -1072,11 +1074,11 @@ int get_config_item(const char *section, } /* Get item */ - error = get_item(section_handle, name, - COL_TYPE_STRING, COL_TRAVERSE_ONELEVEL, item); + error = col_get_item(section_handle, name, + COL_TYPE_STRING, COL_TRAVERSE_ONELEVEL, item); /* Make sure we free the section we found */ - destroy_collection(section_handle); + col_destroy_collection(section_handle); TRACE_FLOW_NUMBER("get_config_item returning", error); return error; @@ -1094,7 +1096,7 @@ long get_long_config_value(struct collection_item *item, /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING)) { + (col_get_item_type(item) != COL_TYPE_STRING)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; return def; @@ -1103,7 +1105,7 @@ long get_long_config_value(struct collection_item *item, if (error) *error = EOK; /* Try to parse the value */ - str = (const char *)get_item_data(item); + str = (const char *)col_get_item_data(item); errno = 0; val = strtol(str, &endptr, 10); @@ -1161,7 +1163,7 @@ double get_double_config_value(struct collection_item *item, /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING)) { + (col_get_item_type(item) != COL_TYPE_STRING)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; return def; @@ -1170,7 +1172,7 @@ double get_double_config_value(struct collection_item *item, if (error) *error = EOK; /* Try to parse the value */ - str = (const char *)get_item_data(item); + str = (const char *)col_get_item_data(item); errno = 0; val = strtod(str, &endptr); @@ -1204,7 +1206,7 @@ unsigned char get_bool_config_value(struct collection_item *item, /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING)) { + (col_get_item_type(item) != COL_TYPE_STRING)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; return def; @@ -1212,8 +1214,8 @@ unsigned char get_bool_config_value(struct collection_item *item, if (error) *error = EOK; - str = (const char *)get_item_data(item); - len = get_item_length(item); + str = (const char *)col_get_item_data(item); + len = col_get_item_length(item); /* Try to parse the value */ if ((strncasecmp(str, "true", len) == 0) || @@ -1242,14 +1244,14 @@ char *get_string_config_value(struct collection_item *item, /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING)) { + (col_get_item_type(item) != COL_TYPE_STRING)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; return NULL; } errno = 0; - str = strdup((const char *)get_item_data(item)); + str = strdup((const char *)col_get_item_data(item)); if (str == NULL) { TRACE_ERROR_NUMBER("Failed to allocate memory.", ENOMEM); if (error) *error = ENOMEM; @@ -1271,13 +1273,13 @@ const char *get_const_string_config_value(struct collection_item *item, int *err /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING)) { + (col_get_item_type(item) != COL_TYPE_STRING)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; return NULL; } - str = (const char *)get_item_data(item); + str = (const char *)col_get_item_data(item); if (error) *error = EOK; @@ -1306,21 +1308,21 @@ char *get_bin_config_value(struct collection_item *item, /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING)) { + (col_get_item_type(item) != COL_TYPE_STRING)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; return NULL; } /* Check the length */ - len = get_item_length(item)-1; + len = col_get_item_length(item)-1; if ((len%2) != 0) { TRACE_ERROR_STRING("Invalid length for binary data", ""); if (error) *error = EINVAL; return NULL; } - str = (const char *)get_item_data(item); + str = (const char *)col_get_item_data(item); /* Is the format correct ? */ if ((*str != '\'') || @@ -1402,7 +1404,7 @@ char **get_string_config_array(struct collection_item *item, /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING)) { + (col_get_item_type(item) != COL_TYPE_STRING)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; return NULL; @@ -1413,7 +1415,7 @@ char **get_string_config_array(struct collection_item *item, lensep = strnlen(sep, 3); /* Allocate memory for the copy of the string */ - copy = malloc(get_item_length(item)); + copy = malloc(col_get_item_length(item)); if (copy == NULL) { TRACE_ERROR_NUMBER("Failed to allocate memory.", ENOMEM); if (error) *error = ENOMEM; @@ -1543,7 +1545,7 @@ long *get_long_config_array(struct collection_item *item, int *size, int *error) /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING) || + (col_get_item_type(item) != COL_TYPE_STRING) || (size == NULL)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; @@ -1551,7 +1553,7 @@ long *get_long_config_array(struct collection_item *item, int *size, int *error) } /* Assume that we have maximum number of different numbers */ - array = (long *)malloc(sizeof(long) * get_item_length(item)/2); + array = (long *)malloc(sizeof(long) * col_get_item_length(item)/2); if (array == NULL) { TRACE_ERROR_NUMBER("Failed to allocate memory.", ENOMEM); if (error) *error = ENOMEM; @@ -1559,7 +1561,7 @@ long *get_long_config_array(struct collection_item *item, int *size, int *error) } /* Now parse the string */ - str = (const char *)get_item_data(item); + str = (const char *)col_get_item_data(item); while (*str) { errno = 0; val = strtol(str, &endptr, 10); @@ -1606,7 +1608,7 @@ double *get_double_config_array(struct collection_item *item, int *size, int *er /* Do we have the item ? */ if ((item == NULL) || - (get_item_type(item) != COL_TYPE_STRING) || + (col_get_item_type(item) != COL_TYPE_STRING) || (size == NULL)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; @@ -1614,7 +1616,7 @@ double *get_double_config_array(struct collection_item *item, int *size, int *er } /* Assume that we have maximum number of different numbers */ - array = (double *)malloc(sizeof(double) * get_item_length(item)/2); + array = (double *)malloc(sizeof(double) * col_get_item_length(item)/2); if (array == NULL) { TRACE_ERROR_NUMBER("Failed to allocate memory.", ENOMEM); if (error) *error = ENOMEM; @@ -1629,7 +1631,7 @@ double *get_double_config_array(struct collection_item *item, int *size, int *er loc = localeconv(); /* Now parse the string */ - str = (const char *)get_item_data(item); + str = (const char *)col_get_item_data(item); while (*str) { errno = 0; TRACE_INFO_STRING("String to convert",str); @@ -1682,7 +1684,7 @@ void free_section_list(char **section_list) { TRACE_FLOW_STRING("free_section_list","Entry"); - free_property_list(section_list); + col_free_property_list(section_list); TRACE_FLOW_STRING("free_section_list","Exit"); } @@ -1692,7 +1694,7 @@ void free_attribute_list(char **section_list) { TRACE_FLOW_STRING("free_section_list","Entry"); - free_property_list(section_list); + col_free_property_list(section_list); TRACE_FLOW_STRING("free_section_list","Exit"); } @@ -1708,14 +1710,14 @@ char **get_section_list(struct collection_item *ini_config, int *size, int *erro 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)) { + !col_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); + list = col_collection_to_list(ini_config, size, error); TRACE_FLOW_STRING("get_section_list returning", list == NULL ? "NULL" : list[0]); return list; @@ -1733,7 +1735,7 @@ char **get_attribute_list(struct collection_item *ini_config, const char *sectio 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) || + !col_is_of_class(ini_config, COL_CLASS_INI_CONFIG) || (section == NULL)) { TRACE_ERROR_NUMBER("Invalid argument.", EINVAL); if (error) *error = EINVAL; @@ -1741,7 +1743,7 @@ char **get_attribute_list(struct collection_item *ini_config, const char *sectio } /* Fetch section */ - err = get_collection_reference(ini_config, &subcollection, section); + err = col_get_collection_reference(ini_config, &subcollection, section); /* Check error */ if (err && (subcollection == NULL)) { TRACE_ERROR_NUMBER("Failed to get section", err); @@ -1750,9 +1752,9 @@ char **get_attribute_list(struct collection_item *ini_config, const char *sectio } /* Pass it to the function from collection API */ - list = collection_to_list(subcollection, size, error); + list = col_collection_to_list(subcollection, size, error); - destroy_collection(subcollection); + col_destroy_collection(subcollection); TRACE_FLOW_STRING("get_attribute_list returning", list == NULL ? "NULL" : list[0]); return list; diff --git a/common/ini/ini_config_ut.c b/common/ini/ini_config_ut.c index 9aefbe301..ce3792111 100644 --- a/common/ini/ini_config_ut.c +++ b/common/ini/ini_config_ut.c @@ -41,9 +41,9 @@ int basic_test() return error; } - debug_collection(ini_config,COL_TRAVERSE_DEFAULT); - print_collection(ini_config); - print_collection(error_set); + col_debug_collection(ini_config,COL_TRAVERSE_DEFAULT); + col_print_collection(ini_config); + col_print_collection(error_set); printf("\n\n----------------------\n"); /* Output parsing errors (if any) */ @@ -51,8 +51,8 @@ int basic_test() printf("----------------------\n\n\n"); - destroy_collection(ini_config); - destroy_collection(error_set); + col_destroy_collection(ini_config); + col_destroy_collection(error_set); return 0; } @@ -76,9 +76,9 @@ int single_file() return error; } - debug_collection(ini_config, COL_TRAVERSE_DEFAULT); - print_collection(ini_config); - print_collection(error_set); + col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT); + col_print_collection(ini_config); + col_print_collection(error_set); printf("\n\n----------------------\n"); /* Output parsing errors (if any) */ @@ -86,8 +86,8 @@ int single_file() printf("----------------------\n\n\n"); - destroy_collection(ini_config); - destroy_collection(error_set); + col_destroy_collection(ini_config); + col_destroy_collection(error_set); ini_config = NULL; error_set = NULL; @@ -102,8 +102,8 @@ int single_file() return error; } - debug_collection(ini_config, COL_TRAVERSE_DEFAULT); - debug_collection(lines, COL_TRAVERSE_DEFAULT); + col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT); + col_debug_collection(lines, COL_TRAVERSE_DEFAULT); printf("\n\n----------------------\n"); /* Output parsing errors (if any) */ @@ -111,9 +111,9 @@ int single_file() printf("----------------------\n\n\n"); - destroy_collection(ini_config); - destroy_collection(error_set); - destroy_collection(lines); + col_destroy_collection(ini_config); + col_destroy_collection(error_set); + col_destroy_collection(lines); return 0; } @@ -153,14 +153,14 @@ int negative_test() } count = 0; - (void)get_collection_count(ini_config, &count); + (void)col_get_collection_count(ini_config, &count); if (count > 1) { printf("Expected empty collection but got contents with %d elements\n", count); - print_collection(ini_config); + col_print_collection(ini_config); return -1; } - destroy_collection(ini_config); + col_destroy_collection(ini_config); return 0; } @@ -184,9 +184,9 @@ int real_test(const char *file) } printf("Debugging the config collection:\n"); - debug_collection(ini_config, COL_TRAVERSE_DEFAULT); + col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT); printf("Debugging the error collection:\n"); - debug_collection(error_set, COL_TRAVERSE_DEFAULT); + col_debug_collection(error_set, COL_TRAVERSE_DEFAULT); printf("About to print parsing errors:\n"); printf("\n\n----------------------\n"); @@ -196,48 +196,48 @@ int real_test(const char *file) printf("About to bind iterator to print the config file contents.\n"); /* Bind iterator */ - error = bind_iterator(&iterator, ini_config, + error = col_bind_iterator(&iterator, ini_config, COL_TRAVERSE_DEFAULT|COL_TRAVERSE_END); if (error) { printf("Failed to bind iterator: %d\n",error); - destroy_collection(ini_config); - destroy_collection(error_set); + col_destroy_collection(ini_config); + col_destroy_collection(error_set); return error; } printf("About to start iteration loop.\n"); do { /* Loop through a collection */ - error = iterate_collection(iterator, &item); + error = col_iterate_collection(iterator, &item); if (error) { printf("Error iterating collection: %d", error); - unbind_iterator(iterator); + col_unbind_iterator(iterator); return error; } /* Are we done ? */ if (item == (struct collection_item *)(NULL)) break; - type = get_item_type(item); + type = col_get_item_type(item); /* Start of the collection */ if (type == COL_TYPE_COLLECTION) - printf("Contents of the configuration for application %s\n", get_item_property(item, NULL)); + printf("Contents of the configuration for application %s\n", col_get_item_property(item, NULL)); /* End of section */ else if (type == COL_TYPE_END) printf("\n"); /* Section header ? */ - else if (type == COL_TYPE_COLLECTIONREF) printf("[%s]\n", get_item_property(item, NULL)); + else if (type == COL_TYPE_COLLECTIONREF) printf("[%s]\n", col_get_item_property(item, NULL)); /* Anything else - we know they are all strings*/ - else printf("%s = %s\n", get_item_property(item, NULL), (char *)get_item_data(item)); + else printf("%s = %s\n", col_get_item_property(item, NULL), (char *)col_get_item_data(item)); } while(1); /* Do not forget to unbind iterator - otherwise there will be a leak */ printf("About to clean up.\n"); - unbind_iterator(iterator); + col_unbind_iterator(iterator); - destroy_collection(ini_config); - destroy_collection(error_set); + col_destroy_collection(ini_config); + col_destroy_collection(error_set); return 0; } @@ -277,10 +277,10 @@ int get_test() } printf("Debugging the config collection:\n"); - debug_collection(ini_config, COL_TRAVERSE_DEFAULT); + col_debug_collection(ini_config, COL_TRAVERSE_DEFAULT); printf("Debugging the error collection:\n"); - debug_collection(error_set, COL_TRAVERSE_DEFAULT); - destroy_collection(error_set); + col_debug_collection(error_set, COL_TRAVERSE_DEFAULT); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should not be found */ if (item != (struct collection_item *)(NULL)) { printf("Expected NULL but got something else!\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should not be found */ if(item != (struct collection_item *)(NULL)) { printf("Expected NULL but got something else!\n"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return -1; } @@ -323,18 +323,18 @@ int get_test() error = get_config_item("monitor", "description", ini_config, &item); if (error) { printf("Expected success but got error! %d\n", error); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should be found */ if (item == (struct collection_item *)(NULL)) { printf("Expected item but got something NULL!\n"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return -1; } - debug_item(item); + col_debug_item(item); printf("Get item as string without duplication from NULL item.\n"); @@ -343,7 +343,7 @@ int get_test() cstrn = get_const_string_config_value(NULL, NULL); if (cstrn != NULL) { printf("Expected error got success.\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } @@ -383,18 +383,18 @@ int get_test() error = get_config_item("monitor", "bad_number", ini_config, &item); if (error) { printf("Expected success but got error! %d\n", error); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should be found */ if (item == (struct collection_item *)(NULL)) { printf("Expected item but got something NULL!\n"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return -1; } - debug_item(item); + col_debug_item(item); /* Now try to get value in different ways */ @@ -405,7 +405,7 @@ int get_test() printf("Expected error.\n"); if(number != 10) { printf("It failed to set default value.\n"); - destroy_collection(ini_config); + col_destroy_collection(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"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } if (number != 5) { /* We expected error in this case */ printf("We expected that the conversion will return 5.\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should be found */ if (item == (struct collection_item *)(NULL)) { printf("Expected success but got NULL.\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* It is 3 in the file */ if (number != 3) { printf("We expected that the conversion will return 3.\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* It is 3 in the file */ if (number_long != 3) { printf("We expected that the conversion will return 3.\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* It is 3 in the file */ if(number_unsigned != 3) { printf("We expected that the conversion will return 3.\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* It is 3 in the file */ if (number_ulong != 3) { printf("We expected that the conversion will return 3.\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* It is 3 in the file */ if (number_double != 3.) { printf("We expected that the conversion will return 3.\n"); - destroy_collection(ini_config); + col_destroy_collection(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"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should be found */ if (item == (struct collection_item *)(NULL)) { printf("Expected success but got NULL.\n"); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } @@ -600,24 +600,24 @@ 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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should be found */ if (item == (struct collection_item *)(NULL)) { printf("Expected success but got NULL.\n"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return -1; } - debug_item(item); + col_debug_item(item); error = 0; binary = get_bin_config_value(item, &length, &error); if (error) { printf("Expect success got error %d.\n", error); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } @@ -635,18 +635,18 @@ int get_test() error = get_config_item("domains", "domainsorder", ini_config, &item); if(error) { printf("Expected success but got error! %d\n",error); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should be found */ if (item == (struct collection_item *)(NULL)) { printf("Expected success but got NULL.\n"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return -1; } - debug_item(item); + col_debug_item(item); printf("Get str array without size.\n"); @@ -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); - destroy_collection(ini_config); + col_destroy_collection(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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } @@ -689,25 +689,25 @@ 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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should be found */ if (item == (struct collection_item *)(NULL)) { printf("Expected success but got NULL.\n"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return -1; } - debug_item(item); + col_debug_item(item); error = 0; size = 0; /* Here size is not optional!!! */ array = get_long_config_array(item, &size, &error); if(error) { printf("Expect success got error %d.\n", error); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } @@ -722,25 +722,25 @@ 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); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return error; } /* Item should be found */ if (item == (struct collection_item *)(NULL)) { printf("Expected success but got NULL.\n"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return -1; } - debug_item(item); + col_debug_item(item); error = 0; size = 0; /* Here size is not optional!!! */ darray = get_double_config_array(item, &size, &error); if (error) { printf("Expect success got error %d.\n", error); - destroy_collection(ini_config); + col_destroy_collection(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"); - destroy_collection(ini_config); + col_destroy_collection(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"); - destroy_collection(ini_config); + col_destroy_collection(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"); - destroy_collection(ini_config); + col_destroy_collection(ini_config); return -1; } for (i=0;i