2017-04-29 21:14:34 +00:00
|
|
|
|
// Copyright (c) 2017 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/.
|
|
|
|
|
|
2017-07-20 19:03:15 +00:00
|
|
|
|
use try_from::TryFrom;
|
2017-05-06 19:30:52 +00:00
|
|
|
|
|
2017-08-27 00:22:15 +00:00
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
2017-05-06 19:46:11 +00:00
|
|
|
|
use hashes::Hash;
|
2017-10-31 16:11:09 +00:00
|
|
|
|
use jingle::{Creator, ContentId};
|
2017-04-22 16:39:21 +00:00
|
|
|
|
|
2017-08-27 00:22:15 +00:00
|
|
|
|
use minidom::{Element, IntoElements, IntoAttributeValue, ElementEmitter};
|
2017-06-16 19:37:48 +00:00
|
|
|
|
use chrono::{DateTime, FixedOffset};
|
2017-04-22 16:39:21 +00:00
|
|
|
|
|
|
|
|
|
use error::Error;
|
|
|
|
|
use ns;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
|
pub struct Range {
|
|
|
|
|
pub offset: u64,
|
|
|
|
|
pub length: Option<u64>,
|
|
|
|
|
pub hashes: Vec<Hash>,
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 18:52:41 +00:00
|
|
|
|
impl IntoElements for Range {
|
|
|
|
|
fn into_elements(self, emitter: &mut ElementEmitter) {
|
|
|
|
|
let mut elem = Element::builder("range")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
2017-08-27 01:33:37 +00:00
|
|
|
|
.attr("offset", if self.offset == 0 { None } else { Some(self.offset) })
|
2017-05-27 22:18:15 +00:00
|
|
|
|
.attr("length", self.length)
|
2017-04-24 18:52:41 +00:00
|
|
|
|
.build();
|
|
|
|
|
for hash in self.hashes {
|
2017-05-23 22:31:33 +00:00
|
|
|
|
elem.append_child(hash.into());
|
2017-04-24 18:52:41 +00:00
|
|
|
|
}
|
|
|
|
|
emitter.append_child(elem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-27 00:22:15 +00:00
|
|
|
|
type Lang = String;
|
|
|
|
|
|
|
|
|
|
generate_id!(Desc);
|
|
|
|
|
|
2017-04-22 16:39:21 +00:00
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct File {
|
2017-06-16 19:37:48 +00:00
|
|
|
|
pub date: Option<DateTime<FixedOffset>>,
|
2017-04-22 16:39:21 +00:00
|
|
|
|
pub media_type: Option<String>,
|
|
|
|
|
pub name: Option<String>,
|
2017-08-27 00:22:15 +00:00
|
|
|
|
pub descs: BTreeMap<Lang, Desc>,
|
2017-04-24 18:52:41 +00:00
|
|
|
|
pub size: Option<u64>,
|
2017-04-22 16:39:21 +00:00
|
|
|
|
pub range: Option<Range>,
|
|
|
|
|
pub hashes: Vec<Hash>,
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 16:25:01 +00:00
|
|
|
|
impl TryFrom<Element> for File {
|
2017-10-31 16:09:28 +00:00
|
|
|
|
type Err = Error;
|
|
|
|
|
|
2017-10-31 16:25:01 +00:00
|
|
|
|
fn try_from(elem: Element) -> Result<File, Error> {
|
|
|
|
|
check_self!(elem, "file", ns::JINGLE_FT);
|
|
|
|
|
check_no_attributes!(elem, "file");
|
2017-04-28 22:43:47 +00:00
|
|
|
|
|
2017-10-31 16:25:01 +00:00
|
|
|
|
let mut file = File {
|
|
|
|
|
date: None,
|
|
|
|
|
media_type: None,
|
|
|
|
|
name: None,
|
|
|
|
|
descs: BTreeMap::new(),
|
|
|
|
|
size: None,
|
|
|
|
|
range: None,
|
|
|
|
|
hashes: vec!(),
|
|
|
|
|
};
|
2017-04-22 16:39:21 +00:00
|
|
|
|
|
2017-10-31 16:25:01 +00:00
|
|
|
|
for child in elem.children() {
|
|
|
|
|
if child.is("date", ns::JINGLE_FT) {
|
|
|
|
|
if file.date.is_some() {
|
|
|
|
|
return Err(Error::ParseError("File must not have more than one date."));
|
|
|
|
|
}
|
|
|
|
|
file.date = Some(child.text().parse()?);
|
|
|
|
|
} else if child.is("media-type", ns::JINGLE_FT) {
|
|
|
|
|
if file.media_type.is_some() {
|
|
|
|
|
return Err(Error::ParseError("File must not have more than one media-type."));
|
|
|
|
|
}
|
|
|
|
|
file.media_type = Some(child.text());
|
|
|
|
|
} else if child.is("name", ns::JINGLE_FT) {
|
|
|
|
|
if file.name.is_some() {
|
|
|
|
|
return Err(Error::ParseError("File must not have more than one name."));
|
|
|
|
|
}
|
|
|
|
|
file.name = Some(child.text());
|
|
|
|
|
} else if child.is("desc", ns::JINGLE_FT) {
|
|
|
|
|
let lang = get_attr!(child, "xml:lang", default);
|
|
|
|
|
let desc = Desc(child.text());
|
|
|
|
|
if file.descs.insert(lang, desc).is_some() {
|
|
|
|
|
return Err(Error::ParseError("Desc element present twice for the same xml:lang."));
|
|
|
|
|
}
|
|
|
|
|
} else if child.is("size", ns::JINGLE_FT) {
|
|
|
|
|
if file.size.is_some() {
|
|
|
|
|
return Err(Error::ParseError("File must not have more than one size."));
|
|
|
|
|
}
|
|
|
|
|
file.size = Some(child.text().parse()?);
|
|
|
|
|
} else if child.is("range", ns::JINGLE_FT) {
|
|
|
|
|
if file.range.is_some() {
|
|
|
|
|
return Err(Error::ParseError("File must not have more than one range."));
|
|
|
|
|
}
|
|
|
|
|
let offset = get_attr!(child, "offset", default);
|
|
|
|
|
let length = get_attr!(child, "length", optional);
|
|
|
|
|
let mut range_hashes = vec!();
|
|
|
|
|
for hash_element in child.children() {
|
|
|
|
|
if !hash_element.is("hash", ns::HASHES) {
|
|
|
|
|
return Err(Error::ParseError("Unknown element in JingleFT range."));
|
2017-05-06 19:30:52 +00:00
|
|
|
|
}
|
2017-10-31 16:25:01 +00:00
|
|
|
|
range_hashes.push(Hash::try_from(hash_element.clone())?);
|
2017-04-22 16:39:21 +00:00
|
|
|
|
}
|
2017-10-31 16:25:01 +00:00
|
|
|
|
file.range = Some(Range {
|
|
|
|
|
offset: offset,
|
|
|
|
|
length: length,
|
|
|
|
|
hashes: range_hashes,
|
|
|
|
|
});
|
|
|
|
|
} else if child.is("hash", ns::HASHES) {
|
|
|
|
|
file.hashes.push(Hash::try_from(child.clone())?);
|
|
|
|
|
} else {
|
|
|
|
|
return Err(Error::ParseError("Unknown element in JingleFT file."));
|
2017-04-22 16:39:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 16:25:01 +00:00
|
|
|
|
Ok(file)
|
2017-05-06 19:30:52 +00:00
|
|
|
|
}
|
2017-04-22 16:39:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 19:36:13 +00:00
|
|
|
|
impl From<File> for Element {
|
|
|
|
|
fn from(file: File) -> Element {
|
2017-05-06 19:30:52 +00:00
|
|
|
|
let mut root = Element::builder("file")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
|
|
|
|
.build();
|
2017-07-20 19:36:13 +00:00
|
|
|
|
if let Some(date) = file.date {
|
2017-05-06 19:30:52 +00:00
|
|
|
|
root.append_child(Element::builder("date")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
2017-06-16 19:37:48 +00:00
|
|
|
|
.append(date.to_rfc3339())
|
2017-05-06 19:30:52 +00:00
|
|
|
|
.build());
|
|
|
|
|
}
|
2017-07-20 19:36:13 +00:00
|
|
|
|
if let Some(media_type) = file.media_type {
|
2017-05-06 19:30:52 +00:00
|
|
|
|
root.append_child(Element::builder("media-type")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
2017-05-23 22:31:33 +00:00
|
|
|
|
.append(media_type)
|
2017-05-06 19:30:52 +00:00
|
|
|
|
.build());
|
|
|
|
|
}
|
2017-07-20 19:36:13 +00:00
|
|
|
|
if let Some(name) = file.name {
|
2017-05-06 19:30:52 +00:00
|
|
|
|
root.append_child(Element::builder("name")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
2017-05-23 22:31:33 +00:00
|
|
|
|
.append(name)
|
2017-05-06 19:30:52 +00:00
|
|
|
|
.build());
|
|
|
|
|
}
|
2017-08-27 00:22:15 +00:00
|
|
|
|
for (lang, desc) in file.descs.into_iter() {
|
2017-05-06 19:30:52 +00:00
|
|
|
|
root.append_child(Element::builder("desc")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
2017-08-27 00:22:15 +00:00
|
|
|
|
.attr("xml:lang", lang)
|
|
|
|
|
.append(desc.0)
|
2017-05-06 19:30:52 +00:00
|
|
|
|
.build());
|
|
|
|
|
}
|
2017-07-20 19:36:13 +00:00
|
|
|
|
if let Some(size) = file.size {
|
2017-05-06 19:30:52 +00:00
|
|
|
|
root.append_child(Element::builder("size")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
|
|
|
|
.append(format!("{}", size))
|
|
|
|
|
.build());
|
|
|
|
|
}
|
2017-07-20 19:36:13 +00:00
|
|
|
|
if let Some(range) = file.range {
|
2017-05-06 19:30:52 +00:00
|
|
|
|
root.append_child(Element::builder("range")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
2017-05-23 22:31:33 +00:00
|
|
|
|
.append(range)
|
2017-05-06 19:30:52 +00:00
|
|
|
|
.build());
|
|
|
|
|
}
|
2017-07-20 19:36:13 +00:00
|
|
|
|
for hash in file.hashes {
|
2017-05-23 22:31:33 +00:00
|
|
|
|
root.append_child(hash.into());
|
2017-05-06 19:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
root
|
2017-04-24 18:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-31 16:25:01 +00:00
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Description {
|
|
|
|
|
pub file: File,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TryFrom<Element> for Description {
|
|
|
|
|
type Err = Error;
|
|
|
|
|
|
|
|
|
|
fn try_from(elem: Element) -> Result<Description, Error> {
|
|
|
|
|
check_self!(elem, "description", ns::JINGLE_FT, "JingleFT description");
|
|
|
|
|
check_no_attributes!(elem, "JingleFT description");
|
|
|
|
|
let mut file = None;
|
|
|
|
|
for child in elem.children() {
|
|
|
|
|
if file.is_some() {
|
|
|
|
|
return Err(Error::ParseError("JingleFT description element must have exactly one child."));
|
|
|
|
|
}
|
|
|
|
|
file = Some(File::try_from(child.clone())?);
|
|
|
|
|
}
|
|
|
|
|
if file.is_none() {
|
|
|
|
|
return Err(Error::ParseError("JingleFT description element must have exactly one child."));
|
|
|
|
|
}
|
|
|
|
|
Ok(Description {
|
|
|
|
|
file: file.unwrap(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-24 18:25:00 +00:00
|
|
|
|
|
2017-07-20 19:36:13 +00:00
|
|
|
|
impl From<Description> for Element {
|
|
|
|
|
fn from(description: Description) -> Element {
|
|
|
|
|
let file: Element = description.file.into();
|
2017-05-06 19:30:52 +00:00
|
|
|
|
Element::builder("description")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
|
|
|
|
.append(file)
|
|
|
|
|
.build()
|
|
|
|
|
}
|
2017-04-24 18:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 16:25:01 +00:00
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Checksum {
|
|
|
|
|
pub name: ContentId,
|
|
|
|
|
pub creator: Creator,
|
|
|
|
|
pub file: File,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Received {
|
|
|
|
|
pub name: ContentId,
|
|
|
|
|
pub creator: Creator,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl TryFrom<Element> for Received {
|
|
|
|
|
type Err = Error;
|
|
|
|
|
|
|
|
|
|
fn try_from(elem: Element) -> Result<Received, Error> {
|
|
|
|
|
check_self!(elem, "received", ns::JINGLE_FT);
|
|
|
|
|
check_no_children!(elem, "received");
|
|
|
|
|
check_no_unknown_attributes!(elem, "received", ["name", "creator"]);
|
|
|
|
|
Ok(Received {
|
|
|
|
|
name: get_attr!(elem, "name", required),
|
|
|
|
|
creator: get_attr!(elem, "creator", required),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Received> for Element {
|
|
|
|
|
fn from(received: Received) -> Element {
|
|
|
|
|
Element::builder("received")
|
|
|
|
|
.ns(ns::JINGLE_FT)
|
|
|
|
|
.attr("name", received.name)
|
|
|
|
|
.attr("creator", received.creator)
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-22 16:39:21 +00:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
2017-05-06 19:30:52 +00:00
|
|
|
|
use super::*;
|
2017-05-18 22:09:29 +00:00
|
|
|
|
use hashes::Algo;
|
2017-05-24 23:30:29 +00:00
|
|
|
|
use base64;
|
2017-04-22 16:39:21 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_description() {
|
|
|
|
|
let elem: Element = r#"
|
|
|
|
|
<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
|
|
|
|
<file>
|
|
|
|
|
<media-type>text/plain</media-type>
|
|
|
|
|
<name>test.txt</name>
|
2017-06-16 19:37:48 +00:00
|
|
|
|
<date>2015-07-26T21:46:00+01:00</date>
|
2017-04-22 16:39:21 +00:00
|
|
|
|
<size>6144</size>
|
|
|
|
|
<hash xmlns='urn:xmpp:hashes:2'
|
|
|
|
|
algo='sha-1'>w0mcJylzCn+AfvuGdqkty2+KP48=</hash>
|
|
|
|
|
</file>
|
|
|
|
|
</description>
|
|
|
|
|
"#.parse().unwrap();
|
2017-05-23 22:31:33 +00:00
|
|
|
|
let desc = Description::try_from(elem).unwrap();
|
2017-04-22 16:39:21 +00:00
|
|
|
|
assert_eq!(desc.file.media_type, Some(String::from("text/plain")));
|
|
|
|
|
assert_eq!(desc.file.name, Some(String::from("test.txt")));
|
2017-08-27 00:22:15 +00:00
|
|
|
|
assert_eq!(desc.file.descs, BTreeMap::new());
|
2017-06-16 19:37:48 +00:00
|
|
|
|
assert_eq!(desc.file.date, Some(DateTime::parse_from_rfc3339("2015-07-26T21:46:00+01:00").unwrap()));
|
2017-04-24 18:52:41 +00:00
|
|
|
|
assert_eq!(desc.file.size, Some(6144u64));
|
2017-04-22 16:39:21 +00:00
|
|
|
|
assert_eq!(desc.file.range, None);
|
2017-05-18 22:09:29 +00:00
|
|
|
|
assert_eq!(desc.file.hashes[0].algo, Algo::Sha_1);
|
2017-05-24 23:30:29 +00:00
|
|
|
|
assert_eq!(desc.file.hashes[0].hash, base64::decode("w0mcJylzCn+AfvuGdqkty2+KP48=").unwrap());
|
2017-04-22 16:39:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_request() {
|
|
|
|
|
let elem: Element = r#"
|
|
|
|
|
<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
|
|
|
|
<file>
|
|
|
|
|
<hash xmlns='urn:xmpp:hashes:2'
|
|
|
|
|
algo='sha-1'>w0mcJylzCn+AfvuGdqkty2+KP48=</hash>
|
|
|
|
|
</file>
|
|
|
|
|
</description>
|
|
|
|
|
"#.parse().unwrap();
|
2017-05-23 22:31:33 +00:00
|
|
|
|
let desc = Description::try_from(elem).unwrap();
|
2017-04-22 16:39:21 +00:00
|
|
|
|
assert_eq!(desc.file.media_type, None);
|
|
|
|
|
assert_eq!(desc.file.name, None);
|
2017-08-27 00:22:15 +00:00
|
|
|
|
assert_eq!(desc.file.descs, BTreeMap::new());
|
2017-04-22 16:39:21 +00:00
|
|
|
|
assert_eq!(desc.file.date, None);
|
|
|
|
|
assert_eq!(desc.file.size, None);
|
|
|
|
|
assert_eq!(desc.file.range, None);
|
2017-05-18 22:09:29 +00:00
|
|
|
|
assert_eq!(desc.file.hashes[0].algo, Algo::Sha_1);
|
2017-05-24 23:30:29 +00:00
|
|
|
|
assert_eq!(desc.file.hashes[0].hash, base64::decode("w0mcJylzCn+AfvuGdqkty2+KP48=").unwrap());
|
2017-04-22 16:39:21 +00:00
|
|
|
|
}
|
2017-08-27 00:22:15 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_descs() {
|
|
|
|
|
let elem: Element = r#"
|
|
|
|
|
<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
|
|
|
|
<file>
|
|
|
|
|
<media-type>text/plain</media-type>
|
|
|
|
|
<desc xml:lang='fr'>Fichier secret !</desc>
|
|
|
|
|
<desc xml:lang='en'>Secret file!</desc>
|
|
|
|
|
<hash xmlns='urn:xmpp:hashes:2'
|
|
|
|
|
algo='sha-1'>w0mcJylzCn+AfvuGdqkty2+KP48=</hash>
|
|
|
|
|
</file>
|
|
|
|
|
</description>
|
|
|
|
|
"#.parse().unwrap();
|
|
|
|
|
let desc = Description::try_from(elem).unwrap();
|
|
|
|
|
assert_eq!(desc.file.descs.keys().cloned().collect::<Vec<_>>(), ["en", "fr"]);
|
|
|
|
|
assert_eq!(desc.file.descs["en"], Desc(String::from("Secret file!")));
|
|
|
|
|
assert_eq!(desc.file.descs["fr"], Desc(String::from("Fichier secret !")));
|
|
|
|
|
|
|
|
|
|
let elem: Element = r#"
|
|
|
|
|
<description xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
|
|
|
|
|
<file>
|
|
|
|
|
<media-type>text/plain</media-type>
|
|
|
|
|
<desc xml:lang='fr'>Fichier secret !</desc>
|
|
|
|
|
<desc xml:lang='fr'>Secret file!</desc>
|
|
|
|
|
<hash xmlns='urn:xmpp:hashes:2'
|
|
|
|
|
algo='sha-1'>w0mcJylzCn+AfvuGdqkty2+KP48=</hash>
|
|
|
|
|
</file>
|
|
|
|
|
</description>
|
|
|
|
|
"#.parse().unwrap();
|
|
|
|
|
let error = Description::try_from(elem).unwrap_err();
|
|
|
|
|
let message = match error {
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Desc element present twice for the same xml:lang.");
|
|
|
|
|
}
|
2017-10-31 16:09:28 +00:00
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_received() {
|
|
|
|
|
let elem: Element = "<received xmlns='urn:xmpp:jingle:apps:file-transfer:5' name='coucou' creator='initiator'/>".parse().unwrap();
|
|
|
|
|
let received = Received::try_from(elem).unwrap();
|
2017-10-31 16:11:09 +00:00
|
|
|
|
assert_eq!(received.name, ContentId(String::from("coucou")));
|
2017-10-31 16:09:28 +00:00
|
|
|
|
assert_eq!(received.creator, Creator::Initiator);
|
|
|
|
|
let elem2 = Element::from(received.clone());
|
|
|
|
|
let received2 = Received::try_from(elem2).unwrap();
|
2017-10-31 16:11:09 +00:00
|
|
|
|
assert_eq!(received2.name, ContentId(String::from("coucou")));
|
2017-10-31 16:09:28 +00:00
|
|
|
|
assert_eq!(received2.creator, Creator::Initiator);
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<received xmlns='urn:xmpp:jingle:apps:file-transfer:5' name='coucou' creator='initiator'><coucou/></received>".parse().unwrap();
|
|
|
|
|
let error = Received::try_from(elem).unwrap_err();
|
|
|
|
|
let message = match error {
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Unknown child in received element.");
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<received xmlns='urn:xmpp:jingle:apps:file-transfer:5' name='coucou' creator='initiator' coucou=''/>".parse().unwrap();
|
|
|
|
|
let error = Received::try_from(elem).unwrap_err();
|
|
|
|
|
let message = match error {
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Unknown attribute in received element.");
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<received xmlns='urn:xmpp:jingle:apps:file-transfer:5' creator='initiator'/>".parse().unwrap();
|
|
|
|
|
let error = Received::try_from(elem).unwrap_err();
|
|
|
|
|
let message = match error {
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Required attribute 'name' missing.");
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<received xmlns='urn:xmpp:jingle:apps:file-transfer:5' name='coucou' creator='coucou'/>".parse().unwrap();
|
|
|
|
|
let error = Received::try_from(elem).unwrap_err();
|
|
|
|
|
let message = match error {
|
|
|
|
|
Error::ParseError(string) => string,
|
|
|
|
|
_ => panic!(),
|
|
|
|
|
};
|
|
|
|
|
assert_eq!(message, "Unknown value for 'creator' attribute.");
|
|
|
|
|
}
|
2017-04-22 16:39:21 +00:00
|
|
|
|
}
|