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;
11use minidom::Element;
12
13/// Error type returned by every parser on failure.
14pub mod error;
15/// XML namespace definitions used through XMPP.
16pub mod ns;
17
18/// RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core
19pub mod body;
20
21/// XEP-0004: Data Forms
22pub mod data_forms;
23
24/// XEP-0030: Service Discovery
25pub mod disco;
26
27/// XEP-0047: In-Band Bytestreams
28pub mod ibb;
29
30/// XEP-0085: Chat State Notifications
31pub mod chatstates;
32
33/// XEP-0166: Jingle
34pub mod jingle;
35
36/// XEP-0184: Message Delivery Receipts
37pub mod receipts;
38
39/// XEP-0199: XMPP Ping
40pub mod ping;
41
42/// XEP-0221: Data Forms Media Element
43pub mod media_element;
44
45/// XEP-0224: Attention
46pub mod attention;
47
48/// XEP-0308: Last Message Correction
49pub mod message_correct;
50
51/// XEP-0390: Entity Capabilities 2.0
52pub mod ecaps2;
53
54/// Lists every known payload of a `<message/>`.
55#[derive(Debug)]
56pub enum MessagePayload {
57 Body(body::Body),
58 ChatState(chatstates::ChatState),
59 Receipt(receipts::Receipt),
60 Attention(attention::Attention),
61 MessageCorrect(message_correct::MessageCorrect),
62}
63
64/// Parse one of the payloads of a `<message/>` element, and return `Some` of a
65/// `MessagePayload` if parsing it succeeded, `None` otherwise.
66pub fn parse_message_payload(elem: &Element) -> Option<MessagePayload> {
67 if let Ok(body) = body::parse_body(elem) {
68 Some(MessagePayload::Body(body))
69 } else if let Ok(chatstate) = chatstates::parse_chatstate(elem) {
70 Some(MessagePayload::ChatState(chatstate))
71 } else if let Ok(receipt) = receipts::parse_receipt(elem) {
72 Some(MessagePayload::Receipt(receipt))
73 } else if let Ok(attention) = attention::parse_attention(elem) {
74 Some(MessagePayload::Attention(attention))
75 } else if let Ok(replace) = message_correct::parse_message_correct(elem) {
76 Some(MessagePayload::MessageCorrect(replace))
77 } else {
78 None
79 }
80}