xmpp-parsers: Fix jingle thumbnails wrt the XEP changes

Version 0.4.2 added a restriction on width and height to be in the
0..65535 range.  The media-type attribute has always been optional as
well.
This commit is contained in:
Emmanuel Gil Peyrot 2024-07-24 22:41:13 +02:00
commit 7fca02958b
3 changed files with 30 additions and 14 deletions

View file

@ -24,7 +24,9 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
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<Extensions>` instead of a `Vec<Element>`, to distinguish
between it being absent or empty (!472).

View file

@ -411,7 +411,7 @@
<xmpp:SupportedXep>
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0264.html"/>
<xmpp:status>complete</xmpp:status>
<xmpp:version>0.4.1</xmpp:version>
<xmpp:version>0.4.2</xmpp:version>
<xmpp:since>0.21.0</xmpp:since>
</xmpp:SupportedXep>
</implements>

View file

@ -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<String>,
/// The width of the thumbnail.
#[xml(attribute)]
pub width: u32,
#[xml(attribute(default))]
pub width: Option<NonZeroU16>,
/// The height of the thumbnail.
#[xml(attribute)]
pub height: u32,
#[xml(attribute(default))]
pub height: Option<NonZeroU16>,
}
#[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));
}
}