parsers: Add Message::extract_valid_payload helper
This commit is contained in:
parent
c1a3c85556
commit
50425617b5
4 changed files with 33 additions and 11 deletions
|
|
@ -21,6 +21,7 @@ sha2 = "0.10"
|
||||||
sha3 = "0.10"
|
sha3 = "0.10"
|
||||||
blake2 = "0.10.4"
|
blake2 = "0.10.4"
|
||||||
chrono = { version = "0.4.5", default-features = false, features = ["std"] }
|
chrono = { version = "0.4.5", default-features = false, features = ["std"] }
|
||||||
|
log = { version = "0.4", optional = true }
|
||||||
# same repository dependencies
|
# same repository dependencies
|
||||||
jid = { version = "0.11", path = "../jid", features = ["minidom"] }
|
jid = { version = "0.11", path = "../jid", features = ["minidom"] }
|
||||||
minidom = { version = "0.16", path = "../minidom" }
|
minidom = { version = "0.16", path = "../minidom" }
|
||||||
|
|
@ -34,6 +35,8 @@ component = []
|
||||||
disable-validation = []
|
disable-validation = []
|
||||||
# Enable serde support in jid crate
|
# Enable serde support in jid crate
|
||||||
serde = [ "jid/serde" ]
|
serde = [ "jid/serde" ]
|
||||||
|
# Enable some additional logging in helpers
|
||||||
|
log = [ "dep:log" ]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
rustdoc-args = [ "--sort-modules-by-appearance", "-Zunstable-options" ]
|
rustdoc-args = [ "--sort-modules-by-appearance", "-Zunstable-options" ]
|
||||||
|
|
|
||||||
|
|
@ -36,20 +36,21 @@ XXXX-YY-ZZ RELEASER <admin@example.com>
|
||||||
fast::Tls0Rtt, legacy_omemo::IsPreKey, mam::Complete, sm::ResumeAttr (!476)
|
fast::Tls0Rtt, legacy_omemo::IsPreKey, mam::Complete, sm::ResumeAttr (!476)
|
||||||
- bookmarks::Conference and bookmarks2::Conference use ResourcePart to store
|
- bookmarks::Conference and bookmarks2::Conference use ResourcePart to store
|
||||||
the optional nickname instead of a String (!485)
|
the optional nickname instead of a String (!485)
|
||||||
|
* New parsers/serialisers:
|
||||||
|
- Stream Features (RFC 6120) (!400)
|
||||||
|
- Extensible SASL Profile (XEP-0388)
|
||||||
|
- SASL Channel-Binding Type Capability (XEP-0440)
|
||||||
|
- Stream Limits Advertisement (XEP-0478)
|
||||||
|
- Message Displayed Synchronization (XEP-0490)
|
||||||
|
- RFC 6120 stream errors
|
||||||
* Improvements:
|
* Improvements:
|
||||||
|
- Add support for `<optional/> in XEP-0198 feature advertisment
|
||||||
|
- Add support application-specific error conditions in XEP-0198
|
||||||
- Keep unsupported vCard elements as `minidom::Element`, so that they
|
- Keep unsupported vCard elements as `minidom::Element`, so that they
|
||||||
get serialized back instead of being dropped. We now also test for
|
get serialized back instead of being dropped. We now also test for
|
||||||
the size of these elements (!472).
|
the size of these elements (!472).
|
||||||
* New parsers/serialisers:
|
- Add Message::extract_valid_payload method to warn in case of failure
|
||||||
- Stream Features (RFC 6120) (!400)
|
and return simply Option<T> instead of Result<Option<T>> (!497)
|
||||||
- Extensible SASL Profile (XEP-0388)
|
|
||||||
- SASL Channel-Binding Type Capability (XEP-0440)
|
|
||||||
- Stream Limits Advertisement (XEP-0478)
|
|
||||||
- Message Displayed Synchronization (XEP-0490)
|
|
||||||
- RFC 6120 stream errors
|
|
||||||
* Improvements:
|
|
||||||
- Add support for `<optional/> in XEP-0198 feature advertisment
|
|
||||||
- Add support application-specific error conditions in XEP-0198
|
|
||||||
|
|
||||||
Version 0.21.0:
|
Version 0.21.0:
|
||||||
2024-07-25 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
2024-07-25 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
||||||
|
|
|
||||||
|
|
@ -238,6 +238,24 @@ impl Message {
|
||||||
std::mem::swap(&mut buf, &mut self.payloads);
|
std::mem::swap(&mut buf, &mut self.payloads);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tries to extract the payload, warning when parsing fails.
|
||||||
|
///
|
||||||
|
/// This method uses [`Message::extract_payload`], but removes the error
|
||||||
|
/// case by simply warning to the current logger.
|
||||||
|
#[cfg(feature = "log")]
|
||||||
|
pub fn extract_valid_payload<T: TryFrom<Element, Error = FromElementError>>(
|
||||||
|
&mut self,
|
||||||
|
) -> Option<T> {
|
||||||
|
match self.extract_payload::<T>() {
|
||||||
|
Ok(opt) => opt,
|
||||||
|
Err(e) => {
|
||||||
|
// TODO: xso should support human-readable name for T
|
||||||
|
log::warn!("Failed to parse payload: {e}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Element> for Message {
|
impl TryFrom<Element> for Message {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ syntect = { version = "5", optional = true }
|
||||||
pin-project-lite = { version = "0.2" }
|
pin-project-lite = { version = "0.2" }
|
||||||
# same repository dependencies
|
# same repository dependencies
|
||||||
sasl = { version = "0.5", path = "../sasl" }
|
sasl = { version = "0.5", path = "../sasl" }
|
||||||
xmpp-parsers = { version = "0.21", path = "../parsers" }
|
xmpp-parsers = { version = "0.21", path = "../parsers", features = [ "log" ] }
|
||||||
xso = { version = "0.1", path = "../xso" }
|
xso = { version = "0.1", path = "../xso" }
|
||||||
|
|
||||||
# these are only needed for starttls ServerConnector support
|
# these are only needed for starttls ServerConnector support
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue