lib.rs

  1//! A crate parsing common XMPP elements into Rust structures.
  2//!
  3//! The main entrypoint is `parse_message_payload`, it takes a minidom
  4//! `Element` reference and optionally returns `Some(MessagePayload)` if the
  5//! parsing succeeded.
  6//!
  7//! Parsed structs can then be manipulated internally, and serialised back
  8//! before being sent over the wire.
  9
 10extern crate minidom;
 11extern crate base64;
 12use minidom::Element;
 13
 14/// Error type returned by every parser on failure.
 15pub mod error;
 16/// XML namespace definitions used through XMPP.
 17pub mod ns;
 18
 19/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
 20pub mod body;
 21
 22/// XEP-0004: Data Forms
 23pub mod data_forms;
 24
 25/// XEP-0030: Service Discovery
 26pub mod disco;
 27
 28/// XEP-0047: In-Band Bytestreams
 29pub mod ibb;
 30
 31/// XEP-0085: Chat State Notifications
 32pub mod chatstates;
 33
 34/// XEP-0166: Jingle
 35pub mod jingle;
 36
 37/// XEP-0184: Message Delivery Receipts
 38pub mod receipts;
 39
 40/// XEP-0199: XMPP Ping
 41pub mod ping;
 42
 43/// XEP-0203: Delayed Delivery
 44pub mod delay;
 45
 46/// XEP-0221: Data Forms Media Element
 47pub mod media_element;
 48
 49/// XEP-0224: Attention
 50pub mod attention;
 51
 52/// XEP-0234: Jingle File Transfer
 53pub mod jingle_ft;
 54
 55/// XEP-0261: Jingle In-Band Bytestreams Transport Method
 56pub mod jingle_ibb;
 57
 58/// XEP-0300: Use of Cryptographic Hash Functions in XMPP
 59pub mod hashes;
 60
 61/// XEP-0308: Last Message Correction
 62pub mod message_correct;
 63
 64/// XEP-0380: Explicit Message Encryption
 65pub mod eme;
 66
 67/// XEP-0390: Entity Capabilities 2.0
 68pub mod ecaps2;
 69
 70/// Lists every known payload of a `<message/>`.
 71#[derive(Debug)]
 72pub enum MessagePayload {
 73    Body(body::Body),
 74    ChatState(chatstates::ChatState),
 75    Receipt(receipts::Receipt),
 76    Delay(delay::Delay),
 77    Attention(attention::Attention),
 78    MessageCorrect(message_correct::MessageCorrect),
 79    ExplicitMessageEncryption(eme::ExplicitMessageEncryption),
 80}
 81
 82/// Parse one of the payloads of a `<message/>` element, and return `Some` of a
 83/// `MessagePayload` if parsing it succeeded, `None` otherwise.
 84pub fn parse_message_payload(elem: &Element) -> Option<MessagePayload> {
 85    if let Ok(body) = body::parse_body(elem) {
 86        Some(MessagePayload::Body(body))
 87    } else if let Ok(chatstate) = chatstates::parse_chatstate(elem) {
 88        Some(MessagePayload::ChatState(chatstate))
 89    } else if let Ok(receipt) = receipts::parse_receipt(elem) {
 90        Some(MessagePayload::Receipt(receipt))
 91    } else if let Ok(delay) = delay::parse_delay(elem) {
 92        Some(MessagePayload::Delay(delay))
 93    } else if let Ok(attention) = attention::parse_attention(elem) {
 94        Some(MessagePayload::Attention(attention))
 95    } else if let Ok(replace) = message_correct::parse_message_correct(elem) {
 96        Some(MessagePayload::MessageCorrect(replace))
 97    } else if let Ok(eme) = eme::parse_explicit_message_encryption(elem) {
 98        Some(MessagePayload::ExplicitMessageEncryption(eme))
 99    } else {
100        None
101    }
102}