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-0390: Entity Capabilities 2.0
46pub mod ecaps2;
47
48/// Lists every known payload of a `<message/>`.
49#[derive(Debug)]
50pub enum MessagePayload {
51 Body(body::Body),
52 ChatState(chatstates::ChatState),
53 Receipt(receipts::Receipt),
54}
55
56/// Parse one of the payloads of a `<message/>` element, and return `Some` of a `MessagePayload` if parsing it succeeded, `None` otherwise.
57pub fn parse_message_payload(elem: &Element) -> Option<MessagePayload> {
58 if let Ok(body) = body::parse_body(elem) {
59 Some(MessagePayload::Body(body))
60 } else if let Ok(chatstate) = chatstates::parse_chatstate(elem) {
61 Some(MessagePayload::ChatState(chatstate))
62 } else if let Ok(receipt) = receipts::parse_receipt(elem) {
63 Some(MessagePayload::Receipt(receipt))
64 } else {
65 None
66 }
67}