Commit graph

2,508 commits

Author SHA1 Message Date
Jonas Schäfer
8688524e1a xso: fix some documentation in minidom_compat 2025-04-27 13:44:07 +02:00
Jonas Schäfer
a7d556ce6f xso: add useful note
I tried to remove it, fell into that trap. Let's save the next person
some work.
2025-04-27 13:44:06 +02:00
Jonas Schäfer
c4de8725fc xso: deprecate try_from_element
It is not necessary anymore, because we switched from `IntoXml` to
`AsXml`, allowing `transform` to work with a reference instead of
consuming its input.

Before that, `try_from_element` was the only way to fallibly attempt to
parse something from `Element` without having to clone the entire DOM.
2025-04-27 13:44:06 +02:00
Jonas Schäfer
88561269bd xso: fix documentation typos 2025-04-27 13:43:48 +02:00
Jonas Schäfer
9fdb1564f6 xso: reject attempts to match the same XML attribute in different fields
This was a bit tricky to build, because it is possible to have an
indirection through a `static` there. Thanks to Rust's extensive
const-fn capabilities, though, it's in fact possible to cover all cases.

We still do two different checks to improve user experience. If we can,
from within the proc macro, determine that two fields refer to the same
XML attribute (because their namespace/name values use the same Rust
tokens), then we reject the fields with a clear error message pointing
at both fields.

In the other case, when there's e.g. `#[xml(lang)]` and
`#[xml(attribute(namespace = rxml::XMLNS_XML, name = "lang"))]`, the
macro cannot be sure that XMLNS_XML is in fact the XML namespace. For
that case, we generate code which is evaluated at compile time (and
has no runtime impact) which panics if the namespace and name of two
attribute-matching fields is the same.

The error message will be less clear (because it contains extra,
unchangeable wording like "evaluation of constant value failed" and "the
evaluated program panicked at", which may be a bit confusing) than the
message generated by the macros themselves, but it's a price we have to
pay unfortunately.

Note that this check may seem cosmetic and purely for better user
experience, but it is in fact needed to avoid generating not-well-formed
and/or not-namespace-well-formed XML: As `AsXml` generates `xso::Item`,
where each attribute is emitted separated (and not aggregated in a
map structure), a naive (and efficient) implementation of a writer might
not double-check that no duplicate attributes are generated.
2025-04-27 11:18:50 +02:00
Jonas Schäfer
174eea5e5d xso: clarify behaviour when two fields match the same xml attribute 2025-04-23 17:25:18 +02:00
Jonas Schäfer
d9a21dd8c9 Track xml:lang throughout parsing 2025-04-22 17:55:44 +02:00
Jonas Schäfer
31d7bbf622 xso: discard xml:lang implicitly
Because this attribute may occur in random places, it makes no sense
failing on it. We discard it after attribute processing though, so it
can still be captured by structs which are explicitly interested in it.
2025-04-22 17:55:12 +02:00
Jonas Schäfer
70d635b0fb Bump rxml to 0.13.1
rxml 0.13.0 changed the quoting style to make it consistent, so we have
to patch up all affected places where we match exact strings.
2025-04-22 17:47:45 +02:00
Maxime “pep” Buquet
477af3c895 xmpp: new 'escape-hatch' feature
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-20 13:41:56 +00:00
Link Mauve
a8c66bc783 minidom, tokio-xmpp: Use Option::as_deref()
This simplifies the Option::as_ref().map(|foo| &**foo) pattern a lot.

skip-changelog: Completely internal change.
2025-04-19 00:06:13 +02:00
Jonas Schäfer
75e0cb7dc3 parsers: improve xml:lang handling
This is still far from being a full fix. Still, we can avoid the lang
attribute (by allowing discarding the `xml:lang` value via the feature
introduced a couple commits ago) and we can avoid emitting `xml:lang=""`
where no language was previously set using the mechanism introduced for
<message/> in 5172fb5e.
2025-04-18 13:16:21 +02:00
Jonas Schäfer
5172fb5e0f parsers: port Message to use the derive macros 2025-04-18 12:56:03 +02:00
Jonas Schäfer
0fd69d2ff8 xso-proc: fix order-dependent compilation bug
The test case which is added fails to compile unless one puts the
`parent` field before the `id` field. The cause is explained somewhat by
the change, but I'll spell it out here nontheless.

Previously, the loop in `Compound::make_as_item_iter_statemachine`
assumed that the serialisation order of fields would match their
declaration order. That is not generally true: attributes must be
serialised before element content, because they must be emitted before
the element header is closed.

This change thus splits the generated states into "header" states (for
everything before the end of the element header (think `>`)) and
"body" states (for everything after and including the end of the
element header). After all fields have been processed, we can then
add the data fields of the body fields to the header states so that
they are carried through the generated state machine until they are
needed in the body.
2025-04-18 12:41:12 +02:00
Jonas Schäfer
134255d1de parsers: port data_forms to use derive macros 2025-04-18 10:49:26 +02:00
Jonas Schäfer
8e81c41f59 xso: add support for post-deserialization callback 2025-04-18 10:49:26 +02:00
Maxime “pep” Buquet
da219d4fed
xmpp: handle SIGINT (^C) in hello_bot example
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-13 21:16:17 +02:00
Maxime “pep” Buquet
23c947d081 tokio-xmpp: clippy run
skip-changelog

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-08 13:57:21 +02:00
Maxime “pep” Buquet
1b635854ad parsers: clippy run
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-08 13:57:21 +02:00
Maxime “pep” Buquet
4c2fac0ac3 jid: clippy run
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-08 12:47:56 +02:00
Maxime “pep” Buquet
4994ac20f9 xso-proc: clippy run
Caught a bug hidden behind #[cfg(not(feature = "minidom"))]

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-08 12:47:56 +02:00
Maxime “pep” Buquet
5b62672541 xso: clippy run
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-08 12:47:56 +02:00
Maxime “pep” Buquet
2555bedaa8
CI: add .show-version block in docs job
skip-changelog

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-08 12:43:30 +02:00
Maxime “pep” Buquet
a1247a0e3c parsers: Add support for XEP-0335: JSON Containers
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-07 18:35:43 +00:00
Maxime “pep” Buquet
ab7e6de3e1 xso: Add support for serde_json::Value
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-07 18:35:43 +00:00
Maxime “pep” Buquet
4780f89604 xmpp: new Agent::new method
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-04-07 18:26:27 +00:00
Link Mauve
5ae38545e4 xmpp: Shorten the default caps node to our main domain
We do own xmpp.rs, so let’s use that instead of gitlab.com.
2025-04-07 11:57:01 +02:00
Jonas Schäfer
84c4b5731c parsers: port stanza_error over to derive macros 2025-04-06 08:36:15 +02:00
Jonas Schäfer
b05ee0280a xso: add support for selectively discarding text and attributes 2025-04-06 08:36:15 +02:00
R T
fd97f9f31c fix presence serialization name 2025-04-05 17:26:33 +00:00
Jonas Schäfer
7faa6dc15b parsers: port time over to derive macros 2025-04-03 21:42:02 +02:00
Emmanuel Gil Peyrot
d203a348cb minidom: Make the whole crate almost no_std
Only std::io is still missing, maybe we should consider using a crate
implementing its API on top of no_std?
2025-03-30 12:46:39 +02:00
Colin Kinloch
8e375aea66 minidom: Specify XML subset restrictions in readme
skip-changelog: It's just a readme
2025-03-27 11:40:47 +00:00
Emmanuel Gil Peyrot
af14717ddc minidom: Fix most issues reported by clippy
This improves some of our internals.

skip-changelog: These changes are purely internal.
2025-03-27 11:19:56 +00:00
Saarko
932575c8d6 xmpp_parsers: Add Push Notifications (XEP-0357)
Add support for Push Notification parsing according to https://xmpp.org/extensions/xep-0357.html version 0.4.1.
2025-02-25 14:47:08 +02:00
Emmanuel Gil Peyrot
9f9eaba7c5 jid: Bump version to 0.12.0 and release it! 2025-02-25 00:00:59 +01:00
Emmanuel Gil Peyrot
cffef5d5f1 jid: Update ChangeLog 2025-02-25 00:00:32 +01:00
Maxime “pep” Buquet
ca241faf7d PrintRawXml: Add changelog entry
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-02-14 18:02:13 +01:00
Maxime “pep” Buquet
947d84c0d2 parsers: add xso test module
Separate from the macro_tests module because it doesn't actually test
macros, it uses it as a convenience.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-02-14 18:02:13 +01:00
Maxime “pep” Buquet
b89d3ab04d xso: Add PrintRawXml helper struct with Display
Add a helper struct to be able to display Raw Xml, useful for debug
logs.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2025-02-12 20:17:41 +01:00
Emmanuel Gil Peyrot
356ad0d46e xso: Fix all failing clippy tests
They are all sensible to me.

skip-changelog: Internal changes.
2025-02-12 19:11:32 +00:00
Emmanuel Gil Peyrot
5cbe5936a6 xmpp-parsers: Use xso for pubsub owner
Also merge its direct children into its enum fields.
2025-02-12 20:06:29 +01:00
Emmanuel Gil Peyrot
26dd6a2a29 minidom: Remove unused lifetimes
These can be elided just fine.

skip-changelog: This is purely internal change.
2025-02-12 18:08:05 +00:00
Emmanuel Gil Peyrot
205857e59c xmpp-parsers: Remove MIX support
This protocol has failed to gain any traction in the XMPP ecosystem and
is actively being replaced with better alternatives based on MUC.
2025-02-12 18:56:40 +01:00
Emmanuel Gil Peyrot
e7395b7ed8 xmpp-parsers: Add a lang property to Presence
This is a workaround for rxml not handling @xml:lang properly yet.
2025-02-12 17:48:04 +00:00
Emmanuel Gil Peyrot
7e260dd677 jid: Simplify *Part parsing
Reuse the main JID parsing blocks for the separate parts.
2025-02-12 18:23:26 +01:00
Emmanuel Gil Peyrot
bd17a2ffbf jid: Move node and resource validation to functions
This simplifies the flow of the checks.
2025-02-12 18:23:24 +01:00
Emmanuel Gil Peyrot
2a2f532c80 jid: Validate domains against idna
The idna crate validates against UTS 46, which supports domains using
either IDNA2003 or IDNA2008.  This allows us to support both old and
new internationalized domain names.

This dependency isn’t a new one in the tree, as hickory-proto, url and
tokio-xmpp all were already depending on it.

There are a bunch of other checks that have to be performed, this is
inspired by slixmpp’s JID implementation.
2025-02-12 18:21:20 +01:00
Emmanuel Gil Peyrot
f5f35eab20 jid: Test for too many @ before the resourcepart
This additionally should optimize the parsing a tiny bit by looking for
both @ and / at the same time and iterating on them, instead of one by
one.

Thanks nicoco for the report!
2025-02-12 17:14:04 +00:00
Emmanuel Gil Peyrot
772a326053 xmpp-parsers: Add missing size tests for MUC
skip-changelog: This is just about testing.
2025-02-11 12:27:07 +01:00