jingle_ft: Add the forgotten desc element.

This commit is contained in:
Emmanuel Gil Peyrot 2017-04-28 23:42:27 +01:00
parent 30a596cb26
commit fe3300b4b0

View file

@ -38,6 +38,7 @@ pub struct File {
pub date: Option<String>, pub date: Option<String>,
pub media_type: Option<String>, pub media_type: Option<String>,
pub name: Option<String>, pub name: Option<String>,
pub desc: Option<String>,
pub size: Option<u64>, pub size: Option<u64>,
pub range: Option<Range>, pub range: Option<Range>,
pub hashes: Vec<Hash>, pub hashes: Vec<Hash>,
@ -71,6 +72,7 @@ pub fn parse_jingle_ft(root: &Element) -> Result<Description, Error> {
let mut date = None; let mut date = None;
let mut media_type = None; let mut media_type = None;
let mut name = None; let mut name = None;
let mut desc = None;
let mut size = None; let mut size = None;
let mut range = None; let mut range = None;
let mut hashes = vec!(); let mut hashes = vec!();
@ -94,6 +96,11 @@ pub fn parse_jingle_ft(root: &Element) -> Result<Description, Error> {
return Err(Error::ParseError("File must not have more than one name.")); return Err(Error::ParseError("File must not have more than one name."));
} }
name = Some(file_payload.text()); name = Some(file_payload.text());
} else if file_payload.is("desc", ns::JINGLE_FT) {
if desc.is_some() {
return Err(Error::ParseError("File must not have more than one desc."));
}
desc = Some(file_payload.text());
} else if file_payload.is("size", ns::JINGLE_FT) { } else if file_payload.is("size", ns::JINGLE_FT) {
if size.is_some() { if size.is_some() {
return Err(Error::ParseError("File must not have more than one size.")); return Err(Error::ParseError("File must not have more than one size."));
@ -133,6 +140,7 @@ pub fn parse_jingle_ft(root: &Element) -> Result<Description, Error> {
date: date, date: date,
media_type: media_type, media_type: media_type,
name: name, name: name,
desc: desc,
size: size, size: size,
range: range, range: range,
hashes: hashes, hashes: hashes,
@ -163,6 +171,12 @@ pub fn serialise_file(file: &File) -> Element {
.append(name.clone()) .append(name.clone())
.build()); .build());
} }
if let Some(ref desc) = file.desc {
root.append_child(Element::builder("desc")
.ns(ns::JINGLE_FT)
.append(desc.clone())
.build());
}
if let Some(ref size) = file.size { if let Some(ref size) = file.size {
root.append_child(Element::builder("size") root.append_child(Element::builder("size")
.ns(ns::JINGLE_FT) .ns(ns::JINGLE_FT)
@ -211,6 +225,7 @@ mod tests {
let desc = jingle_ft::parse_jingle_ft(&elem).unwrap(); let desc = jingle_ft::parse_jingle_ft(&elem).unwrap();
assert_eq!(desc.file.media_type, Some(String::from("text/plain"))); assert_eq!(desc.file.media_type, Some(String::from("text/plain")));
assert_eq!(desc.file.name, Some(String::from("test.txt"))); assert_eq!(desc.file.name, Some(String::from("test.txt")));
assert_eq!(desc.file.desc, None);
assert_eq!(desc.file.date, Some(String::from("2015-07-26T21:46:00"))); assert_eq!(desc.file.date, Some(String::from("2015-07-26T21:46:00")));
assert_eq!(desc.file.size, Some(6144u64)); assert_eq!(desc.file.size, Some(6144u64));
assert_eq!(desc.file.range, None); assert_eq!(desc.file.range, None);
@ -232,6 +247,7 @@ mod tests {
let desc = jingle_ft::parse_jingle_ft(&elem).unwrap(); let desc = jingle_ft::parse_jingle_ft(&elem).unwrap();
assert_eq!(desc.file.media_type, None); assert_eq!(desc.file.media_type, None);
assert_eq!(desc.file.name, None); assert_eq!(desc.file.name, None);
assert_eq!(desc.file.desc, None);
assert_eq!(desc.file.date, None); assert_eq!(desc.file.date, None);
assert_eq!(desc.file.size, None); assert_eq!(desc.file.size, None);
assert_eq!(desc.file.range, None); assert_eq!(desc.file.range, None);