libfireparse/lib.rs
1mod models;
2mod pfsense;
3mod utils;
4
5pub use models::*;
6pub use nullnet_libconfmon::{FileData, Platform, Snapshot};
7use pfsense::PfSenseParser;
8
9/// Represents possible errors that can occur while parsing firewall configurations.
10pub enum FireparseError {
11 UnsupportedPlatform(String),
12 ParserError(String),
13}
14
15/// A generic parser for firewall configuration files.
16///
17/// This parser determines the correct parsing logic based on the specified platform.
18pub struct Parser {}
19
20impl Parser {
21 /// Parses a firewall configuration snapshot based on the specified platform.
22 ///
23 /// # Arguments
24 /// * `platform` - The firewall platform (e.g., `Platform::PfSense` or `Platform::OPNsense`).
25 /// * `snapshot` - A `Snapshot` representing the firewall configuration state.
26 ///
27 /// # Returns
28 /// * `Ok(Configuration)` - If parsing is successful, returns a `Configuration` struct.
29 /// * `Err(FireparseError)` - If the platform is unsupported or the snapshot is invalid.
30 ///
31 /// # Supported Platforms
32 /// - `Platform::PfSense`: Uses `PfSenseParser` to process pfSense configurations.
33 /// - `Platform::OPNsense`: Currently not implemented (`todo!()` placeholder).
34 pub fn parse(platfom: Platform, snapshot: Snapshot) -> Result<Configuration, FireparseError> {
35 match platfom {
36 Platform::PfSense => PfSenseParser::parse(snapshot),
37 Platform::OPNsense => todo!(),
38 }
39 }
40}