jingle: Document this module.

This commit is contained in:
Emmanuel Gil Peyrot 2018-09-20 21:15:50 +02:00
commit 0da5639be5

View file

@ -4,8 +4,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#![allow(missing_docs)]
use try_from::TryFrom; use try_from::TryFrom;
use std::str::FromStr; use std::str::FromStr;
@ -168,6 +166,8 @@ generate_id!(
); );
generate_element!( generate_element!(
/// Describes a session’s content, there can be multiple content in one
/// session.
Content, "content", JINGLE, Content, "content", JINGLE,
attributes: [ attributes: [
/// Who created this content. /// Who created this content.
@ -183,13 +183,19 @@ generate_element!(
senders: Senders = "senders" => default senders: Senders = "senders" => default
], ],
children: [ children: [
/// What to send.
description: Option<Element> = ("description", JINGLE) => Element, description: Option<Element> = ("description", JINGLE) => Element,
/// How to send it.
transport: Option<Element> = ("transport", JINGLE) => Element, transport: Option<Element> = ("transport", JINGLE) => Element,
/// With which security.
security: Option<Element> = ("security", JINGLE) => Element security: Option<Element> = ("security", JINGLE) => Element
] ]
); );
impl Content { impl Content {
/// Create a new content.
pub fn new(creator: Creator, name: ContentId) -> Content { pub fn new(creator: Creator, name: ContentId) -> Content {
Content { Content {
creator, creator,
@ -202,32 +208,38 @@ impl Content {
} }
} }
/// Set how the content is to be interpreted by the recipient.
pub fn with_disposition(mut self, disposition: Disposition) -> Content { pub fn with_disposition(mut self, disposition: Disposition) -> Content {
self.disposition = disposition; self.disposition = disposition;
self self
} }
/// Specify who can send data for this content.
pub fn with_senders(mut self, senders: Senders) -> Content { pub fn with_senders(mut self, senders: Senders) -> Content {
self.senders = senders; self.senders = senders;
self self
} }
/// Set the description of this content.
pub fn with_description(mut self, description: Element) -> Content { pub fn with_description(mut self, description: Element) -> Content {
self.description = Some(description); self.description = Some(description);
self self
} }
/// Set the transport of this content.
pub fn with_transport(mut self, transport: Element) -> Content { pub fn with_transport(mut self, transport: Element) -> Content {
self.transport = Some(transport); self.transport = Some(transport);
self self
} }
/// Set the security of this content.
pub fn with_security(mut self, security: Element) -> Content { pub fn with_security(mut self, security: Element) -> Content {
self.security = Some(security); self.security = Some(security);
self self
} }
} }
/// Lists the possible reasons to be included in a Jingle iq.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum Reason { pub enum Reason {
/// The party prefers to use an existing session with the peer rather than /// The party prefers to use an existing session with the peer rather than
@ -343,9 +355,13 @@ impl From<Reason> for Element {
} }
} }
/// Informs the recipient of something.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ReasonElement { pub struct ReasonElement {
/// The list of possible reasons to be included in a Jingle iq.
pub reason: Reason, pub reason: Reason,
/// A human-readable description of this reason.
pub text: Option<String>, pub text: Option<String>,
} }
@ -397,20 +413,35 @@ generate_id!(
SessionId SessionId
); );
/// The main Jingle container, to be included in an iq stanza.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Jingle { pub struct Jingle {
/// The action to execute on both ends.
pub action: Action, pub action: Action,
/// Who the initiator is.
pub initiator: Option<Jid>, pub initiator: Option<Jid>,
/// Who the responder is.
pub responder: Option<Jid>, pub responder: Option<Jid>,
/// Unique session identifier between two entities.
pub sid: SessionId, pub sid: SessionId,
/// A list of contents to be negociated in this session.
pub contents: Vec<Content>, pub contents: Vec<Content>,
/// An optional reason.
pub reason: Option<ReasonElement>, pub reason: Option<ReasonElement>,
/// Payloads to be included.
pub other: Vec<Element>, pub other: Vec<Element>,
} }
impl IqSetPayload for Jingle {} impl IqSetPayload for Jingle {}
impl Jingle { impl Jingle {
/// Create a new Jingle element.
pub fn new(action: Action, sid: SessionId) -> Jingle { pub fn new(action: Action, sid: SessionId) -> Jingle {
Jingle { Jingle {
action: action, action: action,
@ -423,21 +454,25 @@ impl Jingle {
} }
} }
/// Set the initiator’s JID.
pub fn with_initiator(mut self, initiator: Jid) -> Jingle { pub fn with_initiator(mut self, initiator: Jid) -> Jingle {
self.initiator = Some(initiator); self.initiator = Some(initiator);
self self
} }
/// Set the responder’s JID.
pub fn with_responder(mut self, responder: Jid) -> Jingle { pub fn with_responder(mut self, responder: Jid) -> Jingle {
self.responder = Some(responder); self.responder = Some(responder);
self self
} }
/// Add a content to this Jingle container.
pub fn add_content(mut self, content: Content) -> Jingle { pub fn add_content(mut self, content: Content) -> Jingle {
self.contents.push(content); self.contents.push(content);
self self
} }
/// Set the reason in this Jingle container.
pub fn set_reason(mut self, content: Content) -> Jingle { pub fn set_reason(mut self, content: Content) -> Jingle {
self.contents.push(content); self.contents.push(content);
self self