Skip to content

Commit

Permalink
Made parsing of <parameter> inside <source> more lenient
Browse files Browse the repository at this point in the history
  • Loading branch information
jbg committed Sep 6, 2022
1 parent 348060c commit 316e56e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 49 deletions.
90 changes: 45 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions jitsi-xmpp-parsers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "jitsi-xmpp-parsers"
description = "Provides types for non-standard XMPP elements used by Jitsi Meet"
version = "0.1.1"
edition = "2018"
version = "0.1.2"
edition = "2021"
license = "MPL-2.0"
readme = "../README.md"
repository = "https://github.com/avstack/gst-meet"
Expand Down
39 changes: 37 additions & 2 deletions jitsi-xmpp-parsers/src/jingle_ssma.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use minidom::{Element, NSChoice::Any};
use xmpp_parsers::{
jingle_ssma::{Parameter, Semantics},
jingle_ssma::Semantics,
ns::JINGLE_SSMA,
};

Expand All @@ -14,7 +15,10 @@ generate_element!(
],
children: [
/// List of attributes for this source.
parameters: Vec<Parameter> = ("parameter", JINGLE_SSMA) => Parameter,
// The namespace should be JINGLE_SSMA, but we have to use Any because Jicofo produces
// parameters with the wrong namespace.
// https://github.com/jitsi/jitsi-xmpp-extensions/issues/81
parameters: Vec<Parameter> = ("parameter", Any) => Parameter,

/// --- Non-standard attributes used by Jitsi Meet: ---

Expand All @@ -34,6 +38,37 @@ impl Source {
}
}

/// Parameter associated with a ssrc.
#[derive(Debug, Clone, PartialEq)]
pub struct Parameter {
pub name: String,
pub value: Option<String>,
}

impl TryFrom<Element> for Parameter {
type Error = xmpp_parsers::Error;

fn try_from(root: Element) -> Result<Parameter, xmpp_parsers::Error> {
// The namespace should be JINGLE_SSMA, but we have to use Any because Jicofo produces
// parameters with the wrong namespace.
// https://github.com/jitsi/jitsi-xmpp-extensions/issues/81
check_self!(root, "parameter", Any, "Parameter");
Ok(Parameter {
name: get_attr!(root, "name", Required),
value: get_attr!(root, "value", Option),
})
}
}

impl From<Parameter> for Element {
fn from(parameter: Parameter) -> Element {
Element::builder("parameter", JINGLE_SSMA)
.attr("name", parameter.name)
.attr("value", parameter.value)
.build()
}
}

generate_element!(
/// ssrc-info associated with a ssrc.
SsrcInfo, "ssrc-info", JITSI_MEET,
Expand Down

0 comments on commit 316e56e

Please sign in to comment.