2021-07-26 15:51:37 +00:00
|
|
|
//! Types for EPP requests
|
|
|
|
|
2021-11-26 21:50:22 +00:00
|
|
|
use std::fmt::Debug;
|
2021-07-16 19:16:28 +00:00
|
|
|
|
2022-11-21 19:34:25 +00:00
|
|
|
use instant_xml::{FromXmlOwned, ToXml};
|
|
|
|
|
|
|
|
use crate::common::EPP_XMLNS;
|
2021-07-16 19:16:28 +00:00
|
|
|
|
2021-11-26 19:36:28 +00:00
|
|
|
pub const EPP_VERSION: &str = "1.0";
|
|
|
|
pub const EPP_LANG: &str = "en";
|
|
|
|
|
2021-11-26 21:50:22 +00:00
|
|
|
/// Trait to set correct value for xml tags when tags are being generated from generic types
|
2022-03-12 17:12:16 +00:00
|
|
|
pub trait Transaction<Ext: Extension>: Command + Sized {}
|
2021-11-26 21:50:22 +00:00
|
|
|
|
2022-11-21 19:34:25 +00:00
|
|
|
pub trait Command: ToXml + Debug {
|
|
|
|
type Response: FromXmlOwned + Debug;
|
2021-12-09 09:17:00 +00:00
|
|
|
const COMMAND: &'static str;
|
|
|
|
}
|
|
|
|
|
2022-11-21 19:34:25 +00:00
|
|
|
pub trait Extension: ToXml + Debug {
|
|
|
|
type Response: FromXmlOwned + Debug;
|
2021-11-26 21:50:22 +00:00
|
|
|
}
|
|
|
|
|
2021-12-09 09:17:00 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
2023-03-02 13:27:26 +00:00
|
|
|
/// Type corresponding to the `<command>` tag in an EPP XML request
|
|
|
|
/// with an `<extension>` tag
|
2022-11-21 19:34:25 +00:00
|
|
|
pub(crate) struct CommandWrapper<'a, D, E> {
|
2023-04-14 08:13:36 +00:00
|
|
|
command: &'static str,
|
2023-03-02 13:27:26 +00:00
|
|
|
/// The instance that will be used to populate the `<command>` tag
|
2023-04-14 08:13:36 +00:00
|
|
|
data: &'a D,
|
2021-07-26 15:51:37 +00:00
|
|
|
/// The client TRID
|
2023-04-14 08:13:36 +00:00
|
|
|
extension: Option<&'a E>,
|
|
|
|
client_tr_id: String,
|
2021-07-25 14:34:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 19:34:25 +00:00
|
|
|
impl<'a, E: Extension, D: Transaction<E>> CommandWrapper<'a, D, E> {
|
|
|
|
pub(crate) fn new(data: &'a D, extension: Option<&'a E>, client_tr_id: &'a str) -> Self {
|
|
|
|
Self {
|
|
|
|
command: D::COMMAND,
|
|
|
|
data,
|
|
|
|
extension,
|
|
|
|
client_tr_id: client_tr_id.into(),
|
|
|
|
}
|
2021-07-25 14:34:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-21 19:34:25 +00:00
|
|
|
impl<'a, D: ToXml, E: ToXml> ToXml for CommandWrapper<'a, D, E> {
|
|
|
|
fn serialize<W: std::fmt::Write + ?Sized>(
|
|
|
|
&self,
|
|
|
|
_: Option<instant_xml::Id<'_>>,
|
|
|
|
serializer: &mut instant_xml::Serializer<W>,
|
|
|
|
) -> Result<(), instant_xml::Error> {
|
|
|
|
let prefix = serializer.write_start("command", EPP_XMLNS)?;
|
|
|
|
serializer.end_start()?;
|
|
|
|
self.data.serialize(None, serializer)?;
|
|
|
|
if let Some(extension) = self.extension {
|
|
|
|
Ext { inner: extension }.serialize(None, serializer)?;
|
2021-07-29 15:42:36 +00:00
|
|
|
}
|
2022-11-21 19:34:25 +00:00
|
|
|
|
|
|
|
let id_prefix = serializer.write_start("clTRID", EPP_XMLNS)?;
|
|
|
|
serializer.end_start()?;
|
|
|
|
serializer.write_str(&self.client_tr_id)?;
|
|
|
|
serializer.write_close(id_prefix, "clTRID")?;
|
|
|
|
|
|
|
|
serializer.write_close(prefix, "command")?;
|
|
|
|
Ok(())
|
2021-07-29 15:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-21 19:34:25 +00:00
|
|
|
|
|
|
|
#[derive(Debug, ToXml)]
|
|
|
|
#[xml(rename = "extension", ns(EPP_XMLNS))]
|
|
|
|
struct Ext<E> {
|
|
|
|
inner: E,
|
|
|
|
}
|