From 472137c469bcd1faf2c6f12d9bb15e2675dd6870 Mon Sep 17 00:00:00 2001 From: Bui Nguyen Quoc Thanh Date: Fri, 13 Mar 2020 10:41:01 +0700 Subject: gateway: Improvement of handling Gateway config In the current implementation, we believe in user to treat General section as Mandatory. Hence system could be reset due to memory of connections incorrectly. At the moment, General could be handled as Optional with default value of interval. It means General could be absent from config file. Improvement is to raise WARNING to user, set default value and update the number of connections properly. Signed-off-by: Bui Nguyen Quoc Thanh --- src/shared/dlt_config_file_parser.c | 18 +++++++++++++++++- src/shared/dlt_config_file_parser.h | 12 ++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'src/shared') diff --git a/src/shared/dlt_config_file_parser.c b/src/shared/dlt_config_file_parser.c index b123ebf..009a093 100644 --- a/src/shared/dlt_config_file_parser.c +++ b/src/shared/dlt_config_file_parser.c @@ -505,7 +505,8 @@ int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num) return -1; /* - * Note: this number is also containing General section + * Note: Since General section could be used in configuration file, + * this number could be also containing General section. */ *num = file->num_sections; @@ -548,3 +549,18 @@ int dlt_config_file_get_value(const DltConfigFile *file, dlt_vlog(LOG_WARNING, "Entry does not exist in section: %s\n", key); return -1; } + +int dlt_config_file_check_section_name_exists(const DltConfigFile *file, + const char *name) +{ + int ret = 0; + + if ((file == NULL) || (file->num_sections <= 0) || (name == NULL)) + return -1; + + ret = dlt_config_file_find_section(file, name); + if (ret == -1) + return ret; + + return 0; +} diff --git a/src/shared/dlt_config_file_parser.h b/src/shared/dlt_config_file_parser.h index acde08c..3c1a6fd 100644 --- a/src/shared/dlt_config_file_parser.h +++ b/src/shared/dlt_config_file_parser.h @@ -148,4 +148,16 @@ int dlt_config_file_get_value(const DltConfigFile *file, const char *section, const char *key, char *value); + +/** + * dlt_config_file_check_section_name_exists + * + * Get name of section number. + * + * @param[in] file DltConfigFile + * @param[in] name Section name + * @return 0 on success/exist, else -1 + */ +int dlt_config_file_check_section_name_exists(const DltConfigFile *file, + const char *name); #endif -- cgit v1.2.1