2021-07-20 16:43:13 +00:00
|
|
|
pub mod contact;
|
2021-07-20 16:10:56 +00:00
|
|
|
pub mod domain;
|
2021-07-23 19:23:01 +00:00
|
|
|
pub mod host;
|
|
|
|
pub mod message;
|
2021-07-20 16:10:56 +00:00
|
|
|
|
2021-07-25 14:34:01 +00:00
|
|
|
use serde::{ser::SerializeStruct, ser::Serializer, Deserialize, Serialize};
|
2021-07-16 19:16:28 +00:00
|
|
|
use std::error::Error;
|
2021-07-19 17:56:10 +00:00
|
|
|
use std::time::SystemTime;
|
2021-07-16 19:16:28 +00:00
|
|
|
|
2021-07-20 07:45:01 +00:00
|
|
|
use crate::epp::object::{
|
2021-07-20 16:10:56 +00:00
|
|
|
ElementName, EppObject, Options, ServiceExtension, Services, StringValue, StringValueTrait,
|
2021-07-20 07:45:01 +00:00
|
|
|
};
|
2021-07-23 19:23:01 +00:00
|
|
|
use crate::epp::xml::{EPP_CONTACT_XMLNS, EPP_DOMAIN_XMLNS, EPP_HOST_XMLNS, EPP_LANG, EPP_VERSION};
|
2021-07-22 10:35:20 +00:00
|
|
|
use epp_client_macros::*;
|
2021-07-16 19:16:28 +00:00
|
|
|
|
2021-07-20 16:10:56 +00:00
|
|
|
pub type EppHello = EppObject<Hello>;
|
|
|
|
pub type EppLogin = EppObject<Command<Login>>;
|
|
|
|
pub type EppLogout = EppObject<Command<Logout>>;
|
2021-07-16 19:16:28 +00:00
|
|
|
|
2021-07-25 14:34:01 +00:00
|
|
|
#[derive(Deserialize, Debug, PartialEq, ElementName)]
|
|
|
|
#[element_name(name = "command")]
|
|
|
|
pub struct Command<T: ElementName> {
|
|
|
|
pub command: T,
|
|
|
|
#[serde(rename = "clTRID")]
|
|
|
|
pub client_tr_id: StringValue,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: ElementName + Serialize> Serialize for Command<T> {
|
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
let command_name = self.command.element_name();
|
|
|
|
let mut state = serializer.serialize_struct("command", 2)?;
|
|
|
|
state.serialize_field(command_name, &self.command)?;
|
|
|
|
state.serialize_field("clTRID", &self.client_tr_id)?;
|
|
|
|
state.end()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-20 16:10:56 +00:00
|
|
|
pub fn generate_client_tr_id(username: &str) -> Result<String, Box<dyn Error>> {
|
|
|
|
let timestamp = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
|
|
|
|
Ok(format!("{}:{}", username, timestamp.as_secs()))
|
2021-07-16 19:16:28 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 10:35:20 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
|
|
|
#[element_name(name = "hello")]
|
2021-07-16 19:16:28 +00:00
|
|
|
pub struct Hello;
|
|
|
|
|
2021-07-20 16:43:13 +00:00
|
|
|
impl EppHello {
|
|
|
|
pub fn new() -> EppHello {
|
|
|
|
EppObject::build(Hello {})
|
2021-07-20 16:10:56 +00:00
|
|
|
}
|
2021-07-16 19:16:28 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 10:35:20 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
|
|
|
#[element_name(name = "login")]
|
2021-07-16 19:16:28 +00:00
|
|
|
pub struct Login {
|
|
|
|
#[serde(rename(serialize = "clID", deserialize = "clID"))]
|
|
|
|
username: StringValue,
|
|
|
|
#[serde(rename = "pw", default)]
|
|
|
|
password: StringValue,
|
2021-07-20 07:45:01 +00:00
|
|
|
options: Options,
|
2021-07-16 19:16:28 +00:00
|
|
|
#[serde(rename = "svcs")]
|
|
|
|
services: Services,
|
|
|
|
}
|
|
|
|
|
2021-07-20 16:43:13 +00:00
|
|
|
impl EppLogin {
|
2021-07-23 19:23:01 +00:00
|
|
|
pub fn new(
|
|
|
|
username: &str,
|
|
|
|
password: &str,
|
|
|
|
ext_uris: &Option<Vec<String>>,
|
|
|
|
client_tr_id: &str,
|
|
|
|
) -> EppLogin {
|
|
|
|
let ext_uris = match ext_uris {
|
|
|
|
Some(uris) => Some(
|
|
|
|
uris.iter()
|
|
|
|
.map(|u| u.to_string_value())
|
|
|
|
.collect::<Vec<StringValue>>(),
|
|
|
|
),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
2021-07-16 19:16:28 +00:00
|
|
|
let login = Login {
|
|
|
|
username: username.to_string_value(),
|
|
|
|
password: password.to_string_value(),
|
2021-07-20 07:45:01 +00:00
|
|
|
options: Options {
|
2021-07-16 19:16:28 +00:00
|
|
|
version: EPP_VERSION.to_string_value(),
|
|
|
|
lang: EPP_LANG.to_string_value(),
|
|
|
|
},
|
|
|
|
services: Services {
|
|
|
|
obj_uris: vec![
|
2021-07-23 19:23:01 +00:00
|
|
|
EPP_HOST_XMLNS.to_string_value(),
|
|
|
|
EPP_CONTACT_XMLNS.to_string_value(),
|
|
|
|
EPP_DOMAIN_XMLNS.to_string_value(),
|
2021-07-16 19:16:28 +00:00
|
|
|
],
|
2021-07-23 19:23:01 +00:00
|
|
|
svc_ext: Some(ServiceExtension { ext_uris: ext_uris }),
|
2021-07-16 19:16:28 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-07-20 16:43:13 +00:00
|
|
|
EppObject::build(Command::<Login> {
|
2021-07-20 16:10:56 +00:00
|
|
|
command: login,
|
2021-07-16 19:16:28 +00:00
|
|
|
client_tr_id: client_tr_id.to_string_value(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-07-20 07:45:01 +00:00
|
|
|
pub fn set_options(&mut self, options: Options) {
|
2021-07-20 16:43:13 +00:00
|
|
|
self.data.command.options = options;
|
2021-07-16 19:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_services(&mut self, services: Services) {
|
2021-07-20 16:43:13 +00:00
|
|
|
self.data.command.services = services;
|
2021-07-16 19:16:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 18:17:57 +00:00
|
|
|
|
2021-07-22 10:35:20 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, ElementName)]
|
|
|
|
#[element_name(name = "logout")]
|
2021-07-19 18:17:57 +00:00
|
|
|
pub struct Logout;
|
|
|
|
|
2021-07-20 16:43:13 +00:00
|
|
|
impl EppLogout {
|
|
|
|
pub fn new(client_tr_id: &str) -> EppLogout {
|
|
|
|
EppObject::build(Command::<Logout> {
|
2021-07-20 16:10:56 +00:00
|
|
|
command: Logout,
|
2021-07-19 18:17:57 +00:00
|
|
|
client_tr_id: client_tr_id.to_string_value(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|