Commit graph

2,324 commits

Author SHA1 Message Date
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
Emmanuel Gil Peyrot
c497967b1c xmpp-parsers: Reduce component handshake allocations
This function always appends to an existing string, so by passing it a
String directly we can avoid superfluous allocations.

Also tokio-xmpp was doing a bunch of &str to String for no reason around
there, let’s remove that too.
2025-02-10 17:06:15 +00:00
Emmanuel Gil Peyrot
b8f64037a9 tokio-xmpp: Fix build on insecure-tcp
insecure-tcp requires the io-util feature of tokio, so let’s enable it
there.

Fixes this error:
5   | use tokio::{io::BufStream, net::TcpStream};
    |             ^^^^^^^^^^^^^ no `BufStream` in `io`
2025-02-10 15:40:53 +01:00
Jonas Schäfer
4148e9d165 xso-proc: hide generated FromXml / AsXml types
They really clutter the documentation, because they show up in the
module's index. Downside is that users can't inspect the documentation
of those types anymore, but it's not useful anyway: the parts are
private and they just impl some traits.
2025-01-28 18:26:55 +01:00
Emmanuel Gil Peyrot
fa61f421bb xmpp-parsers: Use xso for pubsub events
Also split the PubSubEvent enum into Event and Payload.
2025-01-27 15:07:59 +01:00
Emmanuel Gil Peyrot
543d9eb590 xmpp-parsers: Convert http_upload::Header to xso
We can’t use generate_attribute!() for HeaderName because it has to be
case insensitive.
2025-01-27 14:45:17 +01:00
Emmanuel Gil Peyrot
40808b883d xmpp-parsers: Add missing size tests for http_upload 2025-01-27 14:41:14 +01:00
Emmanuel Gil Peyrot
c245b3fa84 xmpp-parsers: Simplify SubscribeOptions using #[xml(flag)]
skip-changelog: This is not a user-visible change.
2025-01-27 13:35:09 +00:00
Emmanuel Gil Peyrot
d092b6affa xmpp-parsers: Convert mam::Query to xso
skip-changelog: This is not a user-visible change.
2025-01-27 03:29:29 +01:00
Emmanuel Gil Peyrot
f63b780089 xmpp-parsers: Simplify PubSub Item using xso
Now that we can have a single arbitrary payload, we can derive FromXml
and AsXml on the Item.
2025-01-26 16:40:05 +00:00
Emmanuel Gil Peyrot
1823afbc71 xso-proc: Add the default flag to the element meta
This allows the payload to be absent, and requires the field type to be
Option<minidom::Element>.
2025-01-26 16:40:05 +00:00
Emmanuel Gil Peyrot
c72cf3ddd1 xso-proc: Add n = 1 flag to element meta
This allows exactly one arbitrary payload in any element, and is handled
after every other element with a more specific matcher has been parsed.

Both the #[xml(element(n = 1))] meta and its shortcut #[xml(element)]
are allowed and treated the exact same way.
2025-01-26 16:40:05 +00:00
Jonas Schäfer
057306fba1 ci: use shallow fetch
No need to fetch the entire history. The merge base is likely within the
last couple commits because we require it to be so anyway, because the
repo requires fast-forward merges currently.

skip-changelog, because this doesn't touch library code.
2025-01-26 17:36:51 +01:00
Jonas Schäfer
6bed0f27ec ci: ensure that main branch is fetched for changelog check job
skip-changelog, as this doesn't touch library code.
2025-01-26 17:32:34 +01:00
Jonas Schäfer
8a4d548d9a tokio_xmpp: implement IQ tracking 2025-01-26 17:15:41 +01:00
Jonas Schäfer
ef9d0a95ff tokio_xmpp: improve Client docs
skip-changelog, to not add doc improvement noise.
2025-01-26 15:09:45 +00:00
Jonas Schäfer
beae4ae66b xso: fix no_std support
This reverts the Revert in 6ec275d3 which had to be done in order to
un-break usage of xso in std crates.
2025-01-26 15:07:17 +00:00
Jonas Schäfer
bf12accd48 xso-proc: improve NestedMatcher documentation
skip-changelog
2025-01-26 14:00:48 +00:00
Emmanuel Gil Peyrot
7953524eb7 xmpp-parsers: Remove two now-unused get_attr!() variants
OptionEmpty and RequiredNonEmpty were long gone.

skip-changelog, because this is internal API only.
2025-01-26 14:52:46 +01:00
Jonas Schäfer
33c8f07a6e Disable bot comment for now
It is broken because of an expired token and the fix doesn't seem to be
trivial, so we disable it for now so that the pipelines become green
again.

skip-changelog, this is not a code change.
2025-01-26 12:59:42 +01:00
Emmanuel Gil Peyrot
86b65ab447 xmpp-parsers: Split vCard-temp iq get into new VCardQuery
There is no reason to force users to use the same struct for both.
2025-01-26 12:19:43 +01:00
Emmanuel Gil Peyrot
0adca163f8 xmpp-parsers: Don’t use anything from std
The remaining two were core::str::FromStr and
alloc::collections::BTreeMap.

Note that this doesn’t allow us to be no_std yet.

skip-changelog: This isn’t in any way user-visible, except that some
structs are now slightly smaller.
2025-01-26 10:22:37 +00:00
Emmanuel Gil Peyrot
fefc898fdf xso-proc: Allow #[xml(flag)] without params
The namespace defaults to the parent’s namespace, and the name to the
field name, so we can avoid needlessly duplicating that info.
2025-01-25 20:07:47 +01:00
Emmanuel Gil Peyrot
244a9bbbf2 xmpp-parsers: Switch from zero-sized types to #[xml(flag)]
That way we can simply use true/false, instead of
Some(TheZeroSizedType)/None.
2025-01-25 20:07:47 +01:00
Jonas Schäfer
330b216f3d parsers: add support for mediated invite syntax 2025-01-25 19:27:58 +01:00
Emmanuel Gil Peyrot
c0e45b6a0f xmpp-parsers: Migrate Caps to xso
The hash member has been split into a hash and a ver members, to reflect
the attributes.
2025-01-25 18:07:44 +01:00
Emmanuel Gil Peyrot
01a0c51a2f xso-proc: Add support for the codec field on attribute meta
This allows a custom TextCodec to be used for encoding and decoding the
attribute’s value, instead of FromXmlText and AsOptionalXmlText.
2025-01-25 18:07:44 +01:00
Jonas Schäfer
763a603e49 xso: fix documentation typos
skip-changelog
2025-01-25 12:32:41 +00:00
Jonas Schäfer
fc62229dc5 tokio_xmpp: fix Client on servers without Stream Management
The Client::send_stanza method blocks on the stanza actually being sent
over the stream. Without this change, the method will never return
on streams without XEP-0198 Stream Management because `sm_state` is
then None and thus the StanzaToken's state is never advanced: it would
be stuck in Queued state.

In addition, a lack of advancement to Sent state may cause a deadlock on
XEP-0198-enabled streams if data is received so fast that the
frontend_tx mpsc::Sender in the stanzastream::Worker is filled up. In
such a case, the Worker cannot obtain a permit and will only service
writes. However, that will mean that no StanzaTokens can be advanced
beyond Queued state, because for that, reads need to be serviced (to
receive the SM acks).

If a burst of stanzas is then received while Client::send_stanza is
being awaited, send_stanza can only return if something reads from the
frontend mpsc in the meantime. We do not want to require user code to
drive the Client in full-duplex mode, hence this is a bug.

skip-changelog, because this fixes an unreleased feature.
2025-01-25 12:31:32 +00:00
Emmanuel Gil Peyrot
07f3dc4785 xmpp-parsers: Fix vCard-temp test
xso::text::TextCodec is now generic on base64::Engine, which causes a
base64 engine to have two encode() methods, needing to disambiguate
them.
2025-01-25 13:22:50 +01:00
Jonas Schäfer
4c9a271842 xso: remove incorrect/obsolete comment 2025-01-25 12:24:03 +01:00
Jonas Schäfer
69787569c9 xso: implement TextCodec<_> on all T: base64::engine::Engine
The `xso::text::Base64` struct remains as a shorthand (because frankly,
I find the const names in the base64 crate very unwieldly), but you can
now use any of the base64 engines as codec.
2025-01-25 12:22:05 +01:00
Jonas Schäfer
95773505e4 xso-proc: improve error message on type mismatch for extracted fields
The case this affects is a field like:

```
struct Foo {
   #[xml(extract(fields(text(type_ = String)), namespace = .., name = ..))]
   foo: ServiceType,
}
```

Before, we get this:

```
error[E0631]: type mismatch in closure arguments
    --> muchopper/libmuchopper/src/xmpp/sjn_api.rs:188:10
     |
188  | #[derive(AsXml)]
     |          ^^^^^
     |          |
     |          expected due to this
     |          found signature defined here
     |
     = note: expected closure signature `fn(&ServiceType) -> _`
                found closure signature `fn(&'xso_proc_as_xml_iter_lifetime std::string::String) -> _`
note: required by a bound in `std::option::Option::<T>::map`
    --> /home/jssfr/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1102:12
     |
1100 |     pub fn map<U, F>(self, f: F) -> Option<U>
     |            --- required by a bound in this associated function
1101 |     where
1102 |         F: FnOnce(T) -> U,
     |            ^^^^^^^^^^^^^^ required by this bound in `Option::<T>::map`
     = note: this error originates in the derive macro `AsXml` (in Nightly builds, run with -Z macro-backtrace for more info)

```

Afterwards, this:

```
error[E0308]: mismatched types
   --> muchopper/libmuchopper/src/xmpp/sjn_api.rs:207:20
    |
206 |     #[xml(extract(namespace = ECS, name = "service-type", fields(text(type_ = String))))]
    |                                                                               ------ expected due to this
207 |     pub service_type: ServiceType,
    |                       ^^^^^^^^^^^ expected `Option<&String>`, found `Option<&ServiceType>`
    |
    = note: expected enum `std::option::Option<&'xso_proc_as_xml_iter_lifetime std::string::String>`
               found enum `std::option::Option<&ServiceType>`

```

skip-changelog, because this affects a feature which already has an
"Added" line in the changelog.
2025-01-24 18:28:52 +01:00
Jonas Schäfer
727e57b756 Implement #[xml(flag)] meta 2025-01-21 19:12:43 +01:00
Jonas Schäfer
4eff6303dc Fix compatibility with uuid 1.12
uuid 1.12 introduced the NonNilUuid type, which can, like the Uuid
type, be parsed from a string. The Uuid type now implements
PartialEq<Self> and PartialEq<NonNilUuid>. That breaks type inferrence,
because the compiler now cannot know whether we want to parse a Uuid or
a NonNilUuid.

We thus have to be explicit.
2025-01-21 19:12:23 +01:00