40 #define DLT_CONFIG_FILE_NEW_SECTION 0x0a 41 #define DLT_CONFIG_FILE_NEW_DATA 0x0b 81 int len = strlen(line);
83 for (i = 0; i < len; i++)
85 if (line[i] ==
'#' || line[i] ==
';' || line[i] ==
'\n' || line[i] ==
'\0')
136 dlt_log(LOG_WARNING,
"Cannot store more sections\n");
143 dlt_log(LOG_WARNING,
"Cannot store section name again\n");
153 dlt_log(LOG_ERR,
"Cannot allocate memory for internal data structure\n");
161 dlt_log(LOG_ERR,
"Cannot allocate memory for internal data structure\n");
168 dlt_log(LOG_ERR,
"Cannot create hash table object\n");
202 dlt_log(LOG_WARNING,
"Cannot store more keys in section\n");
209 item.key = strdup(str1);
210 item.data = strdup(str2);
213 if (hsearch_r(item, FIND, &ret, &s->
data) == 0)
215 if (hsearch_r(item, ENTER, &ret, &s->
data) == 0)
220 dlt_log(LOG_ERR,
"Cannot add data to hash table\n");
227 snprintf(error_str,
DLT_DAEMON_TEXTBUFSIZE,
"Key \"%s\" already exists! New data will be ignored\n", item.key);
228 dlt_log(LOG_WARNING, error_str);
272 if(line[i] ==
'[' || isspace(line[i]))
274 else if (line[i] ==
']' || line[i] ==
'\n' || line[i] ==
'\0')
295 char *delimiter =
"=";
302 ptr = strtok_r(line, delimiter, &save_ptr);
309 ptr = strtok_r(
NULL, delimiter, &save_ptr);
371 int is_section_valid = -1;
391 is_section_valid = -1;
394 is_section_valid = 0;
398 if (is_section_valid == 0)
405 dlt_log(LOG_WARNING, error_str);
426 dlt_log(LOG_WARNING,
"Section cannot be found due to invalid parameters\n");
448 dlt_log(LOG_ERR,
"Given configuration file invalid\n");
455 dlt_log(LOG_ERR,
"Setup internal data structure to parse config file failed\n");
462 if ((hdl = fopen(file_name,
"r")) ==
NULL)
464 dlt_log(LOG_ERR,
"Cannot open configuration file\n");
486 for (i = 0; i < max; i++)
497 hsearch_r (entry, FIND, &found, &s->
data);
502 hdestroy_r(&s->
data);
536 const char *key,
char *value)
550 if (num_section == -1)
556 entry.key = strdup(key);
557 if (entry.key ==
NULL)
559 dlt_log(LOG_CRIT,
"Not enougth memory to duplicate key string\n");
563 if (hsearch_r(entry, FIND, &found, &s->
data) == 0)
565 dlt_log(LOG_WARNING,
"Entry does not exist in section\n");
static int dlt_config_file_get_key_value(char *line, char *str1, char *str2)
int dlt_config_file_get_section_name(const DltConfigFile *file, int num, char *name)
#define DLT_CONFIG_FILE_NEW_SECTION
static int dlt_config_file_line_has_section(char *line)
int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num)
static void dlt_config_file_trim_line(char *line)
static void dlt_config_file_read_file(DltConfigFile *file, FILE *hdl)
#define DLT_CONFIG_FILE_ENTRY_MAX_LEN
DltConfigFile * dlt_config_file_init(char *file_name)
#define DLT_CONFIG_FILE_SECTIONS_MAX
static int dlt_config_file_set_section(DltConfigFile *file, char *name)
DltReturnValue dlt_log(int prio, char *s)
static int dlt_config_file_find_section(const DltConfigFile *file, const char *section)
DltConfigFileSection * sections
#define DLT_CONFIG_FILE_LINE_MAX_LEN
#define DLT_CONFIG_FILE_PATH_MAX_LEN
static int dlt_config_file_set_section_data(DltConfigFile *file, char *str1, char *str2)
static int dlt_config_file_ignore_line(char *line)
#define DLT_CONFIG_FILE_NEW_DATA
int dlt_config_file_get_value(const DltConfigFile *file, const char *section, const char *key, char *value)
static int dlt_config_file_get_section_name_from_string(char *line, char *name)
#define DLT_CONFIG_FILE_KEYS_MAX
static int dlt_config_file_is_section_name(DltConfigFile *file, char *name)
static int dlt_config_file_read_line(char *line, char *str1, char *str2)
#define DLT_DAEMON_TEXTBUFSIZE
void dlt_config_file_release(DltConfigFile *file)