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/.
|
|
|
|
|
|
|
|
|
|
use crate::iq::{IqGetPayload, IqResultPayload};
|
2019-09-08 14:22:12 +00:00
|
|
|
|
use crate::util::helpers::{Text, JidCodec};
|
2019-09-08 14:09:49 +00:00
|
|
|
|
use jid::Jid;
|
|
|
|
|
|
|
|
|
|
generate_element!(
|
2019-09-08 14:22:12 +00:00
|
|
|
|
/// Request from a client to stringprep/PRECIS a string into a JID.
|
2019-09-08 14:09:49 +00:00
|
|
|
|
JidPrepQuery, "jid", JID_PREP,
|
|
|
|
|
text: (
|
2019-09-08 14:22:12 +00:00
|
|
|
|
/// The potential JID.
|
|
|
|
|
data: Text<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 {
|
|
|
|
|
JidPrepQuery {
|
|
|
|
|
data: jid.into(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 14:09:49 +00:00
|
|
|
|
generate_element!(
|
2019-09-08 14:22:12 +00:00
|
|
|
|
/// Response from the server with the stringprep’d/PRECIS’d JID.
|
2019-09-08 14:09:49 +00:00
|
|
|
|
JidPrepResponse, "jid", JID_PREP,
|
|
|
|
|
text: (
|
2019-09-08 14:22:12 +00:00
|
|
|
|
/// The JID.
|
2019-09-08 14:09:49 +00:00
|
|
|
|
jid: JidCodec<Jid>
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
impl IqResultPayload for JidPrepResponse {}
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
use minidom::Element;
|
|
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_size() {
|
|
|
|
|
assert_size!(JidPrepQuery, 24);
|
|
|
|
|
assert_size!(JidPrepResponse, 80);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn simple() {
|
|
|
|
|
let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>ROMeo@montague.lit/orchard</jid>".parse().unwrap();
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
let elem: Element = "<jid xmlns='urn:xmpp:jidprep:0'>romeo@montague.lit/orchard</jid>".parse().unwrap();
|
|
|
|
|
let response = JidPrepResponse::try_from(elem).unwrap();
|
|
|
|
|
assert_eq!(response.jid, Jid::from_str("romeo@montague.lit/orchard").unwrap());
|
|
|
|
|
}
|
|
|
|
|
}
|