11/* *
22 * \file src/plugins/output/fds/src/Config.cpp 
33 * \author Lukas Hutak <[email protected] > 4+  * \author Michal Sedlak <[email protected] > 45 * \brief Parser of XML configuration (source file) 
56 * \date 2019 
67 * 
2122 *     <align>...</align>                 <!-- optional --> 
2223 *   </dumpInterval> 
2324 *   <asyncIO>...</asyncIO>               <!-- optional --> 
25+  *   <outputSelection>                    <!-- optional --> 
26+  *     <element>...</element> 
27+  *     <element>...</element> 
28+  *     ... 
29+  *   </outputSelection> 
2430 * </params> 
2531 */  
2632
@@ -30,9 +36,12 @@ enum params_xml_nodes {
3036    NODE_COMPRESS,
3137    NODE_DUMP,
3238    NODE_ASYNCIO,
39+     NODE_SELECTION,
3340
3441    DUMP_WINDOW,
35-     DUMP_ALIGN
42+     DUMP_ALIGN,
43+ 
44+     SELECTION_ELEMENT,
3645};
3746
3847// / Definition of the \<dumpInterval\> node
@@ -42,17 +51,24 @@ static const struct fds_xml_args args_dump[] = {
4251    FDS_OPTS_END
4352};
4453
54+ // / Definition of the \<outputSelection\> node
55+ static  const  struct  fds_xml_args  args_selection[] = {
56+     FDS_OPTS_ELEM (SELECTION_ELEMENT,   " element" 
57+     FDS_OPTS_END
58+ };
59+ 
4560// / Definition of the \<params\> node
4661static  const  struct  fds_xml_args  args_params[] = {
4762    FDS_OPTS_ROOT (" params" 
48-     FDS_OPTS_ELEM (NODE_STORAGE,  " storagePath" 0 ),
49-     FDS_OPTS_ELEM (NODE_COMPRESS, " compression" 
50-     FDS_OPTS_NESTED (NODE_DUMP,   " dumpInterval" 
51-     FDS_OPTS_ELEM (NODE_ASYNCIO,  " asyncIO" 
63+     FDS_OPTS_ELEM (NODE_STORAGE,     " storagePath" 0 ),
64+     FDS_OPTS_ELEM (NODE_COMPRESS,    " compression" 
65+     FDS_OPTS_NESTED (NODE_DUMP,      " dumpInterval" 
66+     FDS_OPTS_ELEM (NODE_ASYNCIO,     " asyncIO" 
67+     FDS_OPTS_NESTED (NODE_SELECTION, " outputSelection" 
5268    FDS_OPTS_END
5369};
5470
55- Config::Config (const  char  *params)
71+ Config::Config (const  char  *params,  const   fds_iemgr_t  *iemgr )
5672{
5773    set_default ();
5874
@@ -74,7 +90,7 @@ Config::Config(const char *params)
7490
7591    //  Parse parameters and check configuration
7692    try  {
77-         parse_root (params_ctx);
93+         parse_root (params_ctx, iemgr );
7894        validate ();
7995    } catch  (std::exception &ex) {
8096        throw  std::runtime_error (" Failed to parse the configuration: " std::string (ex.what ()));
@@ -93,6 +109,9 @@ Config::set_default()
93109
94110    m_window.align  = true ;
95111    m_window.size  = WINDOW_SIZE;
112+ 
113+     m_selection_used = false ;
114+     m_selection.clear ();
96115}
97116
98117/* *
@@ -114,10 +133,11 @@ Config::validate()
114133/* *
115134 * @brief Process \<params\> node 
116135 * @param[in] ctx XML context to process 
136+  * @param[in] iemgr Information elements manager 
117137 * @throw runtime_error if the parser fails 
118138 */  
119139void 
120- Config::parse_root (fds_xml_ctx_t  *ctx)
140+ Config::parse_root (fds_xml_ctx_t  *ctx,  const   fds_iemgr_t  *iemgr )
121141{
122142    const  struct  fds_xml_cont  *content;
123143    while  (fds_xml_next (ctx, &content) != FDS_EOC) {
@@ -151,6 +171,11 @@ Config::parse_root(fds_xml_ctx_t *ctx)
151171            assert (content->type  == FDS_OPTS_T_CONTEXT);
152172            parse_dump (content->ptr_ctx );
153173            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 ;
154179        default :
155180            //  Internal error
156181            throw  std::runtime_error (" Unknown XML node" 
@@ -187,4 +212,38 @@ Config::parse_dump(fds_xml_ctx_t *ctx)
187212            throw  std::runtime_error (" Unknown XML node" 
188213        }
189214    }
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