2019-09-08 14:09:49 +00:00
|
|
|
|
// Copyright (c) 2019 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
2024-07-09 15:01:42 +00:00
|
|
|
|
use xso::{AsXml, FromXml};
|
2024-06-26 16:05:13 +00:00
|
|
|
|
|
|
|
|
|
use jid::Jid;
|
|
|
|
|
|
2019-09-08 14:09:49 +00:00
|
|
|
|
use crate::iq::{IqGetPayload, IqResultPayload};
|
2024-06-26 16:05:13 +00:00
|
|
|
|
use crate::ns;
|
2019-09-08 14:09:49 +00:00
|
|
|
|
|
2024-06-26 16:05:13 +00:00
|
|
|
|
/// Request from a client to stringprep/PRECIS a string into a JID.
|
2024-07-09 15:01:42 +00:00
|
|
|
|
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
|
2024-06-26 16:05:13 +00:00
|
|
|
|
#[xml(namespace = ns::JID_PREP, name = "jid")]
|
|
|
|
|
pub struct JidPrepQuery {
|
|
|
|
|
/// The potential JID.
|
|
|
|
|
#[xml(text)]
|
|
|
|
|
pub data: String,
|
|
|
|
|
}
|
2019-09-08 14:09:49 +00:00
|
|
|
|
|
|
|
|
|
impl IqGetPayload for JidPrepQuery {}
|
|
|
|
|
|
2019-09-08 14:22:12 +00:00
|
|
|
|
impl JidPrepQuery {
|
|
|
|
|
/// Create a new JID Prep query.
|
|
|
|
|
pub fn new<J: Into<String>>(jid: J) -> JidPrepQuery {
|
2019-10-22 23:32:41 +00:00
|
|
|
|
JidPrepQuery { data: jid.into() }
|
2019-09-08 14:22:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-26 16:05:13 +00:00
|
|
|
|
/// Response from the server with the stringprep’d/PRECIS’d JID.
|
2024-07-09 15:01:42 +00:00
|
|
|
|
#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
|
2024-06-26 16:05:13 +00:00
|
|
|
|
#[xml(namespace = ns::JID_PREP, name = "jid")]
|
|
|
|
|
pub struct JidPrepResponse {
|
|
|
|
|
/// The JID.
|
|
|
|
|
#[xml(text)]
|
|
|
|
|
pub jid: Jid,
|
|
|
|
|
}
|
2019-09-08 14:09:49 +00:00
|
|
|
|
|
|
|
|
|
impl IqResultPayload for JidPrepResponse {}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
2020-12-10 19:45:30 +00:00
|
|
|
|
use jid::FullJid;
|
2024-07-24 18:28:22 +00:00
|
|
|
|
use minidom::Element;
|
2019-09-08 14:09:49 +00:00
|
|
|
|
|
2019-09-17 15:13:18 +00:00
|
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_size() {
|
|
|
|
|
assert_size!(JidPrepQuery, 12);
|
2024-04-15 15:03:57 +00:00
|
|
|
|
assert_size!(JidPrepResponse, 16);
|
2019-09-17 15:13:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
2019-09-08 14:09:49 +00:00
|
|
|
|
#[test]
|
|
|
|
|
fn test_size() {
|
|
|
|
|
assert_size!(JidPrepQuery, 24);
|
2024-04-15 15:03:57 +00:00
|
|
|
|
assert_size!(JidPrepResponse, 32);
|
2019-09-08 14:09:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn simple() {
|
2019-10-22 23:32:41 +00:00
|
|
|
|
let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>ROMeo@montague.lit/orchard</jid>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2019-09-08 14:09:49 +00:00
|
|
|
|
let query = JidPrepQuery::try_from(elem).unwrap();
|
2019-09-08 14:22:12 +00:00
|
|
|
|
assert_eq!(query.data, "ROMeo@montague.lit/orchard");
|
2019-09-08 14:09:49 +00:00
|
|
|
|
|
2019-10-22 23:32:41 +00:00
|
|
|
|
let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>romeo@montague.lit/orchard</jid>"
|
|
|
|
|
.parse()
|
|
|
|
|
.unwrap();
|
2019-09-08 14:09:49 +00:00
|
|
|
|
let response = JidPrepResponse::try_from(elem).unwrap();
|
2019-10-22 23:32:41 +00:00
|
|
|
|
assert_eq!(
|
|
|
|
|
response.jid,
|
2023-06-20 12:07:50 +00:00
|
|
|
|
FullJid::new("romeo@montague.lit/orchard").unwrap()
|
2019-10-22 23:32:41 +00:00
|
|
|
|
);
|
2019-09-08 14:09:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|