1
1
/* *
2
2
* \file src/plugins/output/fds/src/Config.cpp
3
3
* \author Lukas Hutak <[email protected] >
4
+ * \author Michal Sedlak <[email protected] >
4
5
* \brief Parser of XML configuration (source file)
5
6
* \date 2019
6
7
*
21
22
* <align>...</align> <!-- optional -->
22
23
* </dumpInterval>
23
24
* <asyncIO>...</asyncIO> <!-- optional -->
25
+ * <outputSelection> <!-- optional -->
26
+ * <element>...</element>
27
+ * <element>...</element>
28
+ * ...
29
+ * </outputSelection>
24
30
* </params>
25
31
*/
26
32
@@ -30,9 +36,12 @@ enum params_xml_nodes {
30
36
NODE_COMPRESS,
31
37
NODE_DUMP,
32
38
NODE_ASYNCIO,
39
+ NODE_SELECTION,
33
40
34
41
DUMP_WINDOW,
35
- DUMP_ALIGN
42
+ DUMP_ALIGN,
43
+
44
+ SELECTION_ELEMENT,
36
45
};
37
46
38
47
// / Definition of the \<dumpInterval\> node
@@ -42,17 +51,24 @@ static const struct fds_xml_args args_dump[] = {
42
51
FDS_OPTS_END
43
52
};
44
53
54
+ // / Definition of the \<outputSelection\> node
55
+ static const struct fds_xml_args args_selection[] = {
56
+ FDS_OPTS_ELEM (SELECTION_ELEMENT, " element" , FDS_OPTS_T_STRING, FDS_OPTS_P_MULTI),
57
+ FDS_OPTS_END
58
+ };
59
+
45
60
// / Definition of the \<params\> node
46
61
static const struct fds_xml_args args_params[] = {
47
62
FDS_OPTS_ROOT (" params" ),
48
- FDS_OPTS_ELEM (NODE_STORAGE, " storagePath" , FDS_OPTS_T_STRING, 0 ),
49
- FDS_OPTS_ELEM (NODE_COMPRESS, " compression" , FDS_OPTS_T_STRING, FDS_OPTS_P_OPT),
50
- FDS_OPTS_NESTED (NODE_DUMP, " dumpInterval" , args_dump, FDS_OPTS_P_OPT),
51
- FDS_OPTS_ELEM (NODE_ASYNCIO, " asyncIO" , FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
63
+ FDS_OPTS_ELEM (NODE_STORAGE, " storagePath" , FDS_OPTS_T_STRING, 0 ),
64
+ FDS_OPTS_ELEM (NODE_COMPRESS, " compression" , FDS_OPTS_T_STRING, FDS_OPTS_P_OPT),
65
+ FDS_OPTS_NESTED (NODE_DUMP, " dumpInterval" , args_dump, FDS_OPTS_P_OPT),
66
+ FDS_OPTS_ELEM (NODE_ASYNCIO, " asyncIO" , FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
67
+ FDS_OPTS_NESTED (NODE_SELECTION, " outputSelection" , args_selection, FDS_OPTS_P_OPT),
52
68
FDS_OPTS_END
53
69
};
54
70
55
- Config::Config (const char *params)
71
+ Config::Config (const char *params, const fds_iemgr_t *iemgr )
56
72
{
57
73
set_default ();
58
74
@@ -74,7 +90,7 @@ Config::Config(const char *params)
74
90
75
91
// Parse parameters and check configuration
76
92
try {
77
- parse_root (params_ctx);
93
+ parse_root (params_ctx, iemgr );
78
94
validate ();
79
95
} catch (std::exception &ex) {
80
96
throw std::runtime_error (" Failed to parse the configuration: " + std::string (ex.what ()));
@@ -93,6 +109,9 @@ Config::set_default()
93
109
94
110
m_window.align = true ;
95
111
m_window.size = WINDOW_SIZE;
112
+
113
+ m_selection_used = false ;
114
+ m_selection.clear ();
96
115
}
97
116
98
117
/* *
@@ -114,10 +133,11 @@ Config::validate()
114
133
/* *
115
134
* @brief Process \<params\> node
116
135
* @param[in] ctx XML context to process
136
+ * @param[in] iemgr Information elements manager
117
137
* @throw runtime_error if the parser fails
118
138
*/
119
139
void
120
- Config::parse_root (fds_xml_ctx_t *ctx)
140
+ Config::parse_root (fds_xml_ctx_t *ctx, const fds_iemgr_t *iemgr )
121
141
{
122
142
const struct fds_xml_cont *content;
123
143
while (fds_xml_next (ctx, &content) != FDS_EOC) {
@@ -151,6 +171,11 @@ Config::parse_root(fds_xml_ctx_t *ctx)
151
171
assert (content->type == FDS_OPTS_T_CONTEXT);
152
172
parse_dump (content->ptr_ctx );
153
173
break ;
174
+ case NODE_SELECTION:
175
+ // Output selection
176
+ assert (content->type == FDS_OPTS_T_CONTEXT);
177
+ parse_selection (content->ptr_ctx , iemgr);
178
+ break ;
154
179
default :
155
180
// Internal error
156
181
throw std::runtime_error (" Unknown XML node" );
@@ -187,4 +212,38 @@ Config::parse_dump(fds_xml_ctx_t *ctx)
187
212
throw std::runtime_error (" Unknown XML node" );
188
213
}
189
214
}
190
- }
215
+ }
216
+
217
+ /* *
218
+ * @brief Auxiliary function for parsing \<outputSelection\> options
219
+ * @param[in] ctx XML context to process
220
+ * @param[in] iemgr Information elements manager
221
+ * @throw runtime_error if the parser fails
222
+ */
223
+ void
224
+ Config::parse_selection (fds_xml_ctx_t *ctx, const fds_iemgr_t * iemgr)
225
+ {
226
+ m_selection_used = true ;
227
+
228
+ const struct fds_xml_cont *content;
229
+ while (fds_xml_next (ctx, &content) != FDS_EOC) {
230
+ switch (content->id ) {
231
+ case SELECTION_ELEMENT: {
232
+ // IPFIX element to select
233
+ assert (content->type == FDS_OPTS_T_STRING);
234
+
235
+ const fds_iemgr_elem* ie = fds_iemgr_elem_find_name (iemgr, content->ptr_string );
236
+ if (!ie) {
237
+ throw std::runtime_error (" Element \" " + std::string (content->ptr_string ) + " \" not found!" );
238
+ }
239
+ element elem;
240
+ elem.pen = ie->scope ->pen ;
241
+ elem.id = ie->id ;
242
+ m_selection.push_back (elem);
243
+ } break ;
244
+ default :
245
+ // Internal error
246
+ throw std::runtime_error (" Unknown XML node" );
247
+ }
248
+ }
249
+ }
0 commit comments