1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//! Types for EPP domain transfer request

use epp_client_macros::*;

use crate::epp::object::data::{AuthInfo, Period};
use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait};
use crate::epp::request::Command;
use crate::epp::xml::EPP_DOMAIN_XMLNS;
use serde::{Deserialize, Serialize};

/// Type that represents the <epp> request for transfer request for domain
///
/// ## Usage
///
/// ```ignore
/// use epp_client::EppClient;
/// use epp_client::epp::{EppDomainTransferRequest, EppDomainTransferRequestResponse};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
/// async fn main() {
///     // Create an instance of EppClient, specifying the name of the registry as in
///     // the config file
///     let mut client = match EppClient::new("verisign").await {
///         Ok(client) => client,
///         Err(e) => panic!("Failed to create EppClient: {}",  e)
///     };
///
///     // Create an EppDomainTransferRequest instance
///     let domain_transfer_request = EppDomainTransferRequest::request(
///         "eppdev-100.net", 1, "epP4uthd#v", generate_client_tr_id(&client).as_str()
///     );
///
///     // send it to the registry and receive a response of type EppDomainTransferRequestResponse
///     let response = client.transact::<_, EppDomainTransferRequestResponse>(&domain_transfer_request).await.unwrap();
///
///     println!("{:?}", response);
/// }
/// ```
pub type EppDomainTransferRequest = EppObject<Command<DomainTransfer>>;

/// Type that represents the &lt;epp&gt; request for transfer approval for domains
///
/// ## Usage
///
/// ```ignore
/// use epp_client::EppClient;
/// use epp_client::epp::{EppDomainTransferApprove, EppDomainTransferApproveResponse};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
/// async fn main() {
///     // Create an instance of EppClient, specifying the name of the registry as in
///     // the config file
///     let mut client = match EppClient::new("verisign").await {
///         Ok(client) => client,
///         Err(e) => panic!("Failed to create EppClient: {}",  e)
///     };
///
///     // Create an EppDomainTransferApprove instance
///     let domain_transfer_approve = EppDomainTransferApprove::approve(
///         "eppdev-100.net", generate_client_tr_id(&client).as_str()
///     );
///
///     // send it to the registry and receive a response of type EppDomainTransferApproveResponse
///     let response = client.transact::<_, EppDomainTransferApproveResponse>(&domain_transfer_approve).await.unwrap();
///
///     println!("{:?}", response);
/// }
/// ```
pub type EppDomainTransferApprove = EppObject<Command<DomainTransfer>>;

/// Type that represents the &lt;epp&gt; request for transfer rejection for domains
///
/// ## Usage
///
/// ```ignore
/// use epp_client::EppClient;
/// use epp_client::epp::{EppDomainTransferReject, EppDomainTransferRejectResponse};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
/// async fn main() {
///     // Create an instance of EppClient, specifying the name of the registry as in
///     // the config file
///     let mut client = match EppClient::new("verisign").await {
///         Ok(client) => client,
///         Err(e) => panic!("Failed to create EppClient: {}",  e)
///     };
///
///     // Create an EppDomainTransferReject instance
///     let domain_transfer_reject = EppDomainTransferReject::reject(
///         "eppdev-100.net", generate_client_tr_id(&client).as_str()
///     );
///
///     // send it to the registry and receive a response of type EppDomainTransferRejectResponse
///     let response = client.transact::<_, EppDomainTransferRejectResponse>(&domain_transfer_reject).await.unwrap();
///
///     println!("{:?}", response);
/// }
/// ```
pub type EppDomainTransferReject = EppObject<Command<DomainTransfer>>;

/// Type that represents the &lt;epp&gt; request for transfer request cancellation for domains
///
/// ## Usage
///
/// ```ignore
/// use epp_client::EppClient;
/// use epp_client::epp::{EppDomainTransferCancel, EppDomainTransferCancelResponse};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
/// async fn main() {
///     // Create an instance of EppClient, specifying the name of the registry as in
///     // the config file
///     let mut client = match EppClient::new("verisign").await {
///         Ok(client) => client,
///         Err(e) => panic!("Failed to create EppClient: {}",  e)
///     };
///
///     // Create an EppDomainTransferCancel instance
///     let domain_transfer_cancel = EppDomainTransferCancel::cancel(
///         "eppdev-100.net", generate_client_tr_id(&client).as_str()
///     );
///
///     // send it to the registry and receive a response of type EppDomainTransferCancelResponse
///     let response = client.transact::<_, EppDomainTransferCancelResponse>(&domain_transfer_cancel).await.unwrap();
///
///     println!("{:?}", response);
/// }
/// ```
pub type EppDomainTransferCancel = EppObject<Command<DomainTransfer>>;

/// Type that represents the &lt;epp&gt; request for transfer request query for domains
///
/// ## Usage
///
/// ```ignore
/// use epp_client::EppClient;
/// use epp_client::epp::{EppDomainTransferQuery, EppDomainTransferQueryResponse};
/// use epp_client::epp::generate_client_tr_id;
///
/// #[tokio::main]
/// async fn main() {
///     // Create an instance of EppClient, specifying the name of the registry as in
///     // the config file
///     let mut client = match EppClient::new("verisign").await {
///         Ok(client) => client,
///         Err(e) => panic!("Failed to create EppClient: {}",  e)
///     };
///
///     // Create an EppDomainTransferQuery instance
///     let domain_transfer_query = EppDomainTransferQuery::query(
///         "eppdev-100.net", "epP4uthd#v", generate_client_tr_id(&client).as_str()
///     );
///
///     // send it to the registry and receive a response of type EppDomainTransferQueryResponse
///     let response = client.transact::<_, EppDomainTransferQueryResponse>(&domain_transfer_query).await.unwrap();
///
///     println!("{:?}", response);
/// }
/// ```
pub type EppDomainTransferQuery = EppObject<Command<DomainTransfer>>;

/// Type for elements under the domain &lt;transfer&gt; tag
#[derive(Serialize, Deserialize, Debug)]
pub struct DomainTransferData {
    /// XML namespace for domain commands
    xmlns: String,
    /// The name of the domain under transfer
    name: StringValue,
    /// The period of renewal upon a successful transfer
    /// Only applicable in case of a transfer request
    period: Option<Period>,
    /// The authInfo for the domain under transfer
    /// Only applicable to domain transfer and domain transfer query requests
    #[serde(rename = "authInfo")]
    auth_info: Option<AuthInfo>,
}

#[derive(Serialize, Deserialize, Debug, ElementName)]
#[element_name(name = "transfer")]
/// Type for EPP XML &lt;transfer&gt; command for domains
pub struct DomainTransfer {
    /// The transfer operation to perform indicated by the 'op' attr
    /// The values are one of transfer, approve, reject, cancel, or query
    #[serde(rename = "op")]
    operation: String,
    /// The data under the &lt;transfer&gt; tag in the transfer request
    #[serde(rename = "transfer")]
    domain: DomainTransferData,
}

impl EppDomainTransferRequest {
    /// Creates a new EppObject for domain transfer request corresponding to the &lt;epp&gt; tag in EPP XML
    pub fn request(
        name: &str,
        years: u16,
        auth_password: &str,
        client_tr_id: &str,
    ) -> EppDomainTransferRequest {
        EppObject::build(Command::<DomainTransfer> {
            command: DomainTransfer {
                operation: "request".to_string(),
                domain: DomainTransferData {
                    xmlns: EPP_DOMAIN_XMLNS.to_string(),
                    name: name.to_string_value(),
                    period: Some(Period::new(years)),
                    auth_info: Some(AuthInfo::new(auth_password)),
                },
            },
            client_tr_id: client_tr_id.to_string_value(),
        })
    }

    /// Sets the period for renewal in case of a successful transfer
    pub fn set_period(&mut self, period: Period) {
        self.data.command.domain.period = Some(period);
    }
}

impl EppDomainTransferApprove {
    /// Creates a new EppObject for domain transfer approval corresponding to the &lt;epp&gt; tag in EPP XML
    pub fn approve(name: &str, client_tr_id: &str) -> EppDomainTransferApprove {
        EppObject::build(Command::<DomainTransfer> {
            command: DomainTransfer {
                operation: "approve".to_string(),
                domain: DomainTransferData {
                    xmlns: EPP_DOMAIN_XMLNS.to_string(),
                    name: name.to_string_value(),
                    period: None,
                    auth_info: None,
                },
            },
            client_tr_id: client_tr_id.to_string_value(),
        })
    }
}

impl EppDomainTransferCancel {
    /// Creates a new EppObject for domain transfer request cancellation corresponding to the &lt;epp&gt; tag in EPP XML
    pub fn cancel(name: &str, client_tr_id: &str) -> EppDomainTransferCancel {
        EppObject::build(Command::<DomainTransfer> {
            command: DomainTransfer {
                operation: "cancel".to_string(),
                domain: DomainTransferData {
                    xmlns: EPP_DOMAIN_XMLNS.to_string(),
                    name: name.to_string_value(),
                    period: None,
                    auth_info: None,
                },
            },
            client_tr_id: client_tr_id.to_string_value(),
        })
    }
}

impl EppDomainTransferReject {
    /// Creates a new EppObject for domain transfer rejection corresponding to the &lt;epp&gt; tag in EPP XML
    pub fn reject(name: &str, client_tr_id: &str) -> EppDomainTransferReject {
        EppObject::build(Command::<DomainTransfer> {
            command: DomainTransfer {
                operation: "reject".to_string(),
                domain: DomainTransferData {
                    xmlns: EPP_DOMAIN_XMLNS.to_string(),
                    name: name.to_string_value(),
                    period: None,
                    auth_info: None,
                },
            },
            client_tr_id: client_tr_id.to_string_value(),
        })
    }
}

impl EppDomainTransferQuery {
    /// Creates a new EppObject for domain transfer request query corresponding to the &lt;epp&gt; tag in EPP XML
    pub fn query(name: &str, auth_password: &str, client_tr_id: &str) -> EppDomainTransferQuery {
        EppObject::build(Command::<DomainTransfer> {
            command: DomainTransfer {
                operation: "query".to_string(),
                domain: DomainTransferData {
                    xmlns: EPP_DOMAIN_XMLNS.to_string(),
                    name: name.to_string_value(),
                    period: None,
                    auth_info: Some(AuthInfo::new(auth_password)),
                },
            },
            client_tr_id: client_tr_id.to_string_value(),
        })
    }
}