diff --git a/parsers/ChangeLog b/parsers/ChangeLog index b47082f38684e763e7828131c0371e03a9214f21..b8372dbdcf10512d1d352d693f19eb68bddcafe0 100644 --- a/parsers/ChangeLog +++ b/parsers/ChangeLog @@ -24,7 +24,9 @@ XXXX-YY-ZZ RELEASER nothing so far uses it for anything but this message. We can always change it again once any other specification allows e.g. presences or iqs. - - Module `jingle_thumnails` renamed to `jingle_thumbnails`. + - Module `jingle_thumnails` has been renamed to `jingle_thumbnails`. It + now respect the latest version of the XEP, with the width and height + being limited to 0..65535 and the media-type being optional (!475). - The bookmarks2 Conference `extensions` child is now an `Option` instead of a `Vec`, to distinguish between it being absent or empty (!472). diff --git a/parsers/doap.xml b/parsers/doap.xml index 719c130d8668918c1ded6eb82ab9654407a0f0f4..e3fc1eb09e9bc4ad5cdd34c53c43b86e73672118 100644 --- a/parsers/doap.xml +++ b/parsers/doap.xml @@ -411,7 +411,7 @@ complete - 0.4.1 + 0.4.2 0.21.0 diff --git a/parsers/src/jingle_thumbnails.rs b/parsers/src/jingle_thumbnails.rs index 879c53580cca4c98630c2f21fb876bdafb38a891..f6631e7e050e824275a81eb73dc8bca2011e2efa 100644 --- a/parsers/src/jingle_thumbnails.rs +++ b/parsers/src/jingle_thumbnails.rs @@ -1,14 +1,15 @@ -//! Jingle thumbnails (XEP-0264) - -// Copyright (c) 2023 XMPP-RS contributors.= +// Copyright (c) 2023 XMPP-RS contributors. // // 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/. +//! Jingle thumbnails (XEP-0264) + use xso::{AsXml, FromXml}; use crate::ns; +use core::num::NonZeroU16; /// A Jingle thumbnail. #[derive(FromXml, AsXml, PartialEq, Debug, Clone)] @@ -19,23 +20,36 @@ pub struct Thumbnail { pub uri: String, /// The media type of the thumbnail. - #[xml(attribute = "media-type")] - pub media_type: String, + #[xml(attribute(default, name = "media-type"))] + pub media_type: Option, /// The width of the thumbnail. - #[xml(attribute)] - pub width: u32, + #[xml(attribute(default))] + pub width: Option, /// The height of the thumbnail. - #[xml(attribute)] - pub height: u32, + #[xml(attribute(default))] + pub height: Option, } #[cfg(test)] mod tests { use crate::jingle_thumbnails::Thumbnail; + use core::num::NonZeroU16; use minidom::Element; + #[cfg(target_pointer_width = "32")] + #[test] + fn test_size() { + assert_size!(Thumbnail, 28); + } + + #[cfg(target_pointer_width = "64")] + #[test] + fn test_size() { + assert_size!(Thumbnail, 56); + } + #[test] fn test_simple_parse() { // Extracted from https://xmpp.org/extensions/xep-0264.html#example-1 @@ -53,8 +67,8 @@ mod tests { thumbnail.uri, "cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org" ); - assert_eq!(thumbnail.media_type, "image/png"); - assert_eq!(thumbnail.width, 128); - assert_eq!(thumbnail.height, 96); + assert_eq!(thumbnail.media_type.unwrap(), "image/png"); + assert_eq!(thumbnail.width, NonZeroU16::new(128)); + assert_eq!(thumbnail.height, NonZeroU16::new(96)); } }