Skip to main content

xmpp_parsers/
jingle_content.rs

1// Copyright (c) 2026 Link Mauve <linkmauve@linkmauve.fr>
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7use xso::{AsXml, FromXml};
8
9use crate::ns;
10
11generate_attribute!(
12    /// The RFC4796 SDP 'content' attribute.
13    Name, "name", {
14        /// The media stream includes presentation slides.
15        Slides => "slides",
16
17        /// The media stream contains the image of the speaker.
18        Speaker => "speaker",
19
20        /// The media stream contains sign language.
21        Sl => "sl",
22
23        /// The media stream is taken from the main source.
24        Main => "main",
25
26        /// The media stream is taken from the alternative source.
27        Alt => "alt",
28    }
29);
30
31/// Wrapper element around the Jingle content category.
32#[derive(FromXml, AsXml, PartialEq, Debug, Clone)]
33#[xml(namespace = ns::JINGLE_CONTENT, name = "category")]
34pub struct Category {
35    /// The actual category being specified.
36    #[xml(attribute)]
37    name: Name,
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43    use minidom::Element;
44    use xso::error::{Error, FromElementError};
45
46    #[test]
47    fn test_size() {
48        assert_size!(Category, 1);
49        assert_size!(Name, 1);
50    }
51
52    #[test]
53    fn parse_category() {
54        let elem: Element = "<category xmlns='urn:xmpp:jingle:apps:category:0' name='slides'/>"
55            .parse()
56            .unwrap();
57        let category = Category::try_from(elem).unwrap();
58        assert_eq!(category.name, Name::Slides);
59    }
60
61    #[test]
62    fn invalid_category() {
63        let elem: Element = "<category xmlns='urn:xmpp:jingle:apps:category:0'/>"
64            .parse()
65            .unwrap();
66        let error = Category::try_from(elem).unwrap_err();
67        let message = match error {
68            FromElementError::Invalid(Error::Other(string)) => string,
69            _ => panic!(),
70        };
71        assert_eq!(
72            message,
73            "Required attribute field 'name' on Category element missing."
74        );
75
76        let elem: Element = "<category xmlns='urn:xmpp:jingle:apps:category:0' name='anime'/>"
77            .parse()
78            .unwrap();
79        let error = Category::try_from(elem).unwrap_err();
80        let message = match error {
81            FromElementError::Invalid(Error::TextParseError(string)) => string,
82            _ => panic!(),
83        };
84        assert_eq!(message.to_string(), "Unknown value for 'name' attribute.");
85    }
86}