diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-22 12:48:08 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-22 12:48:08 +0200 |
commit | e1b8f879044310795424a2fe1c302648aa866178 (patch) | |
tree | ea21a10ded4d77405ee63e7057dcf306e4728cb2 | |
parent | f7c4895386a974f0d985222bea5b3965e6b8b290 (diff) |
add nameserver.info
-rw-r--r-- | src/call/mod.rs | 1 | ||||
-rw-r--r-- | src/call/nameserver.rs | 110 |
2 files changed, 111 insertions, 0 deletions
diff --git a/src/call/mod.rs b/src/call/mod.rs index 83de339..51fca5a 100644 --- a/src/call/mod.rs +++ b/src/call/mod.rs @@ -5,3 +5,4 @@ pub trait Call: Into<xmlrpc::Value> { } pub mod account; +pub mod nameserver; diff --git a/src/call/nameserver.rs b/src/call/nameserver.rs new file mode 100644 index 0000000..01a5d41 --- /dev/null +++ b/src/call/nameserver.rs @@ -0,0 +1,110 @@ +use super::Call; + +use std::collections::BTreeMap; +use std::fmt; + +/// The DNS record type. +#[derive(Clone, Copy, Debug)] +pub enum RecordType { + A, + AAAA, + AFSDB, + ALIAS, + CAA, + CERT, + CNAME, + HINFO, + KEY, + LOC, + MX, + NAPTR, + NS, + OPENPGPKEY, + PTR, + RP, + SMIMEA, + SOA, + SRV, + SSHFP, + TLSA, + TXT, + URI, + URL, +} + +impl fmt::Display for RecordType { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + A => write!(fmt, "A"), + AAAA => write!(fmt, "AAAA"), + AFSDB => write!(fmt, "AFSDB"), + ALIAS => write!(fmt, "ALIAS"), + CAA => write!(fmt, "CAA"), + CERT => write!(fmt, "CERT"), + CNAME => write!(fmt, "CNAME"), + HINFO => write!(fmt, "HINFO"), + KEY => write!(fmt, "KEY"), + LOC => write!(fmt, "LOC"), + MX => write!(fmt, "MX"), + NAPTR => write!(fmt, "NAPTR"), + NS => write!(fmt, "NS"), + OPENPGPKEY => write!(fmt, "OPENPGPKEY"), + PTR => write!(fmt, "PTR"), + RP => write!(fmt, "RP"), + SMIMEA => write!(fmt, "SMIMEA"), + SOA => write!(fmt, "SOA"), + SRV => write!(fmt, "SRV"), + SSHFP => write!(fmt, "SSHFP"), + TLSA => write!(fmt, "TLSA"), + TXT => write!(fmt, "TXT"), + URI => write!(fmt, "URI"), + URL => write!(fmt, "URL"), + } + } +} + +impl From<RecordType> for xmlrpc::Value { + fn from(rt: RecordType) -> Self { + xmlrpc::Value::String(rt.to_string()) + } +} + +/// Search parameters to find nameserver records +/// the account has access to. +#[derive(Clone, Copy, Debug)] +pub struct RecordInfo<'a> { + pub domain_name: &'a str, + pub domain_id: i32, + pub record_id: i32, + pub record_type: RecordType, + pub name: &'a str, + pub content: &'a str, + pub ttl: i32, + pub priority: i32, +} + +impl From<RecordInfo<'_>> for xmlrpc::Value { + fn from(info: RecordInfo<'_>) -> Self { + let mut map = BTreeMap::new(); + + map.insert("domain".into(), info.domain_name.into()); + map.insert("roId".into(), info.domain_id.into()); + map.insert("recordId".into(), info.record_id.into()); + map.insert("type".into(), info.record_type.into()); + map.insert("content".into(), info.content.into()); + map.insert("ttl".into(), info.ttl.into()); + map.insert("prio".into(), info.priority.into()); + + xmlrpc::Value::Struct(map) + } +} + +impl Call for RecordInfo<'_> { + fn method_name(&self) -> &'static str { + "nameserver.info" + } + + fn expected(&self) -> &'static [i32] { + &[1000] + } +} |