mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | Protected Attributes | Friends | Related Functions | List of all members
ConfigParser Class Reference

#include <ConfigParser.hpp>

Collaboration diagram for ConfigParser:
Collaboration graph

Public Member Functions

 ConfigParser (std::string filename)
 
 ConfigParser (const ConfigParser &other)=delete
 
 ConfigParser (ConfigParser &&other)=delete
 
std::unique_ptr< Appmake_app ()
 
ConfigParseroperator= (const ConfigParser &other)=delete
 
ConfigParseroperator= (ConfigParser &&other)=delete
 

Protected Attributes

tao::pegtl::read_input in_
 
std::unique_ptr< config::parse_tree::node > root_
 

Friends

std::ostream & operator<< (std::ostream &os, const ConfigParser &config_parser)
 

Related Functions

(Note that these are not member functions.)

std::map< std::string, std::shared_ptr< Chain > > init_chains (const config::parse_tree::node &root)
 
std::unique_ptr< Ruleparse_action (const config::parse_tree::node &root, std::optional< int > priority, std::optional< If > condition, const std::map< std::string, std::shared_ptr< Chain >> &chains)
 
void parse_chain (Chain &chain, const config::parse_tree::node &root, const std::map< std::string, std::shared_ptr< Chain >> &chains)
 
If parse_condition (const config::parse_tree::node &root)
 
std::unique_ptr< Filterparse_filter (const config::parse_tree::node &root)
 
std::vector< std::unique_ptr< Interface > > parse_interfaces (const config::parse_tree::node &root, std::unique_ptr< Filter > filter)
 
std::unique_ptr< SerialInterfaceparse_serial (const config::parse_tree::node &root, std::shared_ptr< Filter > filter, std::shared_ptr< ConnectionPool > pool)
 
std::unique_ptr< UDPInterfaceparse_udp (const config::parse_tree::node &root, std::shared_ptr< Filter > filter, std::shared_ptr< ConnectionPool > pool)
 

Detailed Description

Configuration file parser.

Used to parse a configuration file and create an instance of the mavtables application.

Definition at line 74 of file ConfigParser.hpp.

Constructor & Destructor Documentation

◆ ConfigParser() [1/3]

ConfigParser::ConfigParser ( std::string  filename)

Construct a configuration parser from a file.

Parameters
filenameThe path of the configuration file to parse.
Exceptions
std::runtime_errorif the configuration file cannot be parsed.

Definition at line 443 of file ConfigParser.cpp.

References in_, config::parse(), and root_.

Here is the call graph for this function:

◆ ConfigParser() [2/3]

ConfigParser::ConfigParser ( const ConfigParser other)
delete

◆ ConfigParser() [3/3]

ConfigParser::ConfigParser ( ConfigParser &&  other)
delete

Member Function Documentation

◆ make_app()

std::unique_ptr< App > ConfigParser::make_app ( )

Build a mavtables application from the AST contained by the parser.

Returns
A mavtables application.

Definition at line 464 of file ConfigParser.cpp.

References parse_filter(), parse_interfaces(), and root_.

Here is the call graph for this function:

◆ operator=() [1/2]

ConfigParser& ConfigParser::operator= ( const ConfigParser other)
delete

◆ operator=() [2/2]

ConfigParser& ConfigParser::operator= ( ConfigParser &&  other)
delete

Friends And Related Function Documentation

◆ init_chains()

std::map< std::string, std::shared_ptr< Chain > > init_chains ( const config::parse_tree::node &  root)
related

Construct a map of non default chains.

Parameters
rootRoot of configuration AST.
Returns
Map of chain names to chains.

Definition at line 54 of file ConfigParser.cpp.

Here is the caller graph for this function:

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const ConfigParser config_parser 
)
friend

Print the configuration settings to the given output stream.

An example (that of test/mavtables.conf) is:

===== test/mavtables.conf =====
:001: default_action
:001: | accept
:004: udp
:005: | port 14500
:006: | address 127.0.0.1
:007: | max_bitrate 8388608
:011: serial
:012: | device ./ttyS0
:013: | baudrate 115200
:014: | flow_control yes
:015: | preload 1.1
:016: | preload 62.34
:020: chain default
:022: | call some_chain10
:022: | | condition
:022: | | | source 127.1
:022: | | | dest 192.0
:023: | reject
:027: chain some_chain10
:029: | accept
:029: | | priority 99
:029: | | condition
:029: | | | dest 192.0
:030: | accept
:030: | | condition
:030: | | | packet_type PING
:031: | accept
Parameters
osThe output stream to print to.
config_parserThe configuration parser to print.
Returns
The output stream.

Definition at line 512 of file ConfigParser.cpp.

◆ parse_action()

std::unique_ptr< Rule > parse_action ( const config::parse_tree::node &  root,
std::optional< int >  priority,
std::optional< If condition,
const std::map< std::string, std::shared_ptr< Chain >> &  chains 
)
related

Construct a Rule with action from AST, priority, and condition.

Parameters
rootAST action node.
priorityThe priority to use when constructing the action. No priority if {}. If the AST node is a reject action the priority will be ignored.
conditionThe condition to use when constructing the action.
chainsMap of chain names to chains for call and goto actions.
Returns
The action (or rule) parsed from the given AST node, priority, and condition.
Exceptions
std::invalid_argumentif the action attempts to call or goto the default chain.
std::runtime_errorif the action is not one of accept, reject, call, or goto.

Definition at line 92 of file ConfigParser.cpp.

Here is the caller graph for this function:

◆ parse_chain()

void parse_chain ( Chain chain,
const config::parse_tree::node &  root,
const std::map< std::string, std::shared_ptr< Chain >> &  chains 
)
related

Add Rule's from AST to a Chain.

Parameters
chainChain to add rules to.
rootAST chain node containing rules.
chainsMap of chain names to chains for call and goto actions.

Definition at line 176 of file ConfigParser.cpp.

References Chain::append(), parse_action(), and parse_condition().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_condition()

If parse_condition ( const config::parse_tree::node &  root)
related

Construct conditional (If) from AST.

Parameters
rootAST conditional node.
Returns
The conditional constructed from the given AST node.

Definition at line 216 of file ConfigParser.cpp.

References If::from(), If::to(), and If::type().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_filter()

std::unique_ptr< Filter > parse_filter ( const config::parse_tree::node &  root)
related

Parse Filter from AST.

Parameters
rootRoot of configuration AST.
Returns
The Filter parsed from the AST.

Definition at line 250 of file ConfigParser.cpp.

References init_chains(), and parse_chain().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_interfaces()

std::vector< std::unique_ptr< Interface > > parse_interfaces ( const config::parse_tree::node &  root,
std::unique_ptr< Filter filter 
)
related

Parse UDP and serial port interfaces from AST root.

Parameters
rootThe root of the AST to create Interface's from.
filterThe packet Filter to use for the interfaces.
Returns
A vector of UDP and serial port interfaces.

Definition at line 292 of file ConfigParser.cpp.

References parse_serial(), and parse_udp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_serial()

std::unique_ptr< SerialInterface > parse_serial ( const config::parse_tree::node &  root,
std::shared_ptr< Filter filter,
std::shared_ptr< ConnectionPool pool 
)
related

Parse a serial port interface from an AST.

Parameters
rootThe serial port node to parse.
filterThe Filter to use for the SerialInterface.
poolThe connection pool to add the interface's connection to.
Returns
The serial port interface parsed from the AST and using the given filter and connection pool.
Exceptions
std::invalid_argumentif the device string is missing.

Definition at line 330 of file ConfigParser.cpp.

References SerialPort::DEFAULT, SerialPort::FLOW_CONTROL, and to_lower().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_udp()

std::unique_ptr< UDPInterface > parse_udp ( const config::parse_tree::node &  root,
std::shared_ptr< Filter filter,
std::shared_ptr< ConnectionPool pool 
)
related

Parse a UPD interface from an AST.

Parameters
rootThe UDP node to parse.
filterThe Filter to use for the UDPInterface.
poolThe connection pool to add the interface's connections to.
Returns
The UDP interface parsed from the AST and using the given filter and connection pool.

Definition at line 400 of file ConfigParser.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ in_

tao::pegtl::read_input ConfigParser::in_
protected

Definition at line 88 of file ConfigParser.hpp.

◆ root_

std::unique_ptr<config::parse_tree::node> ConfigParser::root_
protected

Definition at line 89 of file ConfigParser.hpp.


The documentation for this class was generated from the following files: