From 09c5ad59767478472ec215dba6d99942ab879b1d Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 24 Jul 2024 18:26:21 +0200 Subject: [PATCH] =?UTF-8?q?xmpp-parsers:=20Convert=20jingle=5Fs5b=E2=80=99?= =?UTF-8?q?s=20Candidate=20to=20xso?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parsers/src/jingle_s5b.rs | 49 +++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/parsers/src/jingle_s5b.rs b/parsers/src/jingle_s5b.rs index 0b8883a4..131236af 100644 --- a/parsers/src/jingle_s5b.rs +++ b/parsers/src/jingle_s5b.rs @@ -4,11 +4,15 @@ // 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/. +use xso::{ + error::{Error, FromElementError}, + AsXml, FromXml, +}; + use crate::ns; use jid::Jid; use minidom::Element; use std::net::IpAddr; -use xso::error::{Error, FromElementError}; generate_attribute!( /// The type of the connection being proposed by this candidate. @@ -49,30 +53,35 @@ generate_id!( StreamId ); -generate_element!( - /// A candidate for a connection. - Candidate, "candidate", JINGLE_S5B, - attributes: [ - /// The identifier for this candidate. - cid: Required = "cid", +/// A candidate for a connection. +#[derive(FromXml, AsXml, PartialEq, Debug, Clone)] +#[xml(namespace = ns::JINGLE_S5B, name = "candidate")] +pub struct Candidate { + /// The identifier for this candidate. + #[xml(attribute)] + cid: CandidateId, - /// The host to connect to. - host: Required = "host", + /// The host to connect to. + #[xml(attribute)] + host: IpAddr, - /// The JID to request at the given end. - jid: Required = "jid", + /// The JID to request at the given end. + #[xml(attribute)] + jid: Jid, - /// The port to connect to. - port: Option = "port", + /// The port to connect to. + #[xml(attribute(default))] + port: Option, - /// The priority of this candidate, computed using this formula: - /// priority = (2^16)*(type preference) + (local preference) - priority: Required = "priority", + /// The priority of this candidate, computed using this formula: + /// priority = (2^16)*(type preference) + (local preference) + #[xml(attribute)] + priority: u32, - /// The type of the connection being proposed by this candidate. - type_: Default = "type", - ] -); + /// The type of the connection being proposed by this candidate. + #[xml(attribute(default, name = "type"))] + type_: Type, +} impl Candidate { /// Creates a new candidate with the given parameters.