Add a parser for XEP-0293.

Emmanuel Gil Peyrot created

Change summary

doap.xml              |  9 ++++++++
src/jingle_rtcp_fb.rs | 46 +++++++++++++++++++++++++++++++++++++++++++++
src/jingle_rtp.rs     | 11 +++++++--
src/lib.rs            |  3 ++
src/ns.rs             |  3 ++
5 files changed, 69 insertions(+), 3 deletions(-)

Detailed changes

doap.xml 🔗

@@ -361,6 +361,15 @@
             <xmpp:since>0.15.0</xmpp:since>
         </xmpp:SupportedXep>
     </implements>
+    <implements>
+        <xmpp:SupportedXep>
+            <xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0293.html"/>
+            <xmpp:status>partial</xmpp:status>
+            <xmpp:version>1.0.1</xmpp:version>
+            <xmpp:since>NEXT</xmpp:since>
+            <xmpp:note>Only supported in payload-type, and only for rtcp-fb.</xmpp:note>
+        </xmpp:SupportedXep>
+    </implements>
     <implements>
         <xmpp:SupportedXep>
             <xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0297.html"/>

src/jingle_rtcp_fb.rs 🔗

@@ -0,0 +1,46 @@
+// Copyright (c) 2019 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/.
+
+generate_element!(
+    /// Wrapper element for a rtcp-fb.
+    RtcpFb, "rtcp-fb", JINGLE_RTCP_FB,
+    attributes: [
+        /// Type of this rtcp-fb.
+        type_: Required<String> = "type",
+
+        /// Subtype of this rtcp-fb, if relevant.
+        subtype: Option<String> = "subtype",
+    ]
+);
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::Element;
+    use std::convert::TryFrom;
+
+    #[cfg(target_pointer_width = "32")]
+    #[test]
+    fn test_size() {
+        assert_size!(RtcpFb, 24);
+    }
+
+    #[cfg(target_pointer_width = "64")]
+    #[test]
+    fn test_size() {
+        assert_size!(RtcpFb, 48);
+    }
+
+    #[test]
+    fn parse_simple() {
+        let elem: Element = "<rtcp-fb xmlns='urn:xmpp:jingle:apps:rtp:rtcp-fb:0' type='nack' subtype='sli'/>"
+                .parse()
+                .unwrap();
+        let rtcp_fb = RtcpFb::try_from(elem).unwrap();
+        assert_eq!(rtcp_fb.type_, "nack");
+        assert_eq!(rtcp_fb.subtype.unwrap(), "sli");
+    }
+}

src/jingle_rtp.rs 🔗

@@ -5,6 +5,7 @@
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 use crate::jingle_ssma::{Source, Group};
+use crate::jingle_rtcp_fb::RtcpFb;
 
 generate_element!(
     /// Wrapper element describing an RTP session.
@@ -76,7 +77,10 @@ generate_element!(
         /// List of parameters specifying this payload-type.
         ///
         /// Their order MUST be ignored.
-        parameters: Vec<Parameter> = ("parameter", JINGLE_RTP) => Parameter
+        parameters: Vec<Parameter> = ("parameter", JINGLE_RTP) => Parameter,
+
+        /// List of rtcp-fb parameters from XEP-0293.
+        rtcp_fbs: Vec<RtcpFb> = ("rtcp-fb", JINGLE_RTCP_FB) => RtcpFb
     ]
 );
 
@@ -91,6 +95,7 @@ impl PayloadType {
             name: Some(name),
             ptime: None,
             parameters: Vec::new(),
+            rtcp_fbs: Vec::new(),
         }
     }
 }
@@ -126,9 +131,9 @@ mod tests {
     #[cfg(target_pointer_width = "64")]
     #[test]
     fn test_size() {
-        assert_size!(Description, 72);
+        assert_size!(Description, 120);
         assert_size!(Channels, 1);
-        assert_size!(PayloadType, 80);
+        assert_size!(PayloadType, 104);
         assert_size!(Parameter, 48);
     }
 

src/lib.rs 🔗

@@ -162,6 +162,9 @@ pub mod jingle_ibb;
 /// XEP-0280: Message Carbons
 pub mod carbons;
 
+/// XEP-0293: Jingle RTP Feedback Negotiation
+pub mod jingle_rtcp_fb;
+
 /// XEP-0297: Stanza Forwarding
 pub mod forwarding;
 

src/ns.rs 🔗

@@ -155,6 +155,9 @@ pub const MICROBLOG: &str = "urn:xmpp:microblog:0";
 /// XEP-0280: Message Carbons
 pub const CARBONS: &str = "urn:xmpp:carbons:2";
 
+/// XEP-0293: Jingle RTP Feedback Negotiation
+pub const JINGLE_RTCP_FB: &str = "urn:xmpp:jingle:apps:rtp:rtcp-fb:0";
+
 /// XEP-0297: Stanza Forwarding
 pub const FORWARD: &str = "urn:xmpp:forward:0";