summaryrefslogtreecommitdiff
path: root/src/shared/dlt_config_file_parser.h
blob: 98aef03d711d4cb671a3cbcbbab1c1c143961bf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 * @licence app begin@
 * SPDX license identifier: MPL-2.0
 *
 * Copyright (C) 2015, Advanced Driver Information Technology
 * This code is developed by Advanced Driver Information Technology.
 * Copyright of Advanced Driver Information Technology, Bosch and DENSO.
 *
 * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
 *
 * This Source Code Form is subject to the terms of the
 * Mozilla Public License (MPL), v. 2.0.
 * If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * For further information see http://www.genivi.org/.
 * @licence end@
 */

/*!
 * \author Christoph Lipka <clipka@jp.adit-jv.com>
 *
 * \copyright Copyright © 2015 Advanced Driver Information Technology. \n
 * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
 *
 * \file dlt_config_file_parser.h
 */


/*******************************************************************************
**                                                                            **
**  SRC-MODULE: dlt_config_file_parser.h                                      **
**                                                                            **
**  TARGET    : linux                                                         **
**                                                                            **
**  PROJECT   : DLT                                                           **
**                                                                            **
**  AUTHOR    : Christoph Lipka clipka@jp.adit-jv.com                         **
**                                                                            **
**  PURPOSE   :                                                               **
**                                                                            **
**  REMARKS   :                                                               **
**                                                                            **
**  PLATFORM DEPENDANT [yes/no]: yes                                          **
**                                                                            **
**  TO BE CHANGED BY USER [yes/no]: no                                        **
**                                                                            **
*******************************************************************************/

/*******************************************************************************
**                      Author Identity                                       **
********************************************************************************
**                                                                            **
** Initials     Name                       Company                            **
** --------     -------------------------  ---------------------------------- **
**  cl          Christoph Lipka            ADIT                               **
*******************************************************************************/

#ifndef _DLT_CONFIG_FILE_PARSER_H_
#define _DLT_CONFIG_FILE_PARSER_H_


/* definitions */
#define DLT_CONFIG_FILE_PATH_MAX_LEN       100 /* absolute path including filename */
#define DLT_CONFIG_FILE_ENTRY_MAX_LEN      100 /* Entry for section, key and value */
#define DLT_CONFIG_FILE_LINE_MAX_LEN       210
#define DLT_CONFIG_FILE_SECTIONS_MAX       100
#define DLT_CONFIG_FILE_KEYS_MAX            25 /* Maximal keys per section */

typedef struct DltConfigKeyData
{
    char *key;
    char *data;
    struct DltConfigKeyData *next;
} DltConfigKeyData;

/* Config file section structure */
typedef struct
{
    int num_entries;          /* number of entries */
    char *name;               /* name of section */
    char *keys;               /* keys */
    DltConfigKeyData *list;
} DltConfigFileSection;

typedef struct
{
    int num_sections;               /* number of sections */
    DltConfigFileSection *sections; /* sections */
} DltConfigFile;

/**
 * dlt_config_file_init
 *
 * Load the configuration file and stores all data in
 * internal data structures.
 *
 * @param file_name File to be opened
 * @return          Pointer to DltConfigFile object or NULL on error
 */
DltConfigFile *dlt_config_file_init(char *file_name);

/**
 * dlt_config_file_release
 *
 * Release config file and frees all internal data. Has to be called after
 * after all data is read.
 *
 * @param file      DltConfigFile
 */
void dlt_config_file_release(DltConfigFile *file);

/**
 * dlt_config_file_get_section_name
 *
 * Get name of section number.
 *
 * @param[in]  file      DltConfigFile
 * @param[in]  num       Number of section
 * @param[out] name      Section name
 * @return     0 on success, else -1
 */
int dlt_config_file_get_section_name(const DltConfigFile *file,
                                     int num,
                                     char *name);

/**
 * dlt_config_file_get_num_sections
 *
 * Get the number of sections inside configuration file
 *
 * @param[in]  file     DltConfigFile
 * @param[out] num      Number of sections inside configuration file
 * @return     0 on success, else -1
 */
int dlt_config_file_get_num_sections(const DltConfigFile *file, int *num);

/**
 * dlt_config_file_get_value
 *
 * Get value of key in specified section.
 *
 * @param[in]   file      DltConfigFile
 * @param[in]   section   Name of section
 * @param[in]   key       Key
 * @param[out]  value     Value
 * @return      0 on success, else -1
 */
int dlt_config_file_get_value(const DltConfigFile *file,
                              const char *section,
                              const char *key,
                              char *value);
#endif