|
|
|
@ -9,6 +9,7 @@ use common_types::{Class, Type, types};
|
|
|
|
|
use errors::*; |
|
|
|
|
use records::structs; |
|
|
|
|
use ser::{RRData, StaticRRData}; |
|
|
|
|
use ser::text::DnsTextContext; |
|
|
|
|
|
|
|
|
|
// this should be enough for registered names
|
|
|
|
|
const TYPE_NAME_MAX_LEN: usize = 16; |
|
|
|
@ -42,6 +43,26 @@ pub fn known_name_to_type(name: &str) -> Option<Type> {
|
|
|
|
|
Some(t) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn deserialize_rr_data(ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor<Bytes>) -> Result<Box<RRData>> { |
|
|
|
|
let registry = registry(); |
|
|
|
|
match registry.type_parser.get(&rr_type) { |
|
|
|
|
Some(p) => p.deserialize_rr_data(ttl, rr_class, rr_type, data), |
|
|
|
|
None => Ok(Box::new(super::UnknownRecord::deserialize(rr_type, data)?) as _), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn parse_rr_data(context: &DnsTextContext, data: &mut &str) -> Result<Box<RRData>> { |
|
|
|
|
let registry = registry(); |
|
|
|
|
let t = match context.record_type() { |
|
|
|
|
Some(t) => t, |
|
|
|
|
None => bail!("require record type to parse record data"), |
|
|
|
|
}; |
|
|
|
|
match registry.type_parser.get(&t) { |
|
|
|
|
Some(p) => p.parse_rr_data(context, data), |
|
|
|
|
None => bail!("unknown type: {}", t), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub(crate) fn lookup_type_to_name(rrtype: Type) -> Option<&'static str> { |
|
|
|
|
let registry = registry(); |
|
|
|
|
registry.type_names.get(&rrtype).map(|s| s as _) |
|
|
|
@ -61,12 +82,18 @@ trait RRDataTypeParse: 'static {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn deserialize_rr_data(&self, ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor<Bytes>) -> Result<Box<RRData>>; |
|
|
|
|
|
|
|
|
|
fn parse_rr_data(&self, context: &DnsTextContext, data: &mut &str) -> Result<Box<RRData>>; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl<T: RRData + 'static> RRDataTypeParse for TagRRDataType<T> { |
|
|
|
|
fn deserialize_rr_data(&self, ttl: u32, rr_class: Class, rr_type: Type, data: &mut Cursor<Bytes>) -> Result<Box<RRData>> { |
|
|
|
|
T::deserialize_rr_data(ttl, rr_class, rr_type, data).map(|d| Box::new(d) as _) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn parse_rr_data(&self, context: &DnsTextContext, data: &mut &str) -> Result<Box<RRData>> { |
|
|
|
|
T::dns_parse_rr_data(context, data).map(|d| Box::new(d) as _) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct Registry { |
|
|
|
|