mirror of
https://github.com/NLnetLabs/domain.git
synced 2026-09-27 04:04:53 +02:00
This PR adds zonefile/parsed.rs, zonetree/ and related examples/, which together enable, and show a library user how, to go from a zone file in presentation format to an in-memory tree of zones which can be queried to provide an answer, or walked (iterated over). The tree also supports versioned write operations and a trait based zone implementation allowing for the in-memory tree for a zone to instead be some other (a)synchornous backing store (as demonstrated by the mysql-zone.rs example). The zonetree module is feature-gated behind the unstable-zonetree feature.
32 lines
900 B
Rust
32 lines
900 B
Rust
use domain::base::name::Dname;
|
|
use domain::base::Rtype;
|
|
use domain::rdata::AllRecordData;
|
|
use domain::resolv::StubResolver;
|
|
use std::env;
|
|
use std::str::FromStr;
|
|
|
|
fn main() {
|
|
let mut args = env::args().skip(1);
|
|
let name = args
|
|
.next()
|
|
.and_then(|arg| Dname::<Vec<_>>::from_str(&arg).ok());
|
|
let rtype = args.next().and_then(|arg| Rtype::from_str(&arg).ok());
|
|
let (name, rtype) = match (name, rtype) {
|
|
(Some(name), Some(rtype)) => (name, rtype),
|
|
_ => {
|
|
println!("Usage: sync <domain> <record type>");
|
|
return;
|
|
}
|
|
};
|
|
|
|
let res = StubResolver::run(move |stub| async move {
|
|
stub.query((name, rtype)).await
|
|
});
|
|
let res = res.unwrap();
|
|
let res = res.answer().unwrap().limit_to::<AllRecordData<_, _>>();
|
|
for record in res {
|
|
let record = record.unwrap();
|
|
println!("{record}");
|
|
}
|
|
}
|