aboutsummaryrefslogtreecommitdiffstats
path: root/util
Commit message (Collapse)AuthorAgeFilesLines
...
* | util.jsonschema: Implement 'luaPatternProperties' as Lua variant of ↵Kim Alvefur2023-04-221-1/+18
| | | | | | | | | | | | | | | | 'patternProperties' Previous version of this patch used 'patternProperties' but that would only work with simpler ECMA-262 regular expressions are also valid Lua patterns.
* | Merge 0.12->trunkKim Alvefur2023-04-191-1/+1
|\|
| * util.error: Fix error on conversion of invalid error stanza, fix #1805Kim Alvefur2023-04-191-1/+1
| | | | | | | | | | | | | | | | | | Error stanzas should have an <error> element, but if you pass a stanza without one to util.error.from_stanza() it triggers an attempt to index a nil value, which this patch avoids. In the conditional, it should be safe to assume error_tag is non-nil since condition can't have those values then.
* | util.human.io: Fix column width miscalculationKim Alvefur2023-04-091-3/+0
| | | | | | | | | | | | Fixes that the more fixed width columns there are, the narrower the resulting table becomes. A right-aligned variable-width column at the last position should always be flush to the right side of the terminal.
* | util.human.io: Fix error with ellipsis to negative lengthKim Alvefur2023-04-091-1/+1
| | | | | | | | | | Can happen if you resize the terminal too narrow that the space left for variable width columns end up negative.
* | util.sasl: Fix a singularsKim Alvefur2023-04-071-1/+1
| | | | | | | | | | Thanks timeless, your mere existence inspires us to improve our spelling, tho this was more syntax.
* | util.argparse: Translate '-' to '_' in long option names for convenienceMatthew Wild2023-04-071-0/+1
| | | | | | | | A review of existing code suggests nothing will break. So, here we go...
* | util.human.io: Add parse_duration() method to parse a duration stringMatthew Wild2023-04-071-0/+12
| | | | | | | | | | Similar logic occurs throughout various modules in the codebase. We might even want a module:get_option_duration()??
* | util.prosodyctl.shell: Fix sending terminal width with single argumentKim Alvefur2023-04-071-1/+1
| | | | | | | | | | E.g. when you do 'prosodyctl shell "s2s:show()"', this is the case that triggers, and it was missing the @width argument, causing confusion.
* | util.human.io: Coerce $COLUMNS to numberKim Alvefur2023-04-071-1/+1
| | | | | | | | os.getenv() returns a string but term_width() should return a number
* | util.prosodyctl.shell: Coerce terminal width to string (for util.stanza)Kim Alvefur2023-04-071-1/+1
| | | | | | | | Fixes invalid attribute value: expected string, got number
* | util.human.io: table: don't read $COLUMNS directly, just use term_width()Matthew Wild2023-04-071-1/+1
| | | | | | | | ...which now reads $COLUMNS for us and does the right thing.
* | util.human.io: table: Return determined width as a second resultMatthew Wild2023-04-071-1/+1
| | | | | | | | | | This allows callers to adjust other things based on the width of the rows (such as header lines).
* | util.human.io: Prefer using the $COLUMNS environment variable if set (by ↵Kim Alvefur2023-04-072-1/+3
| | | | | | | | | | | | readline) Feels like it should be faster.
* | util.prosodyctl.shell: Use new term_width() for widthKim Alvefur2023-04-071-1/+2
| | | | | | | | | | Kicks in if/when readline hasn't set $COLUMNS, e.g. when using the `prosodyctl shell command like this` form.
* | util.human.io: table: use term_width() to discover terminal widthMatthew Wild2023-04-071-1/+1
| |
* | util.human.io: Add term_width() method to discover the terminal widthMatthew Wild2023-04-071-0/+12
| | | | | | | | | | This is not standard POSIX, but apparently very widely supported. For reference: https://www.austingroupbugs.net/view.php?id=1053
* | util.human.io: Pass the whole column definition to mapper functionKim Alvefur2023-04-071-1/+1
| | | | | | | | | | | | I forget why I wanted this, but it may allow doing things like pull settings from the column, especially when the mapper function is reused among many columns.
* | util.human.io: Allow defining per column ellipsis functionKim Alvefur2023-04-071-1/+1
| | | | | | | | | | | | As an alternative to doing it in the mapper function. Could be useful in cases where one may want to put the ellipsis in the middle or beginning instead of the start.
* | util.human.io: Pass expected width to mapper functionKim Alvefur2023-04-071-1/+1
| | | | | | | | | | In order to allow it to adjust its output to available space, apply its own ellipsis method or other compacting method.
* | util.set: Change tostring format to {a, b, c}Kim Alvefur2023-04-061-1/+1
| | | | | | | | | | | | | | | | Makes it easier to make out where the set starts and ends in cases where it may get embedded and tostring()-ed in a log message. { } taken over from util.array for consistency with some other systems syntax for Sets, e.g. Python
* | util.array: Change tostring format to [a,b,c]Kim Alvefur2023-04-061-1/+1
| | | | | | | | | | | | | | Arrays in Lua do use { } but since __tostring is often user-facing it seems sensible to use [ ] instead for consistency with many other systems; as well as to allow the {a,b,c} formatting to be used by util.set without being confused with util.array.
* | util.human.io: Fix pattern to support fractional proportionsMatthew Wild2023-04-061-2/+2
| |
* | util.human.io: Support for dynamic "proportional" columnsMatthew Wild2023-04-061-4/+14
| | | | | | | | | | | | | | | | Instead of a percentage, this allows you to specify e.g. `width="[N]p"`, where a width="2p" will be twice the width of a width="1p" column. Compatibility with the old %-based widths is preserved, and percentages adding up to more than 100 are handled more gracefully.
* | util.fsm: New utility lib for finite state machinesMatthew Wild2022-03-171-0/+154
| |
* | util.startup: Add prosody.started promise to easily execute code after startupMatthew Wild2023-04-011-3/+14
| | | | | | | | | | | | | | | | | | To avoid a race where server-started fires before the promise function body is run (on next tick), I moved server-started to fire on the next tick, which seems sensible anyway. Errors are logged, I'm not sure if we ought to be doing something more here. I'm sure we'll find out.
* | util.session: Add 'since' property with timestamp of session creationMatthew Wild2023-03-291-0/+2
| |
* | util.jsonschema: Implement 'dependentSchemas'Kim Alvefur2023-03-261-0/+8
| | | | | | | | | | If this object key exists then this schema must validate against the current object. Seems useful.
* | util.jsonschema: Implement 'dependentRequired'Kim Alvefur2023-03-261-0/+12
| | | | | | | | If this field exists, then these fields must also exist.
* | util.roles: Implement a serialization preparation metamethodKim Alvefur2023-03-261-0/+13
| | | | | | | | | | | | Should be able to roundtrip trough serialization. Also nice for debug and logging purposes where you might want more details than what the __tostring method provides.
* | util.set: Add a serialization preparation metamethodKim Alvefur2023-03-261-0/+9
| | | | | | | | | | | | Enables util.serialization to turn Sets into a representation that can be deserialized with an environment trick, i.e. `set{"a","b"}`. Also useful for debug purposes.
* | util.format: Restore "freeze" serialization behavior in loggingKim Alvefur2023-03-261-0/+1
| | | | | | | | | | | | This was implied with the "debug" preset and does nice things like turn util.set objects into "set{a,b,c}" instead of the quite verbose thing you get otherwise.
* | util.format: Tweak serialization of %q formatted entriesKim Alvefur2023-03-261-1/+8
| | | | | | | | | | | | | | Improves serialization of function references especially, the built-in default handling of that in util.serialization is not the most informative. Now, along with the function metatable from util.startup, the actual function can be found by filename and line number.
* | util.startup: Tweak function string representationKim Alvefur2023-03-261-1/+1
| | | | | | | | | | Mostly in order to avoid triggering the XML syntax highlighting in the console logger.
* | util: Prefix module imports with prosody namespaceKim Alvefur2023-03-1768-246/+246
| |
* | util.sasl.oauthbearer: Fix gs2-header parsingMatthew Wild2023-03-211-1/+1
| |
* | util.sasl.{scram,plain}: Pass authzid to SASL profile callbackKim Alvefur2023-03-162-5/+4
| | | | | | | | | | | | | | For potential future use. Used for logging into a different account than the one used for authentication.
* | util.sasl.scram: Fix off-by-one indentationKim Alvefur2023-03-161-2/+2
| |
* | util.sasl.oauthbearer: Adjust parsing of GS2 to allow lack of authzidKim Alvefur2023-03-162-4/+5
| | | | | | | | Partly copied from util.sasl.scram and then reduced a bit.
* | util.sasl.oauthbearer: Return username from callback instead using authzid (BC)Kim Alvefur2023-03-161-33/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | RFC 6120 states that > If the initiating entity does not wish to act on behalf of another > entity, it MUST NOT provide an authorization identity. Thus it seems weird to require it here. We can instead expect an username from the token data passed back from the profile. This follows the practice of util.sasl.external where the profile callback returns the selected username, making the authentication module responsible for extracting the username from the token.
* | util.sasl.oauthbearer: Fix syntax error in b796e08e6376Matthew Wild2023-03-151-1/+1
| |
* | util.sasl.oauthbearer: Attach token_info to sasl handlerMatthew Wild2023-03-151-0/+2
| | | | | | | | | | | | This allows token-aware things to access extra information about the authentication, such as when the token is due to expire and the attached custom 'data'.
* | util.ip: Add ip.truncate() to return a new IP with only the prefix of anotherMatthew Wild2023-03-141-0/+12
| |
* | util.ip: Add is_ip() helper method to detect if an object is an ip objectMatthew Wild2023-03-141-0/+5
| |
* | util.sasl.oauthbearer: Fix traceback on authz in unexpected formatKim Alvefur2023-03-021-0/+4
| | | | | | | | | | | | E.g. if you were to just pass "username" without @hostname, the split will return nil, "username" and the nil gets passed to saslprep() and it does not like that.
* | util.sasl: Add SASL OAUTHBEARER mechanism (RFC 7628)Matthew Wild2023-03-012-4/+88
| |
* | Merge 0.12->trunkKim Alvefur2023-02-221-2/+2
|\|
| * util.prosodyctl.check: Suggest 'http_cors_override' instead of older CORS ↵Kim Alvefur2023-02-221-2/+2
| | | | | | | | | | | | | | | | settings The cross_domain_* settings were added here prior to http_cors_override being added back in 17d87fb2312a, so for a time there was no replacement, but now there is.
* | mod_storage_sql: Record connection to database as module statusKim Alvefur2023-01-302-4/+12
| | | | | | | | | | | | Allows retrieving this in e.g. a health reporting module Thanks pfak
* | Merge 0.12->trunkKim Alvefur2023-01-222-3/+3
|\|