Commit graph

265 commits

Author SHA1 Message Date
Jonas Schäfer
3089832090 xso-proc: remove stripping of trailing _ from type names
Users can now rename the generated types altogether, which means that we
do not need this anymore to avoid lints.
2024-08-01 12:53:20 +00:00
Jonas Schäfer
c90752aa51 xso: add support for overriding names of generated types
In 1265f4b, we introduced a change which may cause a conflict of type
names when deriving the traits on two different types. While a
workaround existed (use `mod`s to isolate the implementation), that is
ugly.

This commit allows overriding the choice of type names.
2024-08-01 12:53:20 +00:00
Emmanuel Gil Peyrot
d752d8c8fe xmpp-parsers: Convert Tune to xso
The Tune::new() constructor wasn’t pub before that.
2024-07-31 15:38:10 +00:00
Emmanuel Gil Peyrot
c85bde3d2e xmpp-parsers: Convert MetadataResponse to xso 2024-07-31 15:38:10 +00:00
Jonas Schäfer
819a869ffb parsers: replace some more generate_element! calls with derive macros 2024-07-27 09:39:13 +02:00
Jonas Schäfer
cd9f2033f3 xso: add support for boxed children
This allows building recursive tree structures.
2024-07-27 08:24:25 +02:00
Jonas Schäfer
01336802b4 xso-proc: add support for optional children 2024-07-27 08:24:25 +02:00
Jonas Schäfer
5d284bbd3a parsers: port some elements with children to derive macros 2024-07-26 22:31:42 +02:00
Jonas Schäfer
5bd36eccfc xso-proc: add support for child elements 2024-07-26 22:31:42 +02:00
Emmanuel Gil Peyrot
c0f1aa620e xmpp-parsers: Bump version to 0.21.0 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
09c5ad5976 xmpp-parsers: Convert jingle_s5b’s Candidate to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
726801610f xmpp-parsers: Convert ibb to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
1a7dec6f1e xmpp-parsers: Convert sm’s Enable and Enabled to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
01a61c6099 xmpp-parsers: Convert pubsub’s Default to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
5b5df16ac9 xmpp-parsers: Convert jingle_rtp_hdrext to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
0b92061433 xmpp-parsers: Convert jingle_ibb to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
2eb6ca2f94 xmpp-parsers: Remove util::text_node_codecs
This codec system was useful for the previous parser style, but we have
converted them all to xso now!
2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
0c9e478994 xmpp-parsers: Convert media_element to xso
The API changed here, URI became Uri to be more in line with the coding
style.

Also we don’t attempt to trim them any more because that was only used
in the examples, and nowhere in the text of the specification did it say
that those had to be trimmed.
2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
4be297de11 xmpp-parsers: Convert component to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
e9b6fd5d8b xmpp-parsers: Convert avatar to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
a2ece705cc xmpp-parsers: Convert vcard to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
dc0db38cf3 xmpp-parsers: Convert jingle_dtls_srtp to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
8a48244bc3 xmpp-parsers: Convert vcard_update to xso 2024-07-25 18:42:18 +02:00
Emmanuel Gil Peyrot
387fccce4a xmpp-parsers: Write the ChangeLog for 0.21.0 2024-07-25 17:39:42 +02:00
Emmanuel Gil Peyrot
9346aedfac xmpp-parsers: Update the version in the DOAP
We are close to the release!
2024-07-25 17:39:42 +02:00
11d40bac94 Unify version string formats
https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#caret-requirements

"^1.2.3" is strictly equivalent to "1.2.3"

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-07-25 14:41:04 +00:00
Emmanuel Gil Peyrot
7b66de1166 xmpp-parsers: Stop reexporting extra symbols
Let’s continue reexporting jid and minidom, but not their inner pub
items, users of this crate can go one level deeper if they need that.

Only xso::error::Error is still useful to reexport, as this is part of
the public API of all of our parsers.
2024-07-25 14:36:09 +00:00
Jonas Schäfer
ab35c234c8 xso: Bump version to 0.1.0
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled
2024-07-25 08:25:39 +00:00
Emmanuel Gil Peyrot
62b2966b9d xmpp-parsers: Simplify the page-flip logic for MAM
This only has to be a bool, no need for this Option<bool>.
2024-07-25 08:04:49 +00:00
Emmanuel Gil Peyrot
fa2846024f xmpp-parsers: Fix typos noticed by codespell 2024-07-25 07:54:30 +00:00
Jonas Schäfer
ccf38cdf9b Port everything over to AsXml 2024-07-24 16:05:06 +02:00
f35bbcb36d minidom: Bump version to 0.16
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-07-23 19:02:46 +02:00
cc123e3d93 parsers: Update jid to 0.11
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-07-23 18:52:44 +02:00
86c13611ba Remove unused paths in multiple Cargo.toml
Paths are already patched in the workspace's [patch.crates-io] block.
Not sure why this was added in the first place.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
2024-07-23 16:28:38 +00:00
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
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
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
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
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
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
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
Jonas Schäfer
2efef5ceeb xso-proc: add support for string literals for namespaces
Makes it easier to use ad-hoc.
2024-06-23 12:40:18 +02:00
Jonas Schäfer
4d1166b66d xso-proc: allow paths as XML names
Not sure if this is something useful to have, but it feels consistent
with `namespace`.
2024-06-23 12:40:18 +02:00
Jonas Schäfer
bc785fde28 parsers: replace generate_empty_element with derive 2024-06-23 12:20:02 +02:00
Jonas Schäfer
0adfd1218b xso-proc: start making derive macros for FromXml and IntoXml
For now, these macros only support empty elements. Everything else will
be rejected with a compile-time error.
2024-06-23 12:20:02 +02:00
Jonas Schäfer
6ef8dbefa3 parsers: use Error type from xso
This is a large change and as such, it needs good motivation. Let me
remind you of the ultimate goal: we want a derive macro which allows us
to FromXml/IntoXml, and that derive macro should be usable from
`xmpp_parsers` and other crates.

For that, any code generated by the derive macro mustn't depend on any
code in the `xmpp_parsers` crate, because you cannot name the crate you
are in portably (`xmpp_parsers::..` wouldn't resolve within
`xmpp_parsers`, and `crate::..` would point at other crates if the macro
was used in other crates).

We also want to interoperate with code already implementing
`TryFrom<Element>` and `Into<Element>` on structs. This ultimately
requires that we have an error type which is shared by the two
implementations and that error type must be declared in the `xso` crate
to be usable by the macros.

Thus, we port the error type over to use the type declared in `xso`.

This changes the structure of the error type greatly; I do not think
that `xso` should have to know about all the different types we are
parsing there and they don't deserve special treatment. Wrapping them in
a `Box<dyn ..>` seems more appropriate.
2024-06-23 09:40:52 +02:00
Emmanuel Gil Peyrot
2af07f4fc0 xmpp-parsers: Simplify DataForm creation using constructors
The redundancy made it harder to review changes to the Field struct, for
instance in a1bee56ee1.
2024-06-18 18:03:09 +02:00
mb
3d52905fe9 fix check for childen and attributes in desc element 2024-06-18 15:49:27 +00:00
mb
a1bee56ee1 Support desc element in field
From [XEP-0004: Data Forms](https://xmpp.org/extensions/xep-0004.html#protocol-field):

> ...
> The <field/> element MAY contain any of the following child elements:
>
> <desc/>
> The XML character data of this element provides a natural-language
> description of the field, intended for presentation in a
> user-agent (e.g., as a "tool-tip", help button, or explanatory text
> provided near the field). The <desc/> element SHOULD NOT contain
> newlines (the \n and \r characters), since layout is the
> responsibility of a user agent, and any handling of
> newlines (e.g., presentation in a user interface) is unspecified
> herein. (Note: To provide a description of a field, it
> is RECOMMENDED to use a <desc/> element rather than
> a separate <field/> element of type "fixed".)
> ...
2024-06-18 15:07:03 +00:00
Jonas Schäfer
cb3da52ba2 parsers: add streamable parsing
This adds shims which provide FromXml and IntoXml implementations to
*all* macro-generated types in `xmpp_parsers`. Mind that this does not
cover all types in `xmpp_parsers`, but a good share of them.

This is another first step toward real, fully streamed parsing.
2024-06-18 16:54:11 +02:00
mb
998d2825f8 Add alternate_address to StanzaError
[gone](https://datatracker.ietf.org/doc/html/rfc6120#section-8.3.3.5) and [redirect](https://datatracker.ietf.org/doc/html/rfc6120#section-8.3.3.14) errors may include an alternative address.

> gone
>
> The recipient or server can no longer be contacted at this address,
> typically on a permanent basis (as opposed to the <redirect/> error
> condition, which is used for temporary addressing failures); the
> associated error type SHOULD be "cancel" and the error stanza SHOULD
> include a new address (if available) as the XML character data of the
> <gone/> element (which MUST be a Uniform Resource Identifier [URI] or
> Internationalized Resource Identifier [IRI] at which the entity can
> be contacted, typically an XMPP IRI as specified in [XMPP-URI]).

—

> redirect
>
> The recipient or server is redirecting requests for this information
> to another entity, typically in a temporary fashion (as opposed to
> the <gone/> error condition, which is used for permanent addressing
> failures); the associated error type SHOULD be "modify" and the error
> stanza SHOULD contain the alternate address in the XML character data
> of the <redirect/> element (which MUST be a URI or IRI with which the
> sender can communicate, typically an XMPP IRI as specified in
> [XMPP-URI](https://datatracker.ietf.org/doc/html/rfc6120#ref-XMPP-URI)).
2024-06-18 11:11:05 +00:00
mb
ac0707e52d
Make ‘var’ attribute of a Field optional
Looking at [the spec](https://xmpp.org/extensions/xep-0004.html#protocol-field)
it seems valid not to have a `var` attribute set, at least for fields of type
`fixed` that is:

> If the element type is anything other than "fixed" (see below), it MUST
> possess a 'var' attribute that uniquely identifies the field in the context
> of the form (if it is "fixed", it MAY possess a 'var' attribute). The element
> MAY possess a 'label' attribute that defines a human-readable name for the field.
2024-06-18 12:55:32 +02:00
Jonas Schäfer
079379a178 Fix build with nightly rust
Nightly rust complains about `cfg(..)` tests against undeclared
features and other unknown cfgs. They need to be explicitly declared
now.

The nightly/stable features don't exist, so I removed them and
substitutes the currently correct number for the single test where they
were used.

The `xmpprs_doc_build` cfg flag is now declared as expectable.
2024-06-17 19:49:26 +00:00
mb
44029c90bb
Derive PartialEq for PubSub elements 2024-06-17 19:10:14 +02:00
Jonas Schäfer
80efd2eb19 Ignore missing disco#info feature in disco#info responses
xmpp-rs normally has the stance to get buggy implementations fixed
rather than dropping checks. In this particular case I think this is not
a good use of resources:

- The disco#info feature var conveys no actual information:
  If an implementation replies properly to a disco#info query, it is
  already implied that it supports the protocol.

- There are broken server implementations out there.
  A lot of them (all recent (>= 0.10 && < 0.13 AFAICT) Prosody IM
  instances). At this point in time, xmpp-rs is unable to query
  disco#info from MUCs hosted on such prosody versions, except by
  workarounds (such as the one removed in this diff).

- XEP-0030 now features a note which reads:

  > Note: Some entities are known not to advertise the
  > `http://jabber.org/protocol/disco#info` feature within their
  > responses, contrary to this specification. Entities receiving
  > otherwise valid responses which do not include this feature SHOULD
  > infer the support.

The case would be different if there were no (deployed) implementations
which had this bug or if the bug actually had an effect on clients.
Especially the latter is not the case though, as pointed out above.

Hence, I conclude that this check is overly pedantic and the resources
(time, emotional energy of dealing with bugs, punching patches through
to stable distributions, etc. etc.) spent on getting this fixed would
be better invested elsewhere.

In addition, the workaround is extremely ugly and, even in the xmpp-rs
implementation, has no test coverage. Without test coverage of such an
implementation, it is bound to break in funny ways when xmpp-rs changes
the strings of its error messages (which is something one might do even
outside a breaking release).
2024-06-16 10:52:51 +02:00
xmppftw
034976748a Add serde feature for xmpp crate 2024-06-05 11:20:33 +02:00
Emmanuel Gil Peyrot
002c2803d4 Fix typos across the codebase (thanks codespell!) 2024-05-14 05:46:02 +00:00
Paul Fariello
ccd46047be Add OOB 2024-05-14 05:45:42 +00:00
Jonas Schäfer
4853776010 data_forms: ignore incorrect FORM_TYPE fields as per XEP-0068
Some checks failed
Build / lint (push) Has been cancelled
Build / test-stable (push) Has been cancelled
Build / test-nightly (push) Has been cancelled
XEP-0068 is rather explicit that `FORM_TYPE` fields which are not
`type='hidden'` MUST be ignored (in most cases, see comments inside
the code for exceptions). The previous implementation returned an error
instead (and aborted parsing with that), which is obviously not
"ignoring".
2024-05-13 19:56:56 +00:00
Jonas Schäfer
675907ba20 pubsub: provide accessor function for event's source node's name
Some checks are pending
Build / lint (push) Waiting to run
Build / test-stable (push) Blocked by required conditions
Build / test-nightly (push) Blocked by required conditions
Handy if you want to prefilter or distribute events based on the source
node's name.
2024-05-13 17:16:57 +00:00
Jonas Schäfer
384b366f5f Add Message::extract_payload function
This should simplify access to message payloads significantly.
2024-05-06 09:40:08 +00:00
Emmanuel Gil Peyrot
f725994fe0 Bump all dependencies but rustls and webpki-roots
The latter have changed their API a bit, while everything else is still
compatible.
2024-05-04 12:42:53 +02:00
Jonas Schäfer
fcadccfbab parsers::vcard: allow linebreaks in binval data
[RFC 2426][1] says:

> The binary data MUST be encoded using the "B" encoding format.
> Long lines of encoded binary data SHOULD BE folded to 75 characters
> using the folding method defined in [MIME-DIR].

That implies that whitespace may occur in binval data and we thus must
be able to parse this correctly.

   [1]: https://datatracker.ietf.org/doc/html/rfc2426#section-2.4.1
2024-05-04 10:02:53 +00:00
Jonas Schäfer
37481fb8f6 parsers: do not do extensive XEP-0030 validation with disable-validation
Other additional checks are already gated by the absence of this
feature. As the MR to remove these checks altogether is still blocked,
this should serve as at least as an intermediate solution to anyone
affected by buggy remote implementations.
2024-04-28 10:48:35 +02:00
Jonas Schäfer
2e9c9411a3 jid: rewrite public types
This moves InnerJid into Jid and reformulates BareJid and FullJid in
terms of Jid.

Doing this has the key advantage that FullJid and BareJid can deref to
and borrow as Jid. This, in turn, has the advantage that they can be
used much more flexibly in HashMaps. However, this is (as we say in
Germany) future music; this commit only does the internal reworking.

Oh and also, it saves 20% memory on Jid objects.

Fixes #122 more thoroughly, or rather the original intent behind it.
2024-04-15 18:21:24 +02:00
Jonas Schäfer
e7fa6460f4 Update size tests
This seems to be related to an update of chrono. 32-bit sizes verified
using `cargo test --target i686-unknown-linux-gnu`.
2024-03-08 16:04:55 +01:00
Jonas Schäfer
2f7d5edb8a Make TryFrom<Element> chainable
This allows constructs like:

```rust
let residual = match Iq::try_from(stanza) {
  Ok(iq) => return handle_iq(..),
  Err(Error::TypeMismatch(_, _, v)) => v,
  Err(other) => return handle_parse_error(..),
};
let residual = match Message::try_from(stanza) {
  ..
};
let residual = ..
log::warn!("unhandled object: {:?}", residual);
```

The interesting part of this is that this could be used in a loop over a
Vec<Box<dyn FnMut(Element) -> ControlFlow<SomeResult, Element>>, i.e. in
a parsing loop for a generic XML/XMPP stream.

The advantage is that the stanza.is() check runs only once (in
check_self!) and doesn't need to be duplicated outside, and it reduces
the use of magic strings.
2024-03-03 14:50:29 +00:00
Jonas Schäfer
3b3a4ff0c8 Do not .clone() Element in code generated with generate_element
This should improve performance a little.
2024-03-03 15:05:11 +01:00