2017-04-29 22:14:34 +01:00
|
|
|
|
// Copyright (c) 2017 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/.
|
|
|
|
|
|
|
2024-08-09 15:53:15 +02:00
|
|
|
|
use xso::{AsXml, FromXml};
|
|
|
|
|
|
|
2018-12-18 15:27:30 +01:00
|
|
|
|
use crate::iq::IqSetPayload;
|
2020-11-27 20:58:20 +01:00
|
|
|
|
use crate::jingle_grouping::Group;
|
2019-10-12 17:13:42 +02:00
|
|
|
|
use crate::jingle_ibb::Transport as IbbTransport;
|
2019-10-23 01:32:41 +02:00
|
|
|
|
use crate::jingle_ice_udp::Transport as IceUdpTransport;
|
|
|
|
|
|
use crate::jingle_rtp::Description as RtpDescription;
|
2019-10-12 17:13:42 +02:00
|
|
|
|
use crate::jingle_s5b::Transport as Socks5Transport;
|
2018-12-18 15:32:05 +01:00
|
|
|
|
use crate::ns;
|
2024-12-19 19:37:37 +01:00
|
|
|
|
use alloc::{collections::BTreeMap, fmt};
|
2019-10-23 01:32:41 +02:00
|
|
|
|
use jid::Jid;
|
2024-07-24 20:28:22 +02:00
|
|
|
|
use minidom::Element;
|
2024-12-18 15:39:30 +01:00
|
|
|
|
use xso::error::Error;
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
2018-09-20 20:28:50 +02:00
|
|
|
|
generate_attribute!(
|
|
|
|
|
|
/// The action attribute.
|
|
|
|
|
|
Action, "action", {
|
|
|
|
|
|
/// Accept a content-add action received from another party.
|
|
|
|
|
|
ContentAccept => "content-accept",
|
|
|
|
|
|
|
|
|
|
|
|
/// Add one or more new content definitions to the session.
|
|
|
|
|
|
ContentAdd => "content-add",
|
|
|
|
|
|
|
|
|
|
|
|
/// Change the directionality of media sending.
|
|
|
|
|
|
ContentModify => "content-modify",
|
|
|
|
|
|
|
|
|
|
|
|
/// Reject a content-add action received from another party.
|
|
|
|
|
|
ContentReject => "content-reject",
|
|
|
|
|
|
|
|
|
|
|
|
/// Remove one or more content definitions from the session.
|
|
|
|
|
|
ContentRemove => "content-remove",
|
|
|
|
|
|
|
|
|
|
|
|
/// Exchange information about parameters for an application type.
|
|
|
|
|
|
DescriptionInfo => "description-info",
|
|
|
|
|
|
|
|
|
|
|
|
/// Exchange information about security preconditions.
|
|
|
|
|
|
SecurityInfo => "security-info",
|
|
|
|
|
|
|
|
|
|
|
|
/// Definitively accept a session negotiation.
|
|
|
|
|
|
SessionAccept => "session-accept",
|
|
|
|
|
|
|
|
|
|
|
|
/// Send session-level information, such as a ping or a ringing message.
|
|
|
|
|
|
SessionInfo => "session-info",
|
|
|
|
|
|
|
|
|
|
|
|
/// Request negotiation of a new Jingle session.
|
|
|
|
|
|
SessionInitiate => "session-initiate",
|
|
|
|
|
|
|
|
|
|
|
|
/// End an existing session.
|
|
|
|
|
|
SessionTerminate => "session-terminate",
|
|
|
|
|
|
|
|
|
|
|
|
/// Accept a transport-replace action received from another party.
|
|
|
|
|
|
TransportAccept => "transport-accept",
|
|
|
|
|
|
|
|
|
|
|
|
/// Exchange transport candidates.
|
|
|
|
|
|
TransportInfo => "transport-info",
|
|
|
|
|
|
|
|
|
|
|
|
/// Reject a transport-replace action received from another party.
|
|
|
|
|
|
TransportReject => "transport-reject",
|
|
|
|
|
|
|
|
|
|
|
|
/// Redefine a transport method or replace it with a different method.
|
|
|
|
|
|
TransportReplace => "transport-replace",
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_attribute!(
|
|
|
|
|
|
/// Which party originally generated the content type.
|
|
|
|
|
|
Creator, "creator", {
|
|
|
|
|
|
/// This content was created by the initiator of this session.
|
|
|
|
|
|
Initiator => "initiator",
|
|
|
|
|
|
|
|
|
|
|
|
/// This content was created by the responder of this session.
|
|
|
|
|
|
Responder => "responder",
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_attribute!(
|
|
|
|
|
|
/// Which parties in the session will be generating content.
|
|
|
|
|
|
Senders, "senders", {
|
|
|
|
|
|
/// Both parties can send for this content.
|
|
|
|
|
|
Both => "both",
|
|
|
|
|
|
|
|
|
|
|
|
/// Only the initiator can send for this content.
|
|
|
|
|
|
Initiator => "initiator",
|
|
|
|
|
|
|
|
|
|
|
|
/// No one can send for this content.
|
|
|
|
|
|
None => "none",
|
|
|
|
|
|
|
|
|
|
|
|
/// Only the responder can send for this content.
|
|
|
|
|
|
Responder => "responder",
|
|
|
|
|
|
}, Default = Both
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_attribute!(
|
|
|
|
|
|
/// How the content definition is to be interpreted by the recipient. The
|
|
|
|
|
|
/// meaning of this attribute matches the "Content-Disposition" header as
|
|
|
|
|
|
/// defined in RFC 2183 and applied to SIP by RFC 3261.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Possible values are defined here:
|
2022-12-27 16:31:58 +01:00
|
|
|
|
/// <https://www.iana.org/assignments/cont-disp/cont-disp.xhtml>
|
2018-09-20 20:28:50 +02:00
|
|
|
|
Disposition, "disposition", {
|
|
|
|
|
|
/// Displayed automatically.
|
|
|
|
|
|
Inline => "inline",
|
|
|
|
|
|
|
|
|
|
|
|
/// User controlled display.
|
|
|
|
|
|
Attachment => "attachment",
|
|
|
|
|
|
|
|
|
|
|
|
/// Process as form response.
|
|
|
|
|
|
FormData => "form-data",
|
|
|
|
|
|
|
|
|
|
|
|
/// Tunneled content to be processed silently.
|
|
|
|
|
|
Signal => "signal",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body is a custom ring tone to alert the user.
|
|
|
|
|
|
Alert => "alert",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body is displayed as an icon to the user.
|
|
|
|
|
|
Icon => "icon",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body should be displayed to the user.
|
|
|
|
|
|
Render => "render",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body contains a list of URIs that indicates the recipients of
|
|
|
|
|
|
/// the request.
|
|
|
|
|
|
RecipientListHistory => "recipient-list-history",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body describes a communications session, for example, an
|
2022-12-27 16:33:51 +01:00
|
|
|
|
/// [RFC2327](https://www.rfc-editor.org/rfc/rfc2327) SDP body.
|
2018-09-20 20:28:50 +02:00
|
|
|
|
Session => "session",
|
|
|
|
|
|
|
|
|
|
|
|
/// Authenticated Identity Body.
|
|
|
|
|
|
Aib => "aib",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body describes an early communications session, for example,
|
2022-12-27 16:33:51 +01:00
|
|
|
|
/// and [RFC2327](https://www.rfc-editor.org/rfc/rfc2327) SDP body.
|
2018-09-20 20:28:50 +02:00
|
|
|
|
EarlySession => "early-session",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body includes a list of URIs to which URI-list services are to
|
|
|
|
|
|
/// be applied.
|
|
|
|
|
|
RecipientList => "recipient-list",
|
|
|
|
|
|
|
|
|
|
|
|
/// The payload of the message carrying this Content-Disposition header
|
|
|
|
|
|
/// field value is an Instant Message Disposition Notification as
|
|
|
|
|
|
/// requested in the corresponding Instant Message.
|
|
|
|
|
|
Notification => "notification",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body needs to be handled according to a reference to the body
|
|
|
|
|
|
/// that is located in the same SIP message as the body.
|
|
|
|
|
|
ByReference => "by-reference",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body contains information associated with an Info Package.
|
|
|
|
|
|
InfoPackage => "info-package",
|
|
|
|
|
|
|
|
|
|
|
|
/// The body describes either metadata about the RS or the reason for
|
|
|
|
|
|
/// the metadata snapshot request as determined by the MIME value
|
|
|
|
|
|
/// indicated in the Content-Type.
|
|
|
|
|
|
RecordingSession => "recording-session",
|
|
|
|
|
|
}, Default = Session
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
generate_id!(
|
|
|
|
|
|
/// An unique identifier in a session, referencing a
|
|
|
|
|
|
/// [struct.Content.html](Content element).
|
|
|
|
|
|
ContentId
|
|
|
|
|
|
);
|
2017-07-29 02:47:33 +01:00
|
|
|
|
|
2019-10-18 13:06:08 +02:00
|
|
|
|
/// Enum wrapping all of the various supported descriptions of a Content.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[derive(AsXml, Debug, Clone, PartialEq)]
|
|
|
|
|
|
#[xml()]
|
2019-10-18 13:06:08 +02:00
|
|
|
|
pub enum Description {
|
|
|
|
|
|
/// Jingle RTP Sessions (XEP-0167) description.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(transparent)]
|
2019-10-18 13:06:08 +02:00
|
|
|
|
Rtp(RtpDescription),
|
|
|
|
|
|
|
|
|
|
|
|
/// To be used for any description that isn’t known at compile-time.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
// TODO: replace with `#[xml(element, name = ..)]` once we have it.
|
|
|
|
|
|
#[xml(transparent)]
|
2019-10-18 13:06:08 +02:00
|
|
|
|
Unknown(Element),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TryFrom<Element> for Description {
|
|
|
|
|
|
type Error = Error;
|
|
|
|
|
|
|
|
|
|
|
|
fn try_from(elem: Element) -> Result<Description, Error> {
|
|
|
|
|
|
Ok(if elem.is("description", ns::JINGLE_RTP) {
|
|
|
|
|
|
Description::Rtp(RtpDescription::try_from(elem)?)
|
2024-08-09 15:53:15 +02:00
|
|
|
|
} else if elem.name() == "description" {
|
2019-10-18 13:06:08 +02:00
|
|
|
|
Description::Unknown(elem)
|
2024-08-09 15:53:15 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
return Err(Error::Other("Invalid description."));
|
2019-10-18 13:06:08 +02:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-09 15:53:15 +02:00
|
|
|
|
impl ::xso::FromXml for Description {
|
|
|
|
|
|
type Builder = ::xso::minidom_compat::FromEventsViaElement<Description>;
|
|
|
|
|
|
|
|
|
|
|
|
fn from_events(
|
|
|
|
|
|
qname: ::xso::exports::rxml::QName,
|
|
|
|
|
|
attrs: ::xso::exports::rxml::AttrMap,
|
|
|
|
|
|
) -> Result<Self::Builder, ::xso::error::FromEventsError> {
|
|
|
|
|
|
if qname.1 != "description" {
|
|
|
|
|
|
return Err(::xso::error::FromEventsError::Mismatch { name: qname, attrs });
|
|
|
|
|
|
}
|
|
|
|
|
|
Self::Builder::new(qname, attrs)
|
2019-10-18 13:06:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-09 15:53:15 +02:00
|
|
|
|
impl From<RtpDescription> for Description {
|
|
|
|
|
|
fn from(desc: RtpDescription) -> Description {
|
|
|
|
|
|
Description::Rtp(desc)
|
2019-10-18 13:06:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-12 17:13:42 +02:00
|
|
|
|
/// Enum wrapping all of the various supported transports of a Content.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[derive(AsXml, Debug, Clone, PartialEq)]
|
|
|
|
|
|
#[xml()]
|
2019-10-12 17:13:42 +02:00
|
|
|
|
pub enum Transport {
|
|
|
|
|
|
/// Jingle ICE-UDP Bytestreams (XEP-0176) transport.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(transparent)]
|
2019-10-12 17:13:42 +02:00
|
|
|
|
IceUdp(IceUdpTransport),
|
|
|
|
|
|
|
|
|
|
|
|
/// Jingle In-Band Bytestreams (XEP-0261) transport.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(transparent)]
|
2019-10-12 17:13:42 +02:00
|
|
|
|
Ibb(IbbTransport),
|
|
|
|
|
|
|
|
|
|
|
|
/// Jingle SOCKS5 Bytestreams (XEP-0260) transport.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(transparent)]
|
2019-10-12 17:13:42 +02:00
|
|
|
|
Socks5(Socks5Transport),
|
|
|
|
|
|
|
|
|
|
|
|
/// To be used for any transport that isn’t known at compile-time.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
// TODO: replace with `#[xml(element, name = ..)]` once we have it.
|
|
|
|
|
|
#[xml(transparent)]
|
2019-10-12 17:13:42 +02:00
|
|
|
|
Unknown(Element),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TryFrom<Element> for Transport {
|
|
|
|
|
|
type Error = Error;
|
|
|
|
|
|
|
|
|
|
|
|
fn try_from(elem: Element) -> Result<Transport, Error> {
|
|
|
|
|
|
Ok(if elem.is("transport", ns::JINGLE_ICE_UDP) {
|
|
|
|
|
|
Transport::IceUdp(IceUdpTransport::try_from(elem)?)
|
|
|
|
|
|
} else if elem.is("transport", ns::JINGLE_IBB) {
|
|
|
|
|
|
Transport::Ibb(IbbTransport::try_from(elem)?)
|
|
|
|
|
|
} else if elem.is("transport", ns::JINGLE_S5B) {
|
|
|
|
|
|
Transport::Socks5(Socks5Transport::try_from(elem)?)
|
2024-08-09 15:53:15 +02:00
|
|
|
|
} else if elem.name() == "transport" {
|
2019-10-12 17:13:42 +02:00
|
|
|
|
Transport::Unknown(elem)
|
2024-08-09 15:53:15 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
return Err(Error::Other("Invalid transport."));
|
2019-10-12 17:13:42 +02:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-09 15:53:15 +02:00
|
|
|
|
impl ::xso::FromXml for Transport {
|
|
|
|
|
|
type Builder = ::xso::minidom_compat::FromEventsViaElement<Transport>;
|
|
|
|
|
|
|
|
|
|
|
|
fn from_events(
|
|
|
|
|
|
qname: ::xso::exports::rxml::QName,
|
|
|
|
|
|
attrs: ::xso::exports::rxml::AttrMap,
|
|
|
|
|
|
) -> Result<Self::Builder, ::xso::error::FromEventsError> {
|
|
|
|
|
|
if qname.1 != "transport" {
|
|
|
|
|
|
return Err(::xso::error::FromEventsError::Mismatch { name: qname, attrs });
|
|
|
|
|
|
}
|
|
|
|
|
|
Self::Builder::new(qname, attrs)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-10-12 17:13:42 +02:00
|
|
|
|
impl From<IceUdpTransport> for Transport {
|
|
|
|
|
|
fn from(transport: IceUdpTransport) -> Transport {
|
|
|
|
|
|
Transport::IceUdp(transport)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl From<IbbTransport> for Transport {
|
|
|
|
|
|
fn from(transport: IbbTransport) -> Transport {
|
|
|
|
|
|
Transport::Ibb(transport)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Socks5Transport> for Transport {
|
|
|
|
|
|
fn from(transport: Socks5Transport) -> Transport {
|
|
|
|
|
|
Transport::Socks5(transport)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-09 15:53:15 +02:00
|
|
|
|
/// A security element inside a Jingle content, stubbed for now.
|
|
|
|
|
|
#[derive(FromXml, AsXml, Debug, Clone, PartialEq)]
|
|
|
|
|
|
#[xml(namespace = ns::JINGLE, name = "security")]
|
|
|
|
|
|
pub struct Security;
|
|
|
|
|
|
|
|
|
|
|
|
/// Describes a session’s content, there can be multiple content in one
|
|
|
|
|
|
/// session.
|
|
|
|
|
|
#[derive(FromXml, AsXml, Debug, Clone, PartialEq)]
|
|
|
|
|
|
#[xml(namespace = ns::JINGLE, name = "content")]
|
|
|
|
|
|
pub struct Content {
|
|
|
|
|
|
/// Who created this content.
|
|
|
|
|
|
#[xml(attribute)]
|
|
|
|
|
|
pub creator: Creator,
|
|
|
|
|
|
|
|
|
|
|
|
/// How the content definition is to be interpreted by the recipient.
|
|
|
|
|
|
#[xml(attribute(default))]
|
|
|
|
|
|
pub disposition: Disposition,
|
|
|
|
|
|
|
|
|
|
|
|
/// A per-session unique identifier for this content.
|
|
|
|
|
|
#[xml(attribute)]
|
|
|
|
|
|
pub name: ContentId,
|
|
|
|
|
|
|
|
|
|
|
|
/// Who can send data for this content.
|
|
|
|
|
|
#[xml(attribute(default))]
|
|
|
|
|
|
pub senders: Senders,
|
|
|
|
|
|
|
|
|
|
|
|
/// What to send.
|
|
|
|
|
|
#[xml(child(default))]
|
|
|
|
|
|
pub description: Option<Description>,
|
|
|
|
|
|
|
|
|
|
|
|
/// How to send it.
|
|
|
|
|
|
#[xml(child(default))]
|
|
|
|
|
|
pub transport: Option<Transport>,
|
|
|
|
|
|
|
|
|
|
|
|
/// With which security.
|
|
|
|
|
|
#[xml(child(default))]
|
|
|
|
|
|
pub security: Option<Security>,
|
2019-10-12 17:13:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-04 19:10:29 +02:00
|
|
|
|
impl Content {
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Create a new content.
|
2018-05-04 19:10:29 +02:00
|
|
|
|
pub fn new(creator: Creator, name: ContentId) -> Content {
|
|
|
|
|
|
Content {
|
|
|
|
|
|
creator,
|
|
|
|
|
|
name,
|
|
|
|
|
|
disposition: Disposition::Session,
|
|
|
|
|
|
senders: Senders::Both,
|
|
|
|
|
|
description: None,
|
|
|
|
|
|
transport: None,
|
|
|
|
|
|
security: None,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Set how the content is to be interpreted by the recipient.
|
2018-05-04 19:10:29 +02:00
|
|
|
|
pub fn with_disposition(mut self, disposition: Disposition) -> Content {
|
|
|
|
|
|
self.disposition = disposition;
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Specify who can send data for this content.
|
2018-05-04 19:10:29 +02:00
|
|
|
|
pub fn with_senders(mut self, senders: Senders) -> Content {
|
|
|
|
|
|
self.senders = senders;
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Set the description of this content.
|
2019-10-18 13:06:08 +02:00
|
|
|
|
pub fn with_description<D: Into<Description>>(mut self, description: D) -> Content {
|
|
|
|
|
|
self.description = Some(description.into());
|
2018-05-04 19:10:29 +02:00
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Set the transport of this content.
|
2019-10-12 17:13:42 +02:00
|
|
|
|
pub fn with_transport<T: Into<Transport>>(mut self, transport: T) -> Content {
|
|
|
|
|
|
self.transport = Some(transport.into());
|
2018-05-04 19:10:29 +02:00
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Set the security of this content.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
pub fn with_security(mut self, security: Security) -> Content {
|
2018-05-04 19:10:29 +02:00
|
|
|
|
self.security = Some(security);
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Lists the possible reasons to be included in a Jingle iq.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[derive(FromXml, AsXml, Debug, Clone, PartialEq)]
|
|
|
|
|
|
#[xml(namespace = ns::JINGLE)]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub enum Reason {
|
2018-09-20 20:28:50 +02:00
|
|
|
|
/// The party prefers to use an existing session with the peer rather than
|
|
|
|
|
|
/// initiate a new session; the Jingle session ID of the alternative
|
2022-12-27 16:31:58 +01:00
|
|
|
|
/// session SHOULD be provided as the XML character data of the \<sid/\>
|
2018-09-20 20:28:50 +02:00
|
|
|
|
/// child.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "alternative-session")]
|
|
|
|
|
|
AlternativeSession {
|
|
|
|
|
|
/// Session ID of the alternative session.
|
|
|
|
|
|
#[xml(extract(namespace = ns::JINGLE, name = "sid", default, fields(text(type_ = String))))]
|
|
|
|
|
|
sid: Option<String>,
|
|
|
|
|
|
},
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The party is busy and cannot accept a session.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "busy")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
Busy,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The initiator wishes to formally cancel the session initiation request.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "cancel")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
Cancel,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The action is related to connectivity problems.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "connectivity-error")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
ConnectivityError,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The party wishes to formally decline the session.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "decline")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
Decline,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The session length has exceeded a pre-defined time limit (e.g., a
|
|
|
|
|
|
/// meeting hosted at a conference service).
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "expired")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
Expired,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The party has been unable to initialize processing related to the
|
|
|
|
|
|
/// application type.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "failed-application")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
FailedApplication,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The party has been unable to establish connectivity for the transport
|
|
|
|
|
|
/// method.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "failed-transport")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
FailedTransport,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The action is related to a non-specific application error.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "general-error")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
GeneralError,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The entity is going offline or is no longer available.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "gone")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
Gone,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The party supports the offered application type but does not support
|
|
|
|
|
|
/// the offered or negotiated parameters.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "incompatible-parameters")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
IncompatibleParameters,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The action is related to media processing problems.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "media-error")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
MediaError,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The action is related to a violation of local security policies.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "security-error")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
SecurityError,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The action is generated during the normal course of state management
|
|
|
|
|
|
/// and does not reflect any error.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "success")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
Success,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// A request has not been answered so the sender is timing out the
|
|
|
|
|
|
/// request.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "timeout")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
Timeout,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The party supports none of the offered application types.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "unsupported-applications")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
UnsupportedApplications,
|
2018-09-20 20:28:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// The party supports none of the offered transport methods.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(name = "unsupported-transports")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
UnsupportedTransports,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-02-28 02:40:04 +01:00
|
|
|
|
type Lang = String;
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Informs the recipient of something.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[derive(FromXml, AsXml, Debug, Clone, PartialEq)]
|
|
|
|
|
|
#[xml(namespace = ns::JINGLE, name = "reason")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub struct ReasonElement {
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// The list of possible reasons to be included in a Jingle iq.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(child)]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub reason: Reason,
|
2018-09-20 21:15:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// A human-readable description of this reason.
|
2024-12-18 15:39:30 +01:00
|
|
|
|
#[xml(extract(n = .., namespace = ns::JINGLE, name = "text", fields(
|
|
|
|
|
|
attribute(type_ = String, name = "xml:lang", default),
|
|
|
|
|
|
text(type_ = String),
|
|
|
|
|
|
)))]
|
2019-02-28 02:40:04 +01:00
|
|
|
|
pub texts: BTreeMap<Lang, String>,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-27 20:57:01 +01:00
|
|
|
|
impl fmt::Display for ReasonElement {
|
|
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
|
write!(fmt, "{}", Element::from(self.reason.clone()).name())?;
|
|
|
|
|
|
if let Some(text) = self.texts.get("en") {
|
|
|
|
|
|
write!(fmt, ": {}", text)?;
|
|
|
|
|
|
} else if let Some(text) = self.texts.get("") {
|
|
|
|
|
|
write!(fmt, ": {}", text)?;
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 20:28:50 +02:00
|
|
|
|
generate_id!(
|
|
|
|
|
|
/// Unique identifier for a session between two JIDs.
|
|
|
|
|
|
SessionId
|
|
|
|
|
|
);
|
2017-06-14 02:28:42 +01:00
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// The main Jingle container, to be included in an iq stanza.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[derive(FromXml, AsXml, Debug, Clone, PartialEq)]
|
|
|
|
|
|
#[xml(namespace = ns::JINGLE, name = "jingle")]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub struct Jingle {
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// The action to execute on both ends.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(attribute)]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub action: Action,
|
2018-09-20 21:15:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// Who the initiator is.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(attribute(default))]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub initiator: Option<Jid>,
|
2018-09-20 21:15:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// Who the responder is.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(attribute(default))]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub responder: Option<Jid>,
|
2018-09-20 21:15:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// Unique session identifier between two entities.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(attribute)]
|
2017-06-25 22:14:51 +01:00
|
|
|
|
pub sid: SessionId,
|
2018-09-20 21:15:50 +02:00
|
|
|
|
|
2019-09-08 18:24:45 +02:00
|
|
|
|
/// A list of contents to be negotiated in this session.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(child(n = ..))]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub contents: Vec<Content>,
|
2018-09-20 21:15:50 +02:00
|
|
|
|
|
|
|
|
|
|
/// An optional reason.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(child(default))]
|
2017-04-19 02:27:42 +01:00
|
|
|
|
pub reason: Option<ReasonElement>,
|
2018-09-20 21:15:50 +02:00
|
|
|
|
|
2020-11-27 20:58:20 +01:00
|
|
|
|
/// An optional grouping.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(child(default))]
|
2020-11-27 20:58:20 +01:00
|
|
|
|
pub group: Option<Group>,
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Payloads to be included.
|
2024-08-09 15:53:15 +02:00
|
|
|
|
#[xml(child(n = ..))]
|
2017-04-28 23:45:27 +01:00
|
|
|
|
pub other: Vec<Element>,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-16 15:08:17 +02:00
|
|
|
|
impl IqSetPayload for Jingle {}
|
|
|
|
|
|
|
2018-05-04 19:10:29 +02:00
|
|
|
|
impl Jingle {
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Create a new Jingle element.
|
2018-05-04 19:10:29 +02:00
|
|
|
|
pub fn new(action: Action, sid: SessionId) -> Jingle {
|
|
|
|
|
|
Jingle {
|
2019-02-21 21:00:58 +01:00
|
|
|
|
action,
|
|
|
|
|
|
sid,
|
2018-05-04 19:10:29 +02:00
|
|
|
|
initiator: None,
|
|
|
|
|
|
responder: None,
|
|
|
|
|
|
contents: Vec::new(),
|
|
|
|
|
|
reason: None,
|
2020-11-27 20:58:20 +01:00
|
|
|
|
group: None,
|
2018-05-04 19:10:29 +02:00
|
|
|
|
other: Vec::new(),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Set the initiator’s JID.
|
2018-05-04 19:10:29 +02:00
|
|
|
|
pub fn with_initiator(mut self, initiator: Jid) -> Jingle {
|
|
|
|
|
|
self.initiator = Some(initiator);
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Set the responder’s JID.
|
2018-05-04 19:10:29 +02:00
|
|
|
|
pub fn with_responder(mut self, responder: Jid) -> Jingle {
|
|
|
|
|
|
self.responder = Some(responder);
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Add a content to this Jingle container.
|
2018-05-04 19:10:29 +02:00
|
|
|
|
pub fn add_content(mut self, content: Content) -> Jingle {
|
|
|
|
|
|
self.contents.push(content);
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-20 21:15:50 +02:00
|
|
|
|
/// Set the reason in this Jingle container.
|
2020-11-27 20:55:41 +01:00
|
|
|
|
pub fn set_reason(mut self, reason: ReasonElement) -> Jingle {
|
|
|
|
|
|
self.reason = Some(reason);
|
2018-05-04 19:10:29 +02:00
|
|
|
|
self
|
|
|
|
|
|
}
|
2020-11-27 20:58:20 +01:00
|
|
|
|
|
|
|
|
|
|
/// Set the grouping in this Jingle container.
|
|
|
|
|
|
pub fn set_group(mut self, group: Group) -> Jingle {
|
|
|
|
|
|
self.group = Some(group);
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
2018-05-04 19:10:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-19 02:27:42 +01:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests {
|
2017-05-04 01:20:28 +01:00
|
|
|
|
use super::*;
|
2024-12-18 15:39:30 +01:00
|
|
|
|
use xso::error::FromElementError;
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
2018-10-28 13:10:48 +01:00
|
|
|
|
#[cfg(target_pointer_width = "32")]
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_size() {
|
|
|
|
|
|
assert_size!(Action, 1);
|
|
|
|
|
|
assert_size!(Creator, 1);
|
|
|
|
|
|
assert_size!(Senders, 1);
|
|
|
|
|
|
assert_size!(Disposition, 1);
|
|
|
|
|
|
assert_size!(ContentId, 12);
|
2024-08-09 15:53:15 +02:00
|
|
|
|
assert_size!(Content, 156);
|
2024-12-18 15:39:30 +01:00
|
|
|
|
assert_size!(Reason, 12);
|
|
|
|
|
|
assert_size!(ReasonElement, 24);
|
2018-10-28 13:10:48 +01:00
|
|
|
|
assert_size!(SessionId, 12);
|
2024-12-18 15:39:30 +01:00
|
|
|
|
assert_size!(Jingle, 112);
|
2018-10-28 13:10:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
2018-10-26 14:26:16 +02:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_size() {
|
|
|
|
|
|
assert_size!(Action, 1);
|
|
|
|
|
|
assert_size!(Creator, 1);
|
|
|
|
|
|
assert_size!(Senders, 1);
|
|
|
|
|
|
assert_size!(Disposition, 1);
|
|
|
|
|
|
assert_size!(ContentId, 24);
|
2024-08-09 15:53:15 +02:00
|
|
|
|
assert_size!(Content, 312);
|
2024-12-18 15:39:30 +01:00
|
|
|
|
assert_size!(Reason, 24);
|
|
|
|
|
|
assert_size!(ReasonElement, 48);
|
2018-10-26 14:26:16 +02:00
|
|
|
|
assert_size!(SessionId, 24);
|
2024-12-18 15:39:30 +01:00
|
|
|
|
assert_size!(Jingle, 224);
|
2018-10-26 14:26:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-04-19 02:27:42 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_simple() {
|
2018-12-18 15:32:05 +01:00
|
|
|
|
let elem: Element =
|
|
|
|
|
|
"<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let jingle = Jingle::try_from(elem).unwrap();
|
2017-05-04 01:20:28 +01:00
|
|
|
|
assert_eq!(jingle.action, Action::SessionInitiate);
|
2017-06-25 22:14:51 +01:00
|
|
|
|
assert_eq!(jingle.sid, SessionId(String::from("coucou")));
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_invalid_jingle() {
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1'/>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-08-09 15:53:15 +02:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message,
|
|
|
|
|
|
"Required attribute field 'action' on Jingle element missing."
|
|
|
|
|
|
);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
2018-12-18 15:32:05 +01:00
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-info'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-08-09 15:53:15 +02:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message,
|
|
|
|
|
|
"Required attribute field 'sid' on Jingle element missing."
|
|
|
|
|
|
);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
2018-12-18 15:32:05 +01:00
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='coucou' sid='coucou'/>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::TextParseError(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-06-21 16:27:43 +02:00
|
|
|
|
assert_eq!(message.to_string(), "Unknown value for 'action' attribute.");
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_content() {
|
2019-10-12 17:13:42 +02:00
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><content creator='initiator' name='coucou'><description/><transport xmlns='urn:xmpp:jingle:transports:stub:0'/></content></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let jingle = Jingle::try_from(elem).unwrap();
|
2017-05-04 01:20:28 +01:00
|
|
|
|
assert_eq!(jingle.contents[0].creator, Creator::Initiator);
|
2017-07-15 11:37:29 +01:00
|
|
|
|
assert_eq!(jingle.contents[0].name, ContentId(String::from("coucou")));
|
2017-05-04 01:20:28 +01:00
|
|
|
|
assert_eq!(jingle.contents[0].senders, Senders::Both);
|
2017-10-31 17:17:06 +00:00
|
|
|
|
assert_eq!(jingle.contents[0].disposition, Disposition::Session);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
2019-10-12 17:13:42 +02:00
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><content creator='initiator' name='coucou' senders='both'><description/><transport xmlns='urn:xmpp:jingle:transports:stub:0'/></content></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let jingle = Jingle::try_from(elem).unwrap();
|
2017-05-04 01:20:28 +01:00
|
|
|
|
assert_eq!(jingle.contents[0].senders, Senders::Both);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
2019-10-12 17:13:42 +02:00
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><content creator='initiator' name='coucou' disposition='early-session'><description/><transport xmlns='urn:xmpp:jingle:transports:stub:0'/></content></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let jingle = Jingle::try_from(elem).unwrap();
|
2017-10-31 17:17:06 +00:00
|
|
|
|
assert_eq!(jingle.contents[0].disposition, Disposition::EarlySession);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_invalid_content() {
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><content/></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-08-09 15:53:15 +02:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message,
|
|
|
|
|
|
"Required attribute field 'creator' on Content element missing."
|
|
|
|
|
|
);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><content creator='initiator'/></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-08-09 15:53:15 +02:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message,
|
|
|
|
|
|
"Required attribute field 'name' on Content element missing."
|
|
|
|
|
|
);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><content creator='coucou' name='coucou'/></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::TextParseError(string)) => string,
|
|
|
|
|
|
other => panic!("unexpected result: {:?}", other),
|
2017-04-19 02:27:42 +01:00
|
|
|
|
};
|
2024-06-21 16:27:43 +02:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message.to_string(),
|
|
|
|
|
|
"Unknown value for 'creator' attribute."
|
|
|
|
|
|
);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><content creator='initiator' name='coucou' senders='coucou'/></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::TextParseError(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-06-21 16:27:43 +02:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message.to_string(),
|
|
|
|
|
|
"Unknown value for 'senders' attribute."
|
|
|
|
|
|
);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><content creator='initiator' name='coucou' senders=''/></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::TextParseError(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-06-21 16:27:43 +02:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message.to_string(),
|
|
|
|
|
|
"Unknown value for 'senders' attribute."
|
|
|
|
|
|
);
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_reason() {
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><reason><success/></reason></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let jingle = Jingle::try_from(elem).unwrap();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let reason = jingle.reason.unwrap();
|
2017-05-04 01:20:28 +01:00
|
|
|
|
assert_eq!(reason.reason, Reason::Success);
|
2019-02-28 02:40:04 +01:00
|
|
|
|
assert_eq!(reason.texts, BTreeMap::new());
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><reason><success/><text>coucou</text></reason></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let jingle = Jingle::try_from(elem).unwrap();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let reason = jingle.reason.unwrap();
|
2017-05-04 01:20:28 +01:00
|
|
|
|
assert_eq!(reason.reason, Reason::Success);
|
2019-02-28 02:40:04 +01:00
|
|
|
|
assert_eq!(reason.texts.get(""), Some(&String::from("coucou")));
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
2024-12-20 08:57:46 +01:00
|
|
|
|
fn test_missing_reason_text() {
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><reason/></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-12-18 15:39:30 +01:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message,
|
|
|
|
|
|
"Missing child field 'reason' in ReasonElement element."
|
|
|
|
|
|
);
|
2024-12-20 08:57:46 +01:00
|
|
|
|
}
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
2024-12-20 08:57:46 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
#[cfg_attr(feature = "disable-validation", should_panic = "Result::unwrap_err")]
|
|
|
|
|
|
fn test_invalid_child_in_reason() {
|
|
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><reason><decline/><a/></reason></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-12-18 15:39:30 +01:00
|
|
|
|
assert_eq!(message, "Unknown child in ReasonElement element.");
|
2024-12-20 08:57:46 +01:00
|
|
|
|
}
|
2017-04-19 02:27:42 +01:00
|
|
|
|
|
2024-12-20 08:57:46 +01:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_multiple_reason_children() {
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><reason><decline/></reason><reason/></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:27:42 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-19 02:27:42 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2024-08-09 15:53:15 +02:00
|
|
|
|
assert_eq!(
|
|
|
|
|
|
message,
|
|
|
|
|
|
"Jingle element must not have more than one child in field 'reason'."
|
|
|
|
|
|
);
|
2017-04-19 02:38:10 +01:00
|
|
|
|
|
2024-12-18 15:39:30 +01:00
|
|
|
|
// TODO: Reenable this test once xso is able to validate that no more than one text is
|
|
|
|
|
|
// there for every xml:lang.
|
|
|
|
|
|
/*
|
2017-04-19 02:38:10 +01:00
|
|
|
|
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'><reason><decline/><text/><text/></reason></jingle>".parse().unwrap();
|
2017-05-23 23:31:33 +01:00
|
|
|
|
let error = Jingle::try_from(elem).unwrap_err();
|
2017-04-19 02:38:10 +01:00
|
|
|
|
let message = match error {
|
2024-06-21 16:27:43 +02:00
|
|
|
|
FromElementError::Invalid(Error::Other(string)) => string,
|
2017-04-19 02:38:10 +01:00
|
|
|
|
_ => panic!(),
|
|
|
|
|
|
};
|
2019-02-28 02:40:04 +01:00
|
|
|
|
assert_eq!(message, "Text element present twice for the same xml:lang.");
|
2024-12-18 15:39:30 +01:00
|
|
|
|
*/
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|
2019-11-27 18:16:33 +01:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn test_serialize_jingle() {
|
|
|
|
|
|
let reference: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='a73sjjvkla37jfea'><content xmlns='urn:xmpp:jingle:1' creator='initiator' name='this-is-a-stub'><description xmlns='urn:xmpp:jingle:apps:stub:0'/><transport xmlns='urn:xmpp:jingle:transports:stub:0'/></content></jingle>"
|
|
|
|
|
|
.parse()
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
let jingle = Jingle {
|
|
|
|
|
|
action: Action::SessionInitiate,
|
|
|
|
|
|
initiator: None,
|
|
|
|
|
|
responder: None,
|
|
|
|
|
|
sid: SessionId(String::from("a73sjjvkla37jfea")),
|
|
|
|
|
|
contents: vec![Content {
|
|
|
|
|
|
creator: Creator::Initiator,
|
|
|
|
|
|
disposition: Disposition::default(),
|
|
|
|
|
|
name: ContentId(String::from("this-is-a-stub")),
|
|
|
|
|
|
senders: Senders::default(),
|
|
|
|
|
|
description: Some(Description::Unknown(
|
2020-04-02 22:45:20 +02:00
|
|
|
|
Element::builder("description", "urn:xmpp:jingle:apps:stub:0").build(),
|
2019-11-27 18:16:33 +01:00
|
|
|
|
)),
|
|
|
|
|
|
transport: Some(Transport::Unknown(
|
2020-04-02 22:45:20 +02:00
|
|
|
|
Element::builder("transport", "urn:xmpp:jingle:transports:stub:0").build(),
|
2019-11-27 18:16:33 +01:00
|
|
|
|
)),
|
|
|
|
|
|
security: None,
|
|
|
|
|
|
}],
|
|
|
|
|
|
reason: None,
|
2020-11-27 20:58:20 +01:00
|
|
|
|
group: None,
|
2019-11-27 18:16:33 +01:00
|
|
|
|
other: vec![],
|
|
|
|
|
|
};
|
|
|
|
|
|
let serialized: Element = jingle.into();
|
|
|
|
|
|
assert_eq!(serialized, reference);
|
|
|
|
|
|
}
|
2017-04-19 02:27:42 +01:00
|
|
|
|
}
|