Commit graph

1991 commits

Author SHA1 Message Date
Emmanuel Gil Peyrot
c631e4eff4 xmpp-parsers: Implement XEP-0386: Bind 2
This depends on XEP-0313 for its MAM metadata, and many others such as
XEP-0198, XEP-0280 and XEP-0352 for the inline features, but we
currently provide those as minidom Elements instead.
2024-07-03 23:11:23 +00:00
Emmanuel Gil Peyrot
ff588d834e jid: Fix a clippy warning
The other three are about missing Self in the new method’s return type,
but these return the Cow type instead so that’s how they’re meant to be.
2024-07-03 16:28:11 +02:00
Emmanuel Gil Peyrot
1adccee40b minidom: Fix all clippy warnings 2024-07-03 16:28:11 +02:00
Emmanuel Gil Peyrot
4356cab33c xso-proc: Fix all clippy warnings 2024-07-03 16:28:11 +02:00
Emmanuel Gil Peyrot
b18385cfff xso: Fix all clippy warnings 2024-07-03 16:28:11 +02:00
Emmanuel Gil Peyrot
69f480e709 xmpp-parsers: Fix most of the clippy warnings
Only the non-looping loop is kept for now, until we find a better
solution.
2024-07-03 16:28:11 +02:00
Emmanuel Gil Peyrot
b51d6cec3a xmpp-parsers: Reorder the XEP-0122 and XEP-0484 namespaces
We keep the list ordered by XEP number, so that it is easier to search
into.
2024-07-02 07:36:46 +00:00
Emmanuel Gil Peyrot
05651545f8 xmpp-parsers: Update XEP-0313 to its latest version
We didn’t have support for the <metadata/> element, which is a
requirement for XEP-0386: Bind 2.
2024-07-02 07:31:14 +00:00
Emmanuel Gil Peyrot
b94919ae99 xmpp-parsers: Fix tests on 32-bit
This has been tested on ARMv7.
2024-07-02 07:13:56 +00:00
Jonas Schäfer
1367764f85 parsers: use Base64 codec to derive more things 2024-07-02 06:56:30 +02:00
Jonas Schäfer
7c7f6d1f23 xso: add support for base64 text codec 2024-07-02 06:56:30 +02:00
Jonas Schäfer
4ec12fab16 parsers: make use of text codecs and derive more things 2024-07-02 06:56:30 +02:00
Jonas Schäfer
c83ff286e0 xso-proc: add support for text codecs
Text codecs allow to customize the conversion of data from/to XML,
in particular in two scenarios:

1. When the type for which the behaviour is to be defined comes from a
   foreign crate, preventing the implementation of
   FromXmlText/IntoXmlText.

2. When there is not one obvious, or more than one sensible, way to
   convert a value to XML text and back.
2024-07-02 06:56:30 +02:00
Jonas Schäfer
46584f05f9 xso: refine handling of multiple #[xml(text)] fields
Previously, we only enforced the existence of at most one `#[xml(text)]`
field only at code generation time for `FromXml`. This change enforces
it at parsing time, which is more consistent and allows for a clearer
error message.
2024-07-01 08:01:42 +02:00
Jonas Schäfer
ae30221e3c xso: only fail on non-whitespace unknown text
We hereby ignore whitespace-only unexpected text, because that's
generally harmless.
2024-07-01 08:01:42 +02:00
Jonas Schäfer
1e3c075fbf parsers: remove now-obsolete JidCodec 2024-07-01 08:01:42 +02:00
Jonas Schäfer
298bf006bf parsers: use derive macros for simple text-based elements 2024-07-01 08:01:42 +02:00
Jonas Schäfer
b0803f831b xso-proc: add support for parsing text content 2024-07-01 08:01:42 +02:00
Jonas Schäfer
92e69cf59f xso-proc: add debug mode for development purposes 2024-07-01 08:01:42 +02:00
Emmanuel Gil Peyrot
32e8f2ec2e xmpp-parsers: Implement XEP-0484: Fast Authentication Streamlining Tokens
This specification defines a token-based method to streamline
authentication in XMPP, allowing fully authenticated stream
establishment within a single round-trip.
2024-07-01 05:53:48 +00:00
Emmanuel Gil Peyrot
972a8427b0 xmpp-parsers: Use the new macro for the feature element 2024-06-30 21:46:25 +02:00
Jonas Schäfer
0e4865006c parsers: port more elements to derive macros 2024-06-30 13:14:06 +02:00
Jonas Schäfer
2fb9fc6959 xso: add more doc_cfg labels 2024-06-30 13:05:37 +02:00
Jonas Schäfer
e439e9991e parsers: port more generate_element! usages to derive macros 2024-06-30 13:05:37 +02:00
Jonas Schäfer
0c57be3e61 xso-proc: add support for defaulting in attribute parsing 2024-06-30 13:05:37 +02:00
Jonas Schäfer
cea246a0fc parsers: port more generate_element! usages to derive macros 2024-06-30 13:05:16 +02:00
Jonas Schäfer
4e9c4883a3 parsers: add xso text trait implementations to types
This allows them to be used as attribute in xso-proc derived structs.
2024-06-30 13:05:15 +02:00
Jonas Schäfer
c0fc7f49cf xso-proc: add support for non-String typed attributes 2024-06-30 13:01:36 +02:00
Jonas Schäfer
1f679c3af7 xso: add traits for XML text <-> value conversion
The traits have undergone a couple iterations and this is what we end up
with. The core issue which makes this entire thing ugly is the
Orphan Rule, preventing some trait implementations relating to types
which haven't been defined in this crate.

In an ideal world, we would implement FromXmlText and IntoXmlText for
all types implementing FromStr and/or fmt::Display.

This comes with two severe issues:

1. Downstream crates cannot chose to have different
   parsing/serialisation behaviour for "normal" text vs. xml.

2. We ourselves cannot define a behaviour for `Option<T>`. `Option<T>`
   does not implement `FromStr` (nor `Display`), but the standard
   library *could* do that at some point, and thus Rust doesn't let us
   implement e.g. `FromXmlText for Option<T> where T: FromXmlText`,
   if we also implement it on `T: FromStr`.

The second one hurts particularly once we get to optional attributes:
For these, we need to "detect" that the type is in fact `Option<T>`,
because we then need to invoke `FromXmlText` on `T` instead of
`Option<T>`. Unfortunately, we cannot do that: macros operate on token
streams and we have no type information available.

We can of course match on the name `Option`, but that breaks down when
users re-import `Option` under a different name. Even just enumerating
all the possible correct ways of using `Option` from the standard
library (there are more than three) would be a nuisance at best.

Hence, we need *another* trait or at least a specialized implementation
of `FromXmlText for Option<T>`, and we cannot do that if we blanket-impl
`FromXmlText` on `T: FromStr`.

That makes the traits what they are, and introduces the requirement that
we know about any upstream crate which anyone might want to parse from
or to XML. This sucks a lot, but that's the state of the world. We are
late to the party, and we cannot expect everyone to do the same they
have done for `serde` (many crates have a `feature = "serde"` which then
provides Serialize/Deserialize trait impls for their types).
2024-06-30 13:01:36 +02:00
Jonas Schäfer
3a680d4738 parsers: re-arrange data_forms validation implementation
This is more in line with how we handle closely coupled specifications
already. While there are subdirectories for "large" specifications (such
as MUC and PubSub), those only refer to a single XEP document. When
there are multiple separate XEP documents, we have separate modules for
that.
2024-06-30 11:25:45 +02:00
Jonas Schäfer
cfbd58c1cd parsers: fix warnings in doc build 2024-06-30 09:00:21 +00:00
Jonas Schäfer
cb09ab865c parsers: use built-in string quoting instead of manual quoting
There is at least one branch of the FromStr implementation which passes
user input right into the error struct, so we cannot assume that `'` is
not part of that value.
2024-06-30 09:00:21 +00:00
Jonas Schäfer
8d8f3fea37 parsers: fix accidental MSRV bump
The previous code didn't build with 1.78:

```
error[E0716]: temporary value dropped while borrowed
   --> parsers/src/data_forms/validate.rs:394:46
    |
380 |         let value = match self {
    |             ----- borrow later stored here
...
394 |             Datatype::UserDefined(value) => &format!("x:{value}"),
    |                                              ^^^^^^^^^^^^^^^^^^^-
    |                                              |                  |
    |                                              |                  temporary value is freed at the end of this statement
    |                                              creates a temporary value which is freed while still in use
    |
    = note: consider using a `let` binding to create a longer lived value
    = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0716]: temporary value dropped while borrowed
   --> parsers/src/data_forms/validate.rs:395:51
    |
380 |         let value = match self {
    |             ----- borrow later stored here
...
395 |             Datatype::Other { prefix, value } => &format!("{prefix}:{value}"),
    |                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^-
    |                                                   |                         |
    |                                                   |                         temporary value is freed at the end of this statement
    |                                                   creates a temporary value which is freed while still in use
    |
    = note: consider using a `let` binding to create a longer lived value
    = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0716`.
```

This seems like a silly reason to pull up the compiler version
requirements, so I fixed it with a trivial modification.
2024-06-30 09:00:21 +00:00
Jonas Schäfer
6ade419030 xso-proc: improve combinatorial test coverage for attribute fields
This is to avoid another regression slip through the test suite, as had
happened in d4d520e (fixed in this commit's parent).
2024-06-25 13:55:07 +00:00
Jonas Schäfer
c0d109d9be xso-proc: fix renaming attributes using a static item
This was broken by d4d520e by accident, and of course we didn't have
tests for that :-).

(we do, now)
2024-06-25 13:55:07 +00:00
Emmanuel Gil Peyrot
9e07882531 CI: Stop running ignored tests
This got introduced in 2e3004f89e, but
there should be no reason to run ignored tests; if they are #[ignore]
it’s probably for a good reason.

This is particularly annoying with doctests, where ignore is used to
explicitly highlight broken/untested code.

Thanks jonas’ for noticing!
2024-06-25 12:27:01 +02:00
Jonas Schäfer
1e695d8923 sasl: remove ignore from toml snippet
Those aren't run anyway, so we don't need it there.
2024-06-25 07:30:33 +02:00
Jonas Schäfer
8bc1f32218 sasl: remove ignore from scram-requiring doctest
We can make that conditional on the feature flag, thus always doing the
right thing depending on how the sasl crate is being built.
2024-06-25 07:30:33 +02:00
mb
a7fe743850
Add DatatypeError 2024-06-24 17:45:22 +02:00
mb
c94c53ac86
Reorganize imports in data_forms module 2024-06-24 16:01:53 +02:00
mb
1d99e9a298
Fix datatype validation to be case-sensitive 2024-06-24 15:59:17 +02:00
mb
8c7e9fab85
Convert comment to module doc comment 2024-06-24 15:59:16 +02:00
mb
5c129d5285
Adapt to xso change 2024-06-24 15:24:19 +02:00
mb
ffd0c3c719
Add support for XEP-0122: Data Forms Validation 2024-06-24 15:15:02 +02:00
Jonas Schäfer
d4d520e1f6 xso-proc: add support for built-in prefixes in attribute names
This simplifies the use of built-in XML attributes such as xml:lang.
2024-06-24 12:39:32 +02:00
Jonas Schäfer
84de7fc248 xso-proc: add support for namespaced attributes 2024-06-24 12:39:32 +02:00
Jonas Schäfer
219d682295 xso-proc: add support for renaming attributes
This is akin to `#[serde(rename = ..)]` and thus useful.
2024-06-24 11:33:10 +02:00
Jonas Schäfer
0bae5d3346 parsers: replace some generate_element! usage with derive macros 2024-06-24 11:33:10 +02:00
Jonas Schäfer
212c5c4a83 xso-proc: add support for parsing attributes into Strings
This is bare-bones and is missing many features which we intend to add
in future commits, such as parsing from attributes whose names differ
from the field names and parsing into non-String types.
2024-06-24 11:33:10 +02:00
Jonas Schäfer
183bef5cf6 xso-proc: completely overengineer everything for no good reason!
Well, not really, of course. All of this will make sense once we start
adding support for fields and non-struct types. Refactoring the code now
before we start to add actual member field parsing is much easier.

How do I know that this will work out? Well, my crystal ball knows it.
Don't believe me? Okay, ChatGPT told me ... Alright alright, I went
through the entire process of implementing this feature *twice* at this
point and have a pretty good idea of where to draw the abstraction lines
so that everything falls neatly into place. You'll have to trust me on
this one.

(Or, you know, check out old branches in my xmpp-rs repo. That might
work, too. `feature/derive-macro-streaming-full` might be a name to look
for if you dare.)
2024-06-23 18:43:34 +02:00