Commit graph

373 commits

Author SHA1 Message Date
Kim Alvefur
22d734e305 util.poll: Restructure to make adding additional system APIs easier 2022-02-23 20:30:22 +01:00
Matthew Wild
fe56effa55 util.struct: Import Roberto 'struct' library v0.3
Downloaded from http://www.inf.puc-rio.br/~roberto/struct/

This is for compatibility with Lua 5.2 (and 5.1). Eventually we can replace
this with string.pack/string.unpack which are available in 5.3+.
2022-03-04 15:03:02 +00:00
Kim Alvefur
d3bd9f9be5 util.pposix: Use mallinfo2() on glibc 2.33, fix #1649 2022-01-06 18:56:06 +01:00
Kim Alvefur
b93398ce79 util.pposix: Bind isatty(3)
Useful for disabling certain behavior, ANSI colors etc when not
connected to a terminal.
2021-07-04 15:11:07 +02:00
Kim Alvefur
654fd45546 util.hashes: Expose OpenSSL version 2021-05-12 01:11:15 +02:00
Matthew Wild
5bc8b2a379 Merge 0.11->trunk 2021-05-13 11:17:13 +01:00
Kim Alvefur
eefbd36485 Merge 0.11->trunk 2020-10-15 17:23:21 +02:00
Kim Alvefur
20fc0c9c15 Back out changeset 2c1583bb0e0f
Same reason as 712b2e6a09d9
2020-10-15 17:21:58 +02:00
Kim Alvefur
bad47be8f9 Back out 6dde2c9fa272: Doesn't work on Lua 5.1 2020-10-15 17:12:33 +02:00
Kim Alvefur
9b8a54345f util.strbitop: Remove redundant init function
When you have 3 almost identical functions, you tend to edit one and
then copypaste. Forgot to remove this line from the other two.
2020-10-15 17:05:53 +02:00
Kim Alvefur
da8eca639a util.strbitop: Create buffer in the correct size (optimization)
This avoids dynamically growing the buffer as Lua does when luaL_addchar
is used, thus saving on realloc calls.
2020-10-15 16:43:30 +02:00
Kim Alvefur
539255c692 util.strbitop: Reformat code
astyle \
	--indent=tab \
	--attach-classes \
	--indent-switches \
	--break-blocks \
	--pad-oper \
	--unpad-paren \
	--add-braces \
	--align-pointer=name \
	--lineend=linux \
	*.c
2020-10-15 16:26:56 +02:00
Kim Alvefur
4d1b9f7c60 Merge 0.11->trunk 2020-10-15 17:14:03 +02:00
Kim Alvefur
66f3fe9d12 Merge 0.11->trunk 2020-10-15 16:51:16 +02:00
Matthew Wild
4f4140fbc3 Merge 0.11->trunk 2020-10-15 14:25:09 +01:00
Kim Alvefur
9eb8214030 configure: Pass compiler flag to enable ICU only when building util.encodings
Passing it in CFLAGS applied to all modules, which was not needed.
2020-07-12 23:28:04 +02:00
Kim Alvefur
fb1808b185 util.strbitop: Library for bitwise operations on strings 2019-09-07 13:37:47 +02:00
Matthew Wild
f5460a5037 util.hashes: Add constant-time string comparison (binding to CRYPTO_memcmp) 2021-05-10 16:24:54 +01:00
Matthew Wild
b9a670dace util.ringbuffer: Ensure unsigned chars are always returned from :byte() 2020-06-24 12:34:20 +01:00
Kim Alvefur
625ec0a93f util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Actually just an alias of pushnil, but it does make it more obvious
where the failure conditions are, which is good for readability.
2020-06-07 02:25:56 +02:00
Matthew Wild
14a436817d util.ringbuffer: Add :sub() and :byte() methods equivalent to the string methods 2020-06-04 15:19:20 +01:00
Kim Alvefur
4bab7af07d util.ringbuffer: Prevent creation of buffer with negative size
Previously this would have been (unsigned)-1 which is a large positive
integer.
2020-06-04 16:11:08 +02:00
Kim Alvefur
0bb1474ce6 util.ringbuffer: Prevent creation of zero-size buffer 2020-05-29 18:11:42 +02:00
Kim Alvefur
8055c8f7d7 util.pposix,signal: Pass around various OS numbers as integers [Lua 5.3]
Passing around PIDs, UIDs etc as integers makes it more sane in Lua 5.3.
Getting 1234.0 as PID is silly. Shouldn't change any behavior as these
are all integers on the C side and the integral floats are accepted as
integers when passed back from Lua into C.
2020-05-04 21:51:30 +02:00
Kim Alvefur
701c5f4811 util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Somehow it got SHA1's 20 byte output instead of the proper 32 = 256/8
2020-04-22 21:38:36 +02:00
Emmanuel Gil Peyrot
668dc534b6 util.net: Fix signedness warning on ARM
net.c:87:56: warning: comparison of integer expressions of different signedness: ‘long unsigned int’ and ‘long int’ [-Wsign-compare]
2020-01-30 14:22:21 +01:00
Emmanuel Gil Peyrot
a149dda0e3 util.*.c: Add static qualifiers everywhere 2019-12-01 20:25:20 +01:00
Emmanuel Gil Peyrot
8613dc1739 util.encodings: Remove redundant cast 2019-12-01 23:34:49 +01:00
Emmanuel Gil Peyrot
d209c0c677 util.encodings: Don’t export unneeded symbols
This reduces the binary size from 22704 B to 18592 B.
2019-12-01 23:34:45 +01:00
Kim Alvefur
908f5b61c5 Merge 0.11->trunk 2019-11-16 16:52:31 +01:00
Kim Alvefur
c4c38d2f01 util.pposix: Avoid overflow of malloc info at 2GB (fixes #1445 until 4GB) 2019-11-16 16:45:33 +01:00
Kim Alvefur
b679ffe808 util.encodings: Don't ignore non-strings passed to stringprep functions
If you manage to pass a table or something weird to these, you deserve
to know.
2019-11-02 13:09:54 +01:00
Kim Alvefur
42aeda373c util.encodings: Strictly verify that the 'strict' *prep argument is a boolean
This is to prevent mistakes like nodeprep(username:gsub("a","b")) from
unintentionally invoking strict mode.
2019-10-30 16:22:44 +01:00
Kim Alvefur
c42a786ec7 util.encodings: Allow unassigned code points in ICU mode to match libidn behavior (fixes #1348) 2019-04-24 16:16:19 +02:00
Kim Alvefur
41a40ab74b util.encodings: Optional strict flag to stringprep 2019-04-24 15:01:00 +02:00
Kim Alvefur
bf1a0c2f05 util.encodings: Spell out all IDNA 2008 options ICU has 2019-09-11 00:40:30 +02:00
Kim Alvefur
bb4cb60fb8 util.encodings: Switch ICU binding to IDNA2008 (fixes #533, #1301) 2019-09-11 00:14:59 +02:00
Kim Alvefur
7ef028d8d4 util.hashes: Use HMAC function provided by OpenSSL (fixes #1345) 2019-04-19 13:12:00 +02:00
Kim Alvefur
d21439da5c util-src/makefile: Update with util.poll and util.compat (fixes #1251) 2018-11-30 16:00:12 +01:00
Matthew Wild
1454ac8208 util.xpcall, util.compat: Add non-hacky multi-argument xpcall() for Lua 5.1 2018-10-26 19:29:08 +01:00
Kim Alvefur
2bb3772374 net.server_epoll: Special handling of signal interrupts 2018-10-12 03:22:09 +02:00
Kim Alvefur
afeb1f6f02 net.server_epoll: Ignore ENOENT when deregitering socket
It should not really happen
2018-10-12 03:21:11 +02:00
Kim Alvefur
bbf669b2c5 net.server_epoll: Graceful handling of registering already added socket 2018-10-12 03:20:09 +02:00
Kim Alvefur
f26390b484 util.poll: Fix inverted logic 2018-10-11 18:56:11 +02:00
Kim Alvefur
9547e0e66d util.poll: Handle failed epoll FD creation 2018-10-11 18:52:12 +02:00
Kim Alvefur
22e0c16d4c util.poll: Early return from __gc in case of no valid epoll FD
This could happen if the epoll FD has already been closed or
the epoll_create call failed
2018-10-11 18:50:04 +02:00
Kim Alvefur
28522988cc util.poll: Increase max epoll events per call
This makes the struct roughly the same size in both epoll and select
mode (64bit).

There doesn’t seem to be much guidance on an appropriate size, it does
not seem to matter too much since if there are more events they will
simply show up in the next epoll_wait call. The number of exactly
concurrent events should be fairly low most of the time anyways.
2018-10-08 15:33:15 +02:00
Kim Alvefur
4a73f5daef util.poll: Zero FD sets watched for errors on creation 2018-10-07 20:58:51 +02:00
Kim Alvefur
ceadb9c57c net.poll: Guard against negative or too large FDs 2018-10-07 18:44:46 +02:00
Kim Alvefur
31c8b1aca3 util.poll: Fix missing return for adding duplicate FD 2018-10-07 18:41:44 +02:00