//! Types for EPP responses pub mod contact; pub mod domain; pub mod host; pub mod message; use epp_client_macros::*; use serde::{Deserialize, Deserializer, Serialize}; use std::fmt::Debug; use crate::epp::object::{ ElementName, EmptyTag, EppObject, Extension, Options, ServiceExtension, Services, StringValue, }; /// Type corresponding to the <response> tag in an EPP response without an <extension> section pub type CommandResponse = CommandResponseWithExtension; /// The EPP Greeting that is received on a successful connection and in response to an EPP hello pub type EppGreeting = EppObject; /// A generic EPP Response to an EPP command with a result section, a status code and a message pub type EppCommandResponse = EppObject; /// An alias of `EppCommandResponse` indicating an EPP Error pub type EppCommandResponseError = EppCommandResponse; /// An alias of `EppCommandResponse` received in response to a successful login request pub type EppLoginResponse = EppCommandResponse; /// An alias of `EppCommandResponse` received in response to a successful logout request pub type EppLogoutResponse = EppCommandResponse; /// Type for data within the section of an EPP greeting #[derive(Serialize, Debug, PartialEq)] pub struct ServiceMenu { pub options: Options, pub services: Services, } /// Simplified service menu type for deserialization to `ServiceMenu` type from EPP greeting XML #[derive(Serialize, Deserialize, Debug, PartialEq)] struct FlattenedServiceMenu { pub version: StringValue, pub lang: StringValue, #[serde(rename = "objURI")] pub obj_uris: Vec, #[serde(rename = "svcExtension")] pub svc_ext: Option, } impl<'de> Deserialize<'de> for ServiceMenu { /// Deserializes the data to the `ServiceMenu` type fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { let flattened_svc_menu = FlattenedServiceMenu::deserialize(deserializer)?; let svc_menu = ServiceMenu { options: Options { version: flattened_svc_menu.version, lang: flattened_svc_menu.lang, }, services: Services { obj_uris: flattened_svc_menu.obj_uris, svc_ext: flattened_svc_menu.svc_ext, }, }; Ok(svc_menu) } } /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct All; /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Access { /// Data for the tag pub all: All, } /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Admin; /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Prov; /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Purpose { /// Data for the tag pub admin: Admin, /// Data for the tag pub prov: Prov, } /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Ours; /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Public; /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Recipient { /// Data for the tag pub ours: Ours, /// Data for the tag pub public: Public, } /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Stated; /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Retention { /// Data for the tag pub stated: Stated, } /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Statement { /// Data for the tag pub purpose: Purpose, /// Data for the tag pub recipient: Recipient, /// Data for the tag pub retention: Retention, } /// Type corresponding to in the EPP greeting XML (pending more compliant implementation) #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Dcp { /// Data for the tag pub access: Access, /// Data for the tag pub statement: Statement, } #[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] #[serde(rename_all = "lowercase")] #[element_name(name = "greeting")] /// Type corresponding to the tag in the EPP greeting XML pub struct Greeting { /// The service ID #[serde(rename = "svID")] pub service_id: String, /// The date from the EPP server #[serde(rename = "svDate")] pub service_date: String, /// Data under the element #[serde(rename = "svcMenu")] pub svc_menu: ServiceMenu, /// Data under the element pub dcp: Dcp, } /// Type corresponding to the tag an EPP response XML #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Undef; /// Type corresponding to the tag under in an EPP response XML #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct ResultValue { /// The XML namespace for the tag #[serde(rename = "xmlns:epp")] xmlns: String, /// The element pub undef: Undef, } /// Type corresponding to the tag in an EPP response XML #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct ExtValue { /// Data under the tag pub value: ResultValue, /// Data under the tag pub reason: StringValue, } /// Type corresponding to the tag in an EPP response XML #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct EppResult { /// The result code pub code: u16, /// The result message #[serde(rename = "msg")] pub message: StringValue, /// Data under the tag #[serde(rename = "extValue")] pub ext_value: Option, } /// Type corresponding to the tag in an EPP response XML #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct ResponseTRID { /// The client TRID #[serde(rename = "clTRID")] pub client_tr_id: Option, /// The server TRID #[serde(rename = "svTRID")] pub server_tr_id: StringValue, } /// Type corresponding to the tag in an EPP response XML #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct MessageQueue { /// The message count pub count: u32, /// The message ID pub id: String, /// The message date #[serde(rename = "qDate")] pub date: Option, /// The message text #[serde(rename = "msg")] pub message: Option, } #[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] #[serde(rename_all = "lowercase")] #[element_name(name = "response")] /// Type corresponding to the <response> tag in an EPP response XML /// containing an <extension> tag pub struct CommandResponseWithExtension { /// Data under the tag pub result: EppResult, /// Data under the tag #[serde(rename = "msgQ")] pub message_queue: Option, #[serde(rename = "resData")] /// Data under the <resData> tag pub res_data: Option, /// Data under the <extension> tag pub extension: Option>, /// Data under the tag #[serde(rename = "trID")] pub tr_ids: ResponseTRID, } #[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)] #[element_name(name = "response")] /// Type corresponding to the <response> tag in an EPP response XML /// without or <resData> sections. Generally used for error handling pub struct CommandResponseStatus { /// Data under the tag pub result: EppResult, #[serde(rename = "trID")] /// Data under the tag pub tr_ids: ResponseTRID, } impl CommandResponseWithExtension { /// Returns the data under the corresponding <resData> from the EPP XML pub fn res_data(&self) -> Option<&T> { match &self.res_data { Some(res_data) => Some(&res_data), None => None, } } /// Returns the data under the corresponding from the EPP XML pub fn message_queue(&self) -> Option<&MessageQueue> { match &self.message_queue { Some(queue) => Some(&queue), None => None, } } }