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-0300: Use of Cryptographic Hash Functions in XMPP
56pub mod hashes;
57
58/// XEP-0308: Last Message Correction
59pub mod message_correct;
60
61/// XEP-0380: Explicit Message Encryption
62pub mod eme;
63
64/// XEP-0390: Entity Capabilities 2.0
65pub mod ecaps2;
66
67/// Lists every known payload of a `<message/>`.
68#[derive(Debug)]
69pub enum MessagePayload {
70 Body(body::Body),
71 ChatState(chatstates::ChatState),
72 Receipt(receipts::Receipt),
73 Delay(delay::Delay),
74 Attention(attention::Attention),
75 MessageCorrect(message_correct::MessageCorrect),
76 ExplicitMessageEncryption(eme::ExplicitMessageEncryption),
77}
78
79/// Parse one of the payloads of a `<message/>` element, and return `Some` of a
80/// `MessagePayload` if parsing it succeeded, `None` otherwise.
81pub fn parse_message_payload(elem: &Element) -> Option<MessagePayload> {
82 if let Ok(body) = body::parse_body(elem) {
83 Some(MessagePayload::Body(body))
84 } else if let Ok(chatstate) = chatstates::parse_chatstate(elem) {
85 Some(MessagePayload::ChatState(chatstate))
86 } else if let Ok(receipt) = receipts::parse_receipt(elem) {
87 Some(MessagePayload::Receipt(receipt))
88 } else if let Ok(delay) = delay::parse_delay(elem) {
89 Some(MessagePayload::Delay(delay))
90 } else if let Ok(attention) = attention::parse_attention(elem) {
91 Some(MessagePayload::Attention(attention))
92 } else if let Ok(replace) = message_correct::parse_message_correct(elem) {
93 Some(MessagePayload::MessageCorrect(replace))
94 } else if let Ok(eme) = eme::parse_explicit_message_encryption(elem) {
95 Some(MessagePayload::ExplicitMessageEncryption(eme))
96 } else {
97 None
98 }
99}