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