feat: DhcpConfig can now effectively manage a config file to add a static map entry

This commit is contained in:
Jean-Gabriel Gill-Couture
2024-11-18 17:05:48 -05:00
parent cb1fea1eda
commit cc9bcb902c
13 changed files with 1595 additions and 1114 deletions

View File

@@ -1,6 +1,20 @@
//mod generic_xml;
//mod maybe_string;
mod yaserde;
//pub use generic_xml::*;
//pub use maybe_string::*;
pub use yaserde::*;
use yaserde::YaSerialize;
pub fn to_xml_str<T: YaSerialize>(model: &T) -> Result<String, String> {
let yaserde_cfg = yaserde::ser::Config {
perform_indent: true,
write_document_declaration: false,
pad_self_closing: false,
..Default::default()
};
let serialized = yaserde::ser::to_string_with_config::<T>(model, &yaserde_cfg)?;
// Opnsense does not specify encoding in the document declaration
//
// yaserde / xml-rs does not allow disabling the encoding attribute in the
// document declaration
//
// So here we just manually prefix the xml document with the exact document declaration
// that opnsense uses
Ok(format!("<?xml version=\"1.0\"?>\n{serialized}\n"))
}