automotive-dlt
dlt_config_file_parser.c File Reference
#include "dlt_config_file_parser.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <syslog.h>
#include "dlt_common.h"
#include "dlt-daemon_cfg.h"
Include dependency graph for dlt_config_file_parser.c:

Go to the source code of this file.

Macros

#define DLT_CONFIG_FILE_NEW_SECTION   0x0a
 
#define DLT_CONFIG_FILE_NEW_DATA   0x0b
 

Functions

static void dlt_config_file_trim_line (char *line)
 
static int dlt_config_file_ignore_line (char *line)
 
static int dlt_config_file_is_section_name (DltConfigFile *file, char *name)
 
static int dlt_config_file_set_section (DltConfigFile *file, char *name)
 
static int dlt_config_file_set_section_data (DltConfigFile *file, char *str1, char *str2)
 
static int dlt_config_file_line_has_section (char *line)
 
static int dlt_config_file_get_section_name_from_string (char *line, char *name)
 
static int dlt_config_file_get_key_value (char *line, char *str1, char *str2)
 
static int dlt_config_file_read_line (char *line, char *str1, char *str2)
 
static void dlt_config_file_read_file (DltConfigFile *file, FILE *hdl)
 
static int dlt_config_file_find_section (const DltConfigFile *file, const char *section)
 
DltConfigFiledlt_config_file_init (char *file_name)
 
void dlt_config_file_release (DltConfigFile *file)
 
int dlt_config_file_get_section_name (const DltConfigFile *file, int num, char *name)
 
int dlt_config_file_get_num_sections (const DltConfigFile *file, int *num)
 
int dlt_config_file_get_value (const DltConfigFile *file, const char *section, const char *key, char *value)
 

Detailed Description

Author
Christoph Lipka clipk.nosp@m.a@jp.nosp@m..adit.nosp@m.-jv..nosp@m.com

Definition in file dlt_config_file_parser.c.

Macro Definition Documentation

#define DLT_CONFIG_FILE_NEW_DATA   0x0b
#define DLT_CONFIG_FILE_NEW_SECTION   0x0a

Function Documentation

static int dlt_config_file_find_section ( const DltConfigFile file,
const char *  section 
)
static

dlt_config_file_find_section

Find a section

Parameters
fileDltConfigFile
sectionName of section
Returns
number of section on success, else -1

Definition at line 419 of file dlt_config_file_parser.c.

References DLT_CONFIG_FILE_ENTRY_MAX_LEN, dlt_log(), DltConfigFileSection::name, NULL, DltConfigFile::num_sections, and DltConfigFile::sections.

Referenced by dlt_config_file_get_value().

static int dlt_config_file_get_key_value ( char *  line,
char *  str1,
char *  str2 
)
static

dlt_config_file_get_key_value

Get key and value from a line of configuration file

Parameters
lineLine on configuration file
[out]str1String to be used as key
[out]str2String to be used as value
Returns
0 on success, else -1

Definition at line 293 of file dlt_config_file_parser.c.

References DLT_CONFIG_FILE_ENTRY_MAX_LEN, and NULL.

Referenced by dlt_config_file_read_line().

int dlt_config_file_get_num_sections ( const DltConfigFile file,
int *  num 
)

dlt_config_file_get_num_sections

Get the number of sections inside configuration file

Parameters
[in]fileDltConfigFile
[out]numNumber of sections inside configuration file
Returns
0 on success, else -1

Definition at line 524 of file dlt_config_file_parser.c.

References NULL, and DltConfigFile::num_sections.

Referenced by dlt_gateway_configure(), and dlt_logstorage_store_filters().

int dlt_config_file_get_section_name ( const DltConfigFile file,
int  num,
char *  name 
)

dlt_config_file_get_section_name

Get name of section number.

Parameters
[in]fileDltConfigFile
[in]numNumber of section
[out]sectionSection name
Returns
0 on success, else -1

Definition at line 512 of file dlt_config_file_parser.c.

References DLT_CONFIG_FILE_ENTRY_MAX_LEN, NULL, DltConfigFile::num_sections, and DltConfigFile::sections.

Referenced by dlt_gateway_configure(), and dlt_logstorage_store_filters().

static int dlt_config_file_get_section_name_from_string ( char *  line,
char *  name 
)
static

dlt_config_file_get_section_name_from_string

Extract section name from line

Parameters
lineLine in configuration file containing a section header
Returns
0 on success, else -1

Definition at line 262 of file dlt_config_file_parser.c.

References DLT_CONFIG_FILE_ENTRY_MAX_LEN, and NULL.

Referenced by dlt_config_file_read_line().

int dlt_config_file_get_value ( const DltConfigFile file,
const char *  section,
const char *  key,
char *  value 
)

dlt_config_file_get_value

Get value of key in specified section.

Parameters
[in]fileDltConfigFile
[in]sectionName of section
[in]keyKey
[out]valueValue
Returns
0 on success, else -1

Definition at line 534 of file dlt_config_file_parser.c.

References DltConfigFileSection::data, DLT_CONFIG_FILE_ENTRY_MAX_LEN, dlt_config_file_find_section(), dlt_log(), NULL, and DltConfigFile::sections.

Referenced by dlt_daemon_setup_filter_properties(), and dlt_gateway_configure().

static int dlt_config_file_ignore_line ( char *  line)
static

dlt_config_file_ignore_line

Check if a line has to be ignored, because it contains a comment or is empty

Parameters
lineLine of configuration file
Returns
0 if ignore, -1 do not ignore

Definition at line 78 of file dlt_config_file_parser.c.

Referenced by dlt_config_file_read_file().

DltConfigFile* dlt_config_file_init ( char *  file_name)

dlt_config_file_init

Load the configuration file and stores all data in internal data structures.

Parameters
file_nameFile to be opened
Returns
Pointer to DltConfigFile object or NULL on error

Definition at line 441 of file dlt_config_file_parser.c.

References DLT_CONFIG_FILE_PATH_MAX_LEN, dlt_config_file_read_file(), DLT_CONFIG_FILE_SECTIONS_MAX, dlt_log(), NULL, and DltConfigFile::sections.

Referenced by dlt_gateway_configure(), and dlt_logstorage_store_filters().

static int dlt_config_file_is_section_name ( DltConfigFile file,
char *  name 
)
static

dlt_config_file_is_section_name

Check if section name already used

Parameters
fileDltConfigFile
nameName of section
Returns
0, section name not used, -1 section name already used

Definition at line 103 of file dlt_config_file_parser.c.

References DLT_CONFIG_FILE_ENTRY_MAX_LEN, DltConfigFileSection::name, NULL, DltConfigFile::num_sections, and DltConfigFile::sections.

Referenced by dlt_config_file_set_section().

static int dlt_config_file_line_has_section ( char *  line)
static

dlt_config_file_has_section

Check if a certain line in config file is a section header

Parameters
lineLine in configuration file
Returns
0 if section header, else -1

Definition at line 245 of file dlt_config_file_parser.c.

Referenced by dlt_config_file_read_line().

static void dlt_config_file_read_file ( DltConfigFile file,
FILE *  hdl 
)
static

dlt_config_file_read_file

Read configuration file line by line and fill internal structures

Parameters
fileDltConfigFile
hdlFILE handle of opened configuration file

Definition at line 363 of file dlt_config_file_parser.c.

References DLT_CONFIG_FILE_ENTRY_MAX_LEN, dlt_config_file_ignore_line(), DLT_CONFIG_FILE_LINE_MAX_LEN, DLT_CONFIG_FILE_NEW_DATA, DLT_CONFIG_FILE_NEW_SECTION, dlt_config_file_read_line(), dlt_config_file_set_section(), dlt_config_file_set_section_data(), dlt_config_file_trim_line(), DLT_DAEMON_TEXTBUFSIZE, dlt_log(), and NULL.

Referenced by dlt_config_file_init().

static int dlt_config_file_read_line ( char *  line,
char *  str1,
char *  str2 
)
static

dlt_config_file_read_line

Read line from configuration file

Parameters
lineLine from configuration file
[out]str1String contains section header or key
[out]str2String contains value or is empty
Returns
0 on success, else -1

Definition at line 329 of file dlt_config_file_parser.c.

References DLT_CONFIG_FILE_ENTRY_MAX_LEN, dlt_config_file_get_key_value(), dlt_config_file_get_section_name_from_string(), dlt_config_file_line_has_section(), DLT_CONFIG_FILE_NEW_DATA, DLT_CONFIG_FILE_NEW_SECTION, and NULL.

Referenced by dlt_config_file_read_file().

void dlt_config_file_release ( DltConfigFile file)

dlt_config_file_release

Release config file and frees all internal data. Has to be called after after all data is read.

Parameters
fileDltConfigFile

Definition at line 477 of file dlt_config_file_parser.c.

References DltConfigFileSection::data, DLT_CONFIG_FILE_ENTRY_MAX_LEN, DltConfigFileSection::keys, DltConfigFileSection::name, NULL, DltConfigFileSection::num_entries, DltConfigFile::num_sections, and DltConfigFile::sections.

Referenced by dlt_gateway_configure(), and dlt_logstorage_store_filters().

static int dlt_config_file_set_section ( DltConfigFile file,
char *  name 
)
static

dlt_config_file_set_section

Store section in internal data structure

Parameters
fileDltConfigFile
nameName of section
Returns
0 on success, else -1

Definition at line 130 of file dlt_config_file_parser.c.

References DltConfigFileSection::data, DLT_CONFIG_FILE_ENTRY_MAX_LEN, dlt_config_file_is_section_name(), DLT_CONFIG_FILE_KEYS_MAX, DLT_CONFIG_FILE_SECTIONS_MAX, dlt_log(), DltConfigFileSection::keys, DltConfigFileSection::name, NULL, DltConfigFile::num_sections, and DltConfigFile::sections.

Referenced by dlt_config_file_read_file().

static int dlt_config_file_set_section_data ( DltConfigFile file,
char *  str1,
char *  str2 
)
static

dlt_config_file_set_section_data

Store data pair of a section

Parameters
fileDltConfigFile
str1string used for key
str2string used for value
Returns
0 on success, else -1

Definition at line 189 of file dlt_config_file_parser.c.

References DltConfigFileSection::data, DLT_CONFIG_FILE_ENTRY_MAX_LEN, DLT_CONFIG_FILE_KEYS_MAX, DLT_DAEMON_TEXTBUFSIZE, dlt_log(), DltConfigFileSection::keys, NULL, DltConfigFileSection::num_entries, DltConfigFile::num_sections, and DltConfigFile::sections.

Referenced by dlt_config_file_read_file().

static void dlt_config_file_trim_line ( char *  line)
static

dlt_config_file_trim_line

Trim all whitespace from a string

Parameters
lineString to remove whitespace from

Definition at line 53 of file dlt_config_file_parser.c.

References NULL.

Referenced by dlt_config_file_read_file().