instant_epp/
common.rs

1//! Common data types included in EPP Requests and Responses
2
3use std::borrow::Cow;
4
5use instant_xml::{FromXml, ToXml};
6
7use crate::request::Extension;
8
9pub(crate) const EPP_XMLNS: &str = "urn:ietf:params:xml:ns:epp-1.0";
10
11#[derive(Debug, Eq, PartialEq, ToXml)]
12pub struct NoExtension;
13
14impl<'xml> FromXml<'xml> for NoExtension {
15    fn matches(_: instant_xml::Id<'_>, _: Option<instant_xml::Id<'_>>) -> bool {
16        false
17    }
18
19    fn deserialize<'cx>(
20        _: &mut Self::Accumulator,
21        _: &'static str,
22        _: &mut instant_xml::Deserializer<'cx, 'xml>,
23    ) -> Result<(), instant_xml::Error> {
24        unreachable!()
25    }
26
27    type Accumulator = Option<Self>;
28    const KIND: instant_xml::Kind = instant_xml::Kind::Element;
29}
30
31impl Extension for NoExtension {
32    type Response = Self;
33}
34
35/// The `<option>` type in EPP XML login requests
36#[derive(Debug, Eq, FromXml, PartialEq, ToXml)]
37#[xml(rename = "options", ns(EPP_XMLNS))]
38pub struct Options<'a> {
39    /// The EPP version being used
40    pub version: Cow<'a, str>,
41    /// The language that will be used during EPP transactions
42    pub lang: Cow<'a, str>,
43}
44
45impl<'a> Options<'a> {
46    /// Creates an Options object with version and lang data
47    pub fn build(version: &'a str, lang: &'a str) -> Self {
48        Self {
49            version: version.into(),
50            lang: lang.into(),
51        }
52    }
53}
54
55/// The `<svcExtension>` type in EPP XML
56#[derive(Debug, Eq, FromXml, PartialEq, ToXml)]
57#[xml(rename = "svcExtension", ns(EPP_XMLNS))]
58pub struct ServiceExtension<'a> {
59    /// The service extension URIs being represented by `<extURI>` in EPP XML
60    #[xml(rename = "extURI")]
61    pub ext_uris: Vec<Cow<'a, str>>,
62}
63
64/// The `<svcs>` type in EPP XML
65#[derive(Debug, Eq, FromXml, PartialEq, ToXml)]
66#[xml(rename = "svcs", ns(EPP_XMLNS))]
67pub struct Services<'a> {
68    /// The service URIs being used by this EPP session represented by `<objURI>` in EPP XML
69    #[xml(rename = "objURI")]
70    pub obj_uris: Vec<Cow<'a, str>>,
71    // The `<svcExtension>` being used in this EPP session
72    #[xml(rename = "svcExtension")]
73    pub svc_ext: Option<ServiceExtension<'a>>,
74}