wip: xml parser

This commit is contained in:
Jean-Gabriel Gill-Couture 2024-10-04 11:26:55 -04:00
parent 407bdbc032
commit 6a5ebdbac7
4 changed files with 40 additions and 69 deletions

97
harmony-rs/Cargo.lock generated
View File

@ -247,15 +247,6 @@ version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
[[package]]
name = "castaway"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5"
dependencies = [
"rustversion",
]
[[package]]
name = "cbc"
version = "0.1.2"
@ -313,19 +304,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "compact_str"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f"
dependencies = [
"castaway",
"cfg-if",
"itoa",
"ryu",
"static_assertions",
]
[[package]]
name = "const-oid"
version = "0.9.6"
@ -828,7 +806,6 @@ dependencies = [
"env_logger",
"libredfish",
"log",
"minidom",
"reqwest",
"russh",
"rust-ipmi",
@ -836,6 +813,7 @@ dependencies = [
"serde",
"serde_json",
"tokio",
"xml_dom",
]
[[package]]
@ -1081,15 +1059,6 @@ version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]]
name = "minidom"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e394a0e3c7ccc2daea3dffabe82f09857b6b510cb25af87d54bf3e910ac1642d"
dependencies = [
"rxml",
]
[[package]]
name = "miniz_oxide"
version = "0.7.4"
@ -1452,6 +1421,15 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "quick-xml"
version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe"
dependencies = [
"memchr",
]
[[package]]
name = "quote"
version = "1.0.37"
@ -1753,31 +1731,6 @@ dependencies = [
"base64",
]
[[package]]
name = "rustversion"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
[[package]]
name = "rxml"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65bc94b580d0f5a6b7a2d604e597513d3c673154b52ddeccd1d5c32360d945ee"
dependencies = [
"bytes",
"rxml_validation",
]
[[package]]
name = "rxml_validation"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e80413b9a35e9d33217b3dcac04cf95f6559d15944b93887a08be5496c4a4"
dependencies = [
"compact_str",
]
[[package]]
name = "ryu"
version = "1.0.18"
@ -2039,12 +1992,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "subtle"
version = "2.6.1"
@ -2218,9 +2165,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.32"
@ -2583,6 +2542,18 @@ dependencies = [
"tap",
]
[[package]]
name = "xml_dom"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "836bd445caf6b9e969199f2a9667d58b433b286ddb515764303ab75a6d17e51f"
dependencies = [
"log",
"quick-xml",
"regex",
"tracing",
]
[[package]]
name = "zerocopy"
version = "0.7.35"

View File

@ -17,4 +17,4 @@ derive-new = "0.7.0"
async-trait = "0.1.82"
tokio = { version = "1.40.0", features = ["io-std"] }
cidr = "0.2.3"
minidom = "0.16.0"
xml_dom = "0.2.8"

View File

@ -17,4 +17,4 @@ log = { workspace = true }
env_logger = { workspace = true }
async-trait = { workspace = true }
cidr = { workspace = true }
minidom = { workspace = true }
xml_dom = { workspace = true }

View File

@ -10,11 +10,12 @@ impl OPNSenseXmlConfigEditor {
#[cfg(test)]
mod test {
use minidom::Element;
use std::fs;
use std::io::{BufReader, Read};
use std::process::Command;
use xml_dom::parser::read_xml;
// #[test]
// fn should_not_alter_config() {
// let path = "./private_repos/affilium_mcd/private/config.xml";
@ -34,10 +35,9 @@ mod test {
let file_str = fs::read_to_string(path).expect("Failed to read file");
// Parse with minidom
let root: Element = file_str.parse().unwrap();
let root = read_xml(&file_str).unwrap();
// Save file with suffix name
fs::write(&output_path, String::from(&root)).expect("Failed to write output file");
assert_eq!(&root.to_string(), &file_str);
}
}