Commit graph

143 commits

Author SHA1 Message Date
Kim Alvefur
885fde62be util.stanza: Handle Clark notation for attributes in :find() 2024-11-17 13:40:20 +01:00
Kim Alvefur
00584c4d61 util.stanza: Handle namespace prefixes for attributes in :find()
More correct handling of namespaces here.

This works with both prefixes from the parser and hacky .attr["foo:bar"]
2024-11-17 12:35:51 +01:00
Kim Alvefur
43531740f9 util: Prefix module imports with prosody namespace 2023-03-17 16:23:16 +01:00
Kim Alvefur
080d7974bf Merge 0.12->trunk 2022-12-12 07:10:54 +01:00
Kim Alvefur
63fde85044 Merge 0.11->0.12 2022-12-12 07:07:13 +01:00
Kim Alvefur
4fa3808e8d util.stanza: Allow U+7F
Allowed by XML despite arguably being a control character.

Drops the part of the range meant to rule out octets invalid in UTF-8
(\247 starts a 4-byte sequence), since UTF-8 correctness is validated by
util.encodings.utf8.valid().
2022-11-22 23:56:01 +01:00
Kim Alvefur
473c68770e Merge 0.12->trunk 2022-09-15 11:11:52 +02:00
Kim Alvefur
f6727510da util.stanza: Return nil instead of nothing (fix test with luassert >=1.9)
Due to a change in luassert, a dependency luassert of the Busted test
framework, returning nothing is no longer treated as not falsy.
2022-09-15 11:05:21 +02:00
Matthew Wild
b02ab508d5 util.stanza: Add add_error() to simplify adding error tags to existing stanzas
Some fiddling is required now in error_reply() to ensure the cursor is in the
same place as before this change (a lot of code apparently uses that feature).
2022-08-29 14:59:46 +01:00
Kim Alvefur
8959868a28 util.stanza: Add method for extracting a single attribute value
Sometimes you only care about a single attribute, but the child tag
itself may be optional, leading to needing `tag and tag.attr.foo` or
`stanza:find("tag@foo")`.

The `:find()` method is fairly complex, so avoiding it for this kind of
simpler use case is a win.
2022-08-17 19:04:30 +02:00
Kim Alvefur
7f7ec9e1ed util.stanza: Move misplaced argument to correct place
valid_utf8() takes only one argument, so the false was probably meant
to be valid_xml_cdata(text, attribute=false)
2020-12-24 17:57:28 +01:00
Kim Alvefur
8328e6681e util.stanza: Reject ASCII control characters (fixes #1606) 2020-11-11 16:00:41 +01:00
Kim Alvefur
5ead4102de util.stanza: Remove dead code
These cases are caught by `check_text(v, ..)` above. Those errors do not
contain the attribute however, which would have been nice.
2021-12-31 14:01:12 +01:00
Kim Alvefur
72be6f8229 util.stanza: Make type error message consistent with others 2021-12-31 13:52:11 +01:00
Kim Alvefur
ebd4ea2bb3 util.stanza: Adjust pretty printing for symmetry
Self-closing <tags/> and <?processing instructions?> had some
asymmetries in applied colors.
2021-11-29 02:13:45 +01:00
Matthew Wild
eba0bacfda util.stanza: Add :get_child_with_attr() + tests 2021-09-12 10:31:02 +01:00
Kim Alvefur
f40173b4c7 util.stanza: Export pretty printing function 2021-06-29 16:06:54 +02:00
Kim Alvefur
db2c51bcae util.stanza: Simplify and make pretty-printing look nicer
I've had this color theme in a local debug module for some time and I
quite like it. The colors are from the XMPP logo.

Removes extra XML serialization implementation in favor of the standard
one. Also removes recursive str=str..more string building.

The new two-level gsub has the accumulator in C space so shouldn't be
too bad. The inner gsub calls use no callback, so should be fast and
not create all that much garbage.

No serious benchmarking has been done, but who cares if it looks nice?
2020-11-07 22:09:46 +01:00
Kim Alvefur
317c76c881 util.stanza: Remove Windows "support" (disabling ANSI color pretty printing)
Always enable pretty printing if util.termcolours is available

util.termcolours can be nooped out to disable pretty printing.
2020-11-07 21:39:36 +01:00
Jonas Schäfer
b3ec594dd4 util.stanza: add at_top helper
This allows the user to detect whether the cursor is currently
at the top of the stanza. This will be used by util.xmppstream
to be able to port it over.
2021-05-08 16:31:48 +02:00
Kim Alvefur
2f4d12286f Merge 0.11->trunk 2021-01-08 23:56:27 +01:00
Kim Alvefur
f69303f264 Merge 0.11->trunk 2020-11-11 16:09:55 +01:00
Kim Alvefur
815ce25d10 util.stanza: Extract Application-Specific Condition from errors
API change
2020-09-26 18:12:18 +02:00
Kim Alvefur
1c53f533b0 util.stanza: Support Application-Specific Conditions in util.error 2020-09-26 18:09:10 +02:00
Kim Alvefur
8c0efc9e55 util.stanza: Get 'by' from context instead
Zash> <error by=?> should go where?  extra.by?  context? source?
Zash> In Prosody this would usually be module.host or a bare user/room JID
MattJ> Zash: context
MattJ> context.by, basically the opposite of context.actor
2020-09-26 18:07:33 +02:00
Kim Alvefur
3f9988468d util.stanza: Support inclusion of <gone> URI from util.error object 2020-09-26 17:30:47 +02:00
Kim Alvefur
2f0b85ce29 util.stanza: Support getting 'by' from util.error object 2020-09-26 17:26:31 +02:00
Kim Alvefur
d9e80064b5 util.stanza: Reorder code to prepare for extracting 'by' from util.error 2020-09-26 17:18:17 +02:00
Kim Alvefur
f0ac29acf0 util.stanza: Add method returning stanza with added indentation
Adds indentation and line breaks to stanzas, to make stanzas easier to
read for humans.
2020-04-12 17:03:05 +02:00
Kim Alvefur
4e34c40ece util.stanza: Accept util.error object to error_reply
If we're moving towards util.error as the standard error container then
this makes sense.

This may allow for future extensibility without needing a lot of
optional arguments.
2019-12-14 22:47:41 +01:00
Kim Alvefur
be23b274f6 util.stanza: Support the 'by' attribute on errors
This is to be used when the entity generating the error is not the same
as the one the stanza was directed to, e.g. an intermediate server.
2019-11-25 20:59:36 +01:00
Kim Alvefur
54da2ab6f7 util.stanza: Check that argument to error_reply is NOT a stanza of type error
Replying to an error is Very Bad
2019-11-25 20:52:03 +01:00
Kim Alvefur
52b7181979 util.stanza: Check that argument to error_reply is a stanza 2019-11-25 20:52:01 +01:00
Kim Alvefur
11095184a5 util.stanza: Remove redundant check for attrs
A stanza can't not have attrs if created the correct way
2019-11-25 20:46:55 +01:00
Kim Alvefur
b340e5e462 util.stanza: Check that argument to reply is a stanza 2019-11-25 20:44:05 +01:00
Kim Alvefur
76536dab05 util.stanza: Deserialize stanza without mutating input (fixes #711) 2018-12-01 18:30:19 +01:00
Kim Alvefur
50f6335501 util.stanza: Validate input to clone() (with brief tests) 2018-11-17 15:26:11 +01:00
Kim Alvefur
6e624e01c6 util.stanza: Use :text_tag internally everywhere
May allow future changes in a single place.
2019-08-02 08:56:29 +02:00
Kim Alvefur
e2321c4d37 util.stanza: Set preserialize as freeze metamethod 2018-10-12 00:52:18 +02:00
Matthew Wild
27d8902b8e util.stanza: Don't automatically generate ids for iq stanzas
Users of this API should provide their own id attribute that meets their
uniqueness requirements.

The current implementation leaks information (i.e. how many iq stanzas
have been sent by the server to other JIDs). Providing any strong
guarantees of randomness here would need to pull in additional
dependencies that we don't want in this simple library.
2018-09-13 16:35:48 +01:00
Matthew Wild
3b0271f560 util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981 2018-08-19 21:56:33 +01:00
Kim Alvefur
a4d7a08317 Merge 0.10->trunk 2018-07-08 19:12:17 +02:00
Kim Alvefur
759fe72f49 util.stanza: Add method for removing all children with a specific name, xmlns 2018-07-08 16:48:59 +02:00
Kim Alvefur
6d79aef106 util.stanza: Remove redundant check from :text now done in :add_direct_child 2018-06-08 17:44:44 +02:00
Kim Alvefur
37344a42d8 util.stanza: Verify that other objects added as children are valid strings 2018-06-08 17:06:21 +02:00
Kim Alvefur
beac6ef1ea util.stanza: Verify that child tags added are really stanzas (closes #1165) 2018-06-08 17:04:47 +02:00
Kim Alvefur
2d784f1063 util.stanza: Add :text_tag(), a shortcut for adding nodes with text 2018-03-21 23:20:26 +01:00
Matthew Wild
17500b46fb util.stanza: Allow :text(nil) and :text("") as harmless nops 2018-03-21 22:04:20 +00:00
Matthew Wild
65f4b853a0 util.stanza: Switch from asserts to if's, improve performance, errors and tests 2018-03-18 11:32:00 +00:00
Matthew Wild
6d7cd57d44 util.stanza: Add stricter validation for data passed to stanza builder API 2018-03-16 14:51:24 +00:00